From e5e56f4372aabaa1903951f28513d7de9401b43c Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Mon, 30 Nov 2026 19:15:04 +0100 Subject: [PATCH] CI: public release builds its 33 images six at a time Changelog: - Co-Authored-By: Claude Opus 5.5 --- .github/workflows/pub-release.yml | 86 +++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pub-release.yml b/.github/workflows/pub-release.yml index 80127c8e..44adaa8b 100644 --- a/.github/workflows/pub-release.yml +++ b/.github/workflows/pub-release.yml @@ -86,6 +86,9 @@ env: Xiao_nrf52_repeater Xiao_nrf52_room_server Xiao_nrf52_sensor SenseCap_Solar_repeater RAK_4631_repeater RAK_4631_room_server t1000e_repeater Heltec_t114_repeater PUB_REPO: tth-pub/meshcore-tth # where delta bases come from, dry run or not + # grg-runner: 24 cores, up to 8 jobs of its own; 6 builds x 6 compilers + PARALLEL: 6 + PIO_JOBS: 6 ENVS: >- Xiao_nrf52_repeater Xiao_nrf52_companion_radio_ble Xiao_nrf52_room_server Xiao_nrf52_sensor SenseCap_Solar_repeater SenseCap_Solar_companion_radio_ble @@ -224,14 +227,66 @@ jobs: fi done <"$bases/releases.jsonl" } - # build [ota variant]; PlatformIO - # appends PLATFORMIO_BUILD_FLAGS after each env's flags: last -D wins - build() { - local env=$1 suffix=$3 variant=${4:-} b v - if [ -n "$ONLY" ] && [[ " $ONLY " != *" $env$suffix "* ]]; then return 0; fi - echo "::group::$env$suffix" - FW_OTA_VARIANT=$variant PLATFORMIO_BUILD_FLAGS="$PUB_FLAGS $2" pio run -e "$env" - b=".pio/build/$env" + # The artifacts: |||. + # PlatformIO appends PLATFORMIO_BUILD_FLAGS after each env's flags: + # last -D wins. + arts=() + add() { + if [ -n "$ONLY" ] && [[ " $ONLY " != *" $1$3 "* ]]; then return 0; fi + arts+=("$1|$2|$3|${4:-}") + } + for env in $ENVS; do add "$env" "" ""; done + for env in $OBS_ENVS; do add "$env" "$OBS_FLAGS" "-observer"; done + for env in $OTA_ENVS; do add "$env" "-D FW_OTA=1" "-ota" ota; done + for env in $OBS_ENVS; do add "$env" "$OBS_FLAGS -D FW_OTA=1" "-observer-ota" observer-ota; done + # 1) compile PARALLEL artifacts at a time, each into its own build dir + # (one env comes in up to four flag sets). One by one this took 38 + # of the run's 40 minutes on a 24-core runner that sat mostly idle. + # Platforms, tools and libraries are installed first, one env at a + # time: concurrent first installs would race in ~/.platformio and + # .pio/libdeps. + bdir="$RUNNER_TEMP/build" logs="$RUNNER_TEMP/logs" + mkdir -p "$bdir" "$logs" + for env in $(printf '%s\n' "${arts[@]}" | cut -d'|' -f1 | sort -u); do + pio pkg install -e "$env" >"$logs/install-$env.log" 2>&1 || + { cat "$logs/install-$env.log"; echo "::error::$env: pio pkg install failed"; exit 1; } + done + compile() { # , in a subshell + export FW_OTA_VARIANT=$4 PLATFORMIO_BUILD_DIR="$bdir/$1$3" PLATFORMIO_BUILD_FLAGS="$PUB_FLAGS $2" + pio run -j "$PIO_JOBS" -e "$1" || return 1 + [ -f "$bdir/$1$3/$1/firmware.zip" ] || pio run -j "$PIO_JOBS" -t mergebin -e "$1" # ESP32 + } + t0=$SECONDS running=0 + for a in "${arts[@]}"; do + IFS='|' read -r env flags suffix variant <<<"$a" + if [ "$running" -ge "$PARALLEL" ]; then wait -n || :; running=$((running - 1)); fi + (set +e; compile "$env" "$flags" "$suffix" "$variant"; echo $? >"$logs/$env$suffix.rc") >"$logs/$env$suffix.log" 2>&1 & + running=$((running + 1)) + done + wait + echo "compiled ${#arts[@]} artifacts in $((SECONDS - t0)) s ($PARALLEL at a time)" + failed=() + for a in "${arts[@]}"; do + IFS='|' read -r env flags suffix variant <<<"$a" + rc=$(cat "$logs/$env$suffix.rc" 2>/dev/null || echo "?") + echo "::group::$env$suffix (rc $rc)" + cat "$logs/$env$suffix.log" + echo "::endgroup::" + [ "$rc" = 0 ] || failed+=("$env$suffix") + done + if [ ${#failed[@]} -gt 0 ]; then + for f in "${failed[@]}"; do echo "== $f"; tail -n 30 "$logs/$f.log"; done + echo "::error::build failed: ${failed[*]}" + exit 1 + fi + # 2) package in order: manifest.json, deltas and the version are + # written one artifact at a time. The OTA tools read .pio/build/, + # so that points at the artifact being packaged. + mkdir -p .pio/build + for a in "${arts[@]}"; do + IFS='|' read -r env flags suffix variant <<<"$a" + b="$bdir/$env$suffix/$env" + echo "::group::package $env$suffix" if [ -f "$b/firmware.zip" ]; then # nRF52 python3 bin/uf2conv/uf2conv.py "$b/firmware.hex" -c -o "$b/firmware.uf2" -f 0xADA52840 cp "$b/firmware.uf2" "$dist/$env$suffix-$TAG.uf2" @@ -239,18 +294,19 @@ jobs: v=$(grep -m1 -aoE 'v[0-9]+\.[0-9]+\.[0-9]+-tth[0-9a-f]+\+?' "$b/firmware.elf" || true) case "$v" in *+) echo "::error::$env is dirty ($v)"; exit 1 ;; esac [ -n "$version" ] || version="$v" - [ -z "$variant" ] || { unzip -p "$b/firmware.zip" firmware.bin >"$b/firmware.bin"; ota_package "$env" "$env$suffix"; } + if [ -n "$variant" ]; then + rm -rf ".pio/build/$env" + ln -s "$b" ".pio/build/$env" + unzip -p "$b/firmware.zip" firmware.bin >"$b/firmware.bin" + ota_package "$env" "$env$suffix" + fi else # ESP32 - PLATFORMIO_BUILD_FLAGS="$PUB_FLAGS $2" pio run -t mergebin -e "$env" cp "$b/firmware.bin" "$dist/$env$suffix-$TAG.bin" cp "$b/firmware-merged.bin" "$dist/$env$suffix-$TAG-merged.bin" fi echo "::endgroup::" - } - for env in $ENVS; do build "$env" "" ""; done - for env in $OBS_ENVS; do build "$env" "$OBS_FLAGS" "-observer"; done - for env in $OTA_ENVS; do build "$env" "-D FW_OTA=1" "-ota" ota; done - for env in $OBS_ENVS; do build "$env" "$OBS_FLAGS -D FW_OTA=1" "-observer-ota" observer-ota; done + done + echo "built and packaged in $((SECONDS - t0)) s" jq --arg c "$(git rev-parse HEAD)" --arg t "$TAG" '.commit = $c | .tag = $t' \ "$dist/manifest.json" >"$dist/m.tmp" && mv "$dist/m.tmp" "$dist/manifest.json" cd "$dist"