From 6e1988d6b5a7febb5190d81a0d0b7271f3aeb594 Mon Sep 17 00:00:00 2001 From: AronHetLam Date: Wed, 20 Sep 2023 14:23:24 +0200 Subject: [PATCH] ... --- .github/workflows/build_binaries.yml | 24 ++++----- ...export_binaries.py => publish_binaries.py} | 53 ++++++++++--------- platformio.ini | 2 +- 3 files changed, 39 insertions(+), 40 deletions(-) rename pio_scripts/{export_binaries.py => publish_binaries.py} (62%) diff --git a/.github/workflows/build_binaries.yml b/.github/workflows/build_binaries.yml index 8abbc96..e51da32 100644 --- a/.github/workflows/build_binaries.yml +++ b/.github/workflows/build_binaries.yml @@ -49,7 +49,9 @@ jobs: - name: Cache PlatformIO uses: actions/cache@v3 with: - path: ~/.platformio + path: | + ~/.platformio + ./pio key: ${{ runner.os }}-pio-${{ matrix.environment }}-${{ hashFiles('**/platformio.ini') }} - name: Set up Python uses: actions/setup-python@v4 @@ -59,7 +61,7 @@ jobs: run: pip install -r requirements.txt - name: Build firmware env: - PLATFORMIO_BUILD_FLAGS: -DPUBLISH + PUBLISH: true run: pio run -e ${{ matrix.environment }} - uses: actions/upload-artifact@v3 with: @@ -77,26 +79,18 @@ jobs: - uses: actions/download-artifact@v3 with: path: ./output - - run: pushd ./output && pwd && ls && popd - - name: merge manifests - run: | - jq -s '[.[] | select(.name == "ATEM_tally_light")] | (.[0] | with_entries(select(.key != "builds"))) + {builds: map(.builds) | add}' output/*/manifest.json > ./output/ATEM_tally_light_manifest.json && - jq -s '[.[] | select(.name == "ATEM_tally_test_server")] | (.[0] | with_entries(select(.key != "builds"))) + {builds: map(.builds) | add}' output/*/manifest.json > ./output/ATEM_tally_test_server_manifest.json - uses: actions/configure-pages@v3 - - run: pushd ./output && pwd && ls && popd - uses: actions/jekyll-build-pages@v1 with: destination: ./output - - run: pushd ./output && pwd && ls && popd - uses: actions/download-artifact@v3 with: - path: ./output - - run: pushd ./output && pwd && ls && popd + path: ./output/publish + - name: merge manifests + run: | + jq -s '[.[] | select(.name == "ATEM_tally_light")] | (.[0] | with_entries(select(.key != "builds"))) + {builds: map(.builds) | add}' output/*/manifest.json > ./output/ATEM_tally_light_manifest.json && + jq -s '[.[] | select(.name == "ATEM_tally_test_server")] | (.[0] | with_entries(select(.key != "builds"))) + {builds: map(.builds) | add}' output/*/manifest.json > ./output/ATEM_tally_test_server_manifest.json - uses: actions/upload-pages-artifact@v2 with: name: gh-page-mine - path: ./ - - uses: actions/upload-artifact@v3 - with: - name: gh-mine path: ./output diff --git a/pio_scripts/export_binaries.py b/pio_scripts/publish_binaries.py similarity index 62% rename from pio_scripts/export_binaries.py rename to pio_scripts/publish_binaries.py index 32f0c88..23d759f 100644 --- a/pio_scripts/export_binaries.py +++ b/pio_scripts/publish_binaries.py @@ -4,14 +4,14 @@ Import('env') PIOENV = env.get("PIOENV") -VERSION = env.get("VERSION", "") +VERSION = os.getenv("VERSION", "") BOARD_CONFIG = env.BoardConfig() APP_BIN = "{}{}{}.bin".format( env.get("BUILD_DIR"), os.path.sep, env.get("PROGNAME")) PUBLISH_DIR_BASE = "publish{}".format(os.path.sep) PUBLISH_DIR_FULL = "{}{}{}".format(PUBLISH_DIR_BASE, PIOENV, os.path.sep) -PUBLISH_BIN = "{}ATEM_tally_light_{}_{}.bin".format(PUBLISH_DIR_FULL, VERSION, PIOENV) - +PUBLISH_BIN = "{}ATEM_tally_light_{}_{}.bin".format( + PUBLISH_DIR_FULL, VERSION, PIOENV) def _get_cpp_define_value(env, define: str): define_list = [(item[-1] if item[0] == define else "") @@ -21,14 +21,16 @@ def _get_cpp_define_value(env, define: str): return None + def _create_publish_dir(): if not os.path.isdir(PUBLISH_DIR_BASE): os.mkdir(PUBLISH_DIR_BASE) - + if not os.path.isdir(PUBLISH_DIR_FULL): os.mkdir(PUBLISH_DIR_FULL) -def _esp_webtools_manifest(env, chip_family, flash_images): + +def _esp_webtools_manifest(env, chip_family, flash_parts): is_test_server = _get_cpp_define_value( env, "TALLY_TEST_SERVER") is not None manifest = { @@ -39,41 +41,44 @@ def _esp_webtools_manifest(env, chip_family, flash_images): "chipFamily": chip_family, "parts": [ { - "path": "{}{}".format(PIOENV, os.path.basename(image[1])), + "path": "{}{}".format(PUBLISH_DIR_FULL, os.path.basename(image[1])), "offset": int(image[0], 16) - } for image in flash_images] + } for image in flash_parts] }] } with open("{}manifest.json".format(PUBLISH_DIR_FULL), "w") as outfile: json.dump(manifest, outfile) + def bin_rename_copy(source, target, env): _create_publish_dir() chip_family = _get_cpp_define_value(env, "CHIP_FAMILY") - flash_images = env.get("FLASH_EXTRA_IMAGES", []) + \ - [(env.get("ESP32_APP_OFFSET", "0x00"), str(target[0]))] + flash_images = env.get("FLASH_EXTRA_IMAGES", []) - if (chip_family.startswith("ESP32")): - # Run esptool to merge images into a single binary - env.Execute(" ".join( - [ - "esptool", - "--chip", BOARD_CONFIG.get("build.mcu", "esp32"), - "merge_bin", - "-o", PUBLISH_BIN, - *env.Flatten(flash_images) - ] - )) + # if (chip_family.startswith("ESP32")): + # # Run esptool to merge images into a single binary + # env.Execute(" ".join( + # [ + # "esptool", + # "--chip", BOARD_CONFIG.get("build.mcu", "esp32"), + # "merge_bin", + # "-o", PUBLISH_BIN, + # *env.Flatten(flash_images) + # ] + # )) - else: # esp8266 - shutil.copy(str(target[0]), PUBLISH_BIN) + # else: # esp8266 + for image in flash_images: + shutil.copy(image[1], PUBLISH_DIR_FULL) + shutil.copy(str(target[0]), PUBLISH_BIN) - _esp_webtools_manifest(env, chip_family, flash_images) + _esp_webtools_manifest(env, chip_family, flash_images + + [(env.get("ESP32_APP_OFFSET", "0x00"), PUBLISH_BIN)]) -if (_get_cpp_define_value(env, "PUBLISH") is not None): +if (os.getenv("PUBLISH") is not None): env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_rename_copy]) env.Replace( diff --git a/platformio.ini b/platformio.ini index 6a9aff2..d001334 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,7 +20,7 @@ lib_deps = fastled/FastLED@^3.6.0 monitor_speed = 115200 extra_scripts = - post:pio_scripts/export_binaries.py + post:pio_scripts/publish_binaries.py [env:esp8266] build_flags =