diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bb38a0..b6cbf9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,5 +93,10 @@ jobs: - name: Validate json file matches ${{ matrix.manifest }} manifest-template.json run: | - jq -n --arg md5 "$(md5sum test-esp32.ota.bin | head -c 32)" -f tests/${{ matrix.manifest }}-manifest-template.json > /tmp/manifest.json + jq -n \ + --arg ota_md5 "$(md5sum test-esp32.ota.bin | head -c 32)" \ + --arg ota_sha256 "$(sha256sum test-esp32.ota.bin | head -c 64)" \ + --arg factory_md5 "$(md5sum test-esp32.factory.bin | head -c 32)" \ + --arg factory_sha256 "$(sha256sum test-esp32.factory.bin | head -c 64)" \ + -f tests/${{ matrix.manifest }}-manifest-template.json > /tmp/manifest.json diff <(jq --sort-keys . /tmp/manifest.json) <(jq --sort-keys . manifest.json) diff --git a/entrypoint.py b/entrypoint.py index 2ec56b7..53cd562 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -227,12 +227,15 @@ def generate_manifest_part( with open(ota_bin, "rb") as f: ota_md5 = hashlib.md5(f.read()).hexdigest() + f.seek(0) + ota_sha256 = hashlib.sha256(f.read()).hexdigest() manifest = { "chipFamily": chip_family, "ota": { "path": ota_bin.name, "md5": ota_md5, + "sha256": ota_sha256, }, } @@ -242,10 +245,16 @@ def generate_manifest_part( manifest["ota"]["release_url"] = release_url if has_factory_part: + with open(factory_bin, "rb") as f: + factory_md5 = hashlib.md5(f.read()).hexdigest() + f.seek(0) + factory_sha256 = hashlib.sha256(f.read()).hexdigest() manifest["parts"] = [ { "path": str(factory_bin.name), "offset": 0x00, + "md5": factory_md5, + "sha256": factory_sha256, } ] diff --git a/tests/complete-manifest-template.json b/tests/complete-manifest-template.json index 47f9f8f..663621a 100644 --- a/tests/complete-manifest-template.json +++ b/tests/complete-manifest-template.json @@ -8,14 +8,17 @@ "chipFamily": "ESP32", "ota": { "path": "test-esp32.ota.bin", - "md5": "\($md5)", + "md5": "\($ota_md5)", + "sha256": "\($ota_sha256)", "summary": "Test \"release\" summary\n* Multiple lines", "release_url": "https://github.com/esphome/build-action" }, "parts": [ { "path": "test-esp32.factory.bin", - "offset": 0 + "offset": 0, + "md5": "\($factory_md5)", + "sha256": "\($factory_sha256)" } ] } diff --git a/tests/partial-manifest-template.json b/tests/partial-manifest-template.json index 144b74b..b6cbc79 100644 --- a/tests/partial-manifest-template.json +++ b/tests/partial-manifest-template.json @@ -2,14 +2,17 @@ "chipFamily": "ESP32", "ota": { "path": "test-esp32.ota.bin", - "md5": "\($md5)", + "md5": "\($ota_md5)", + "sha256": "\($ota_sha256)", "summary": "Test \"release\" summary\n* Multiple lines", "release_url": "https://github.com/esphome/build-action" }, "parts": [ { "path": "test-esp32.factory.bin", - "offset": 0 + "offset": 0, + "md5": "\($factory_md5)", + "sha256": "\($factory_sha256)" } ] }