diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 77ad6e6..fa9b06b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -33,8 +33,9 @@ jobs: PLATFORMIO_BUILD_FLAGS: -D SPECIFIC_MACRO -I/extra/inc VERSION: ${{ steps.get_version.outputs.version-without-v }} - - name: Archive production artifacts - uses: actions/upload-artifact@v2 + - name: Release + uses: softprops/action-gh-release@v1 with: - name: firmware - path: .pio/build/**/firmware_*.bin + files: | + .pio/build/*/firmware_*.bin + .pio/build/*/firmware_*.bin.gz diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index ef36ab6..70008b2 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -29,3 +29,5 @@ the safe UART baudrate to 38400 bps. To test the release workflow execute: $ act --container-architecture linux/amd64 --artifact-server-path $PWD/act-cache -e act/release.json -W .github/workflows/release.yaml + +Note that the `Release` step will fail. diff --git a/platformio.ini b/platformio.ini index 9817984..d9ee7fc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -30,6 +30,7 @@ build_flags = extra_scripts = ${env.extra_scripts} pre:scripts/get_build_time.py + scripts/make_gz.py upload_port = upload_resetmethod = nodemcu upload_speed = 115200 diff --git a/scripts/make_gz.py b/scripts/make_gz.py new file mode 100644 index 0000000..c12280b --- /dev/null +++ b/scripts/make_gz.py @@ -0,0 +1,23 @@ +import gzip +import shutil +import os +Import("env") + + +def compress_firmware(source, target, env): + """ Compress ESP8266 firmware using gzip for 'compressed OTA upload' """ + SOURCE_FILE = env.subst("$BUILD_DIR") + os.sep + env.subst("$PROGNAME") + ".bin" + if not os.path.exists(SOURCE_FILE+'.bak'): + print("Compressing firmware for upload...") + shutil.move(SOURCE_FILE, SOURCE_FILE + '.bak') + with open(SOURCE_FILE + '.bak', 'rb') as f_in: + with gzip.open(SOURCE_FILE + '.gz', 'wb') as f_out: + shutil.copyfileobj(f_in, f_out) + shutil.move(SOURCE_FILE + '.bak', SOURCE_FILE) + + ORG_FIRMWARE_SIZE = os.stat(SOURCE_FILE).st_size + GZ_FIRMWARE_SIZE = os.stat(SOURCE_FILE + '.gz').st_size + + print("Compression reduced firmware size to {:.0f}% of original (was {} bytes, now {} bytes)".format((GZ_FIRMWARE_SIZE / ORG_FIRMWARE_SIZE) * 100, ORG_FIRMWARE_SIZE, GZ_FIRMWARE_SIZE)) + +env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [compress_firmware])