CI: public release installs shared platforms once, libraries in parallel
Changelog: - Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e5e56f4372
commit
ca4c8e6206
1 file changed
+73
-40
@@ -231,61 +231,94 @@ jobs:
|
|||||||
# PlatformIO appends PLATFORMIO_BUILD_FLAGS after each env's flags:
|
# PlatformIO appends PLATFORMIO_BUILD_FLAGS after each env's flags:
|
||||||
# last -D wins.
|
# last -D wins.
|
||||||
arts=()
|
arts=()
|
||||||
|
declare -A spec=()
|
||||||
add() {
|
add() {
|
||||||
if [ -n "$ONLY" ] && [[ " $ONLY " != *" $1$3 "* ]]; then return 0; fi
|
if [ -n "$ONLY" ] && [[ " $ONLY " != *" $1$3 "* ]]; then return 0; fi
|
||||||
arts+=("$1|$2|$3|${4:-}")
|
arts+=("$1$3")
|
||||||
|
spec[$1$3]="$1|$2|$3|${4:-}"
|
||||||
}
|
}
|
||||||
for env in $ENVS; do add "$env" "" ""; done
|
for env in $ENVS; do add "$env" "" ""; done
|
||||||
for env in $OBS_ENVS; do add "$env" "$OBS_FLAGS" "-observer"; 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 $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
|
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
|
# Builds run PARALLEL at a time: one by one they took 38 of the run's
|
||||||
# (one env comes in up to four flag sets). One by one this took 38
|
# 40 minutes on a 24-core runner that sat mostly idle.
|
||||||
# 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"
|
bdir="$RUNNER_TEMP/build" logs="$RUNNER_TEMP/logs"
|
||||||
mkdir -p "$bdir" "$logs"
|
mkdir -p "$bdir" "$logs"
|
||||||
for env in $(printf '%s\n' "${arts[@]}" | cut -d'|' -f1 | sort -u); do
|
# par <function> <name>...: `<function> <name>` PARALLEL at a time,
|
||||||
pio pkg install -e "$env" >"$logs/install-$env.log" 2>&1 ||
|
# output to $logs/<name>.log, exit code to $logs/<name>.rc
|
||||||
{ cat "$logs/install-$env.log"; echo "::error::$env: pio pkg install failed"; exit 1; }
|
par() {
|
||||||
done
|
local fn=$1 n running=0
|
||||||
compile() { # <env> <flags> <suffix> <variant>, in a subshell
|
shift
|
||||||
export FW_OTA_VARIANT=$4 PLATFORMIO_BUILD_DIR="$bdir/$1$3" PLATFORMIO_BUILD_FLAGS="$PUB_FLAGS $2"
|
for n in "$@"; do
|
||||||
pio run -j "$PIO_JOBS" -e "$1" || return 1
|
if [ "$running" -ge "$PARALLEL" ]; then wait -n || :; running=$((running - 1)); fi
|
||||||
[ -f "$bdir/$1$3/$1/firmware.zip" ] || pio run -j "$PIO_JOBS" -t mergebin -e "$1" # ESP32
|
(set +e; "$fn" "$n"; echo $? >"$logs/$n.rc") >"$logs/$n.log" 2>&1 &
|
||||||
|
running=$((running + 1))
|
||||||
|
done
|
||||||
|
wait
|
||||||
}
|
}
|
||||||
t0=$SECONDS running=0
|
# report <title> <name>...: each log as a group, in this order; fails
|
||||||
for a in "${arts[@]}"; do
|
# the step, with the tails of the failed ones, if any failed
|
||||||
IFS='|' read -r env flags suffix variant <<<"$a"
|
report() {
|
||||||
if [ "$running" -ge "$PARALLEL" ]; then wait -n || :; running=$((running - 1)); fi
|
local title=$1 n rc failed=()
|
||||||
(set +e; compile "$env" "$flags" "$suffix" "$variant"; echo $? >"$logs/$env$suffix.rc") >"$logs/$env$suffix.log" 2>&1 &
|
shift
|
||||||
running=$((running + 1))
|
for n in "$@"; do
|
||||||
done
|
rc=$(cat "$logs/$n.rc" 2>/dev/null || echo "?")
|
||||||
wait
|
echo "::group::$n (rc $rc)"
|
||||||
echo "compiled ${#arts[@]} artifacts in $((SECONDS - t0)) s ($PARALLEL at a time)"
|
cat "$logs/$n.log"
|
||||||
failed=()
|
echo "::endgroup::"
|
||||||
for a in "${arts[@]}"; do
|
[ "$rc" = 0 ] || failed+=("$n")
|
||||||
IFS='|' read -r env flags suffix variant <<<"$a"
|
done
|
||||||
rc=$(cat "$logs/$env$suffix.rc" 2>/dev/null || echo "?")
|
[ ${#failed[@]} -eq 0 ] && return 0
|
||||||
echo "::group::$env$suffix (rc $rc)"
|
for n in "${failed[@]}"; do echo "== $n"; tail -n 30 "$logs/$n.log"; done
|
||||||
cat "$logs/$env$suffix.log"
|
echo "::error::$title failed: ${failed[*]}"
|
||||||
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
|
exit 1
|
||||||
fi
|
}
|
||||||
|
# 1) install. Nothing is cached here (reproducible), so each run
|
||||||
|
# downloads the platforms, toolchains and libraries: 8 minutes when
|
||||||
|
# done env by env. One env per distinct platform (+ platform_packages)
|
||||||
|
# installs those first, one at a time -- they are shared, concurrent
|
||||||
|
# installs would race in ~/.platformio. The other envs then only add
|
||||||
|
# their libraries, each into its own .pio/libdeps/<env>: in parallel.
|
||||||
|
envs=$(printf '%s\n' "${arts[@]}" | while read -r a; do echo "${spec[$a]%%|*}"; done | sort -u)
|
||||||
|
mapfile -t first < <(pio project config --json-output | python3 -c '
|
||||||
|
import json, sys
|
||||||
|
want, seen = set(sys.argv[1].split()), set()
|
||||||
|
for name, opts in json.load(sys.stdin):
|
||||||
|
o = dict(opts)
|
||||||
|
key = (o.get("platform"), str(o.get("platform_packages")))
|
||||||
|
if name[4:] in want and name.startswith("env:") and key not in seen:
|
||||||
|
seen.add(key)
|
||||||
|
print(name[4:])' "$envs")
|
||||||
|
install() { pio pkg install -e "${1#install-}"; }
|
||||||
|
t0=$SECONDS
|
||||||
|
for env in "${first[@]}"; do par install "install-$env"; done
|
||||||
|
report "install" "${first[@]/#/install-}"
|
||||||
|
rest=()
|
||||||
|
for env in $envs; do [[ " ${first[*]} " == *" $env "* ]] || rest+=("install-$env"); done
|
||||||
|
par install "${rest[@]}"
|
||||||
|
report "install" "${rest[@]}"
|
||||||
|
echo "installed $(wc -w <<<"$envs") envs (${#first[@]} platforms first) in $((SECONDS - t0)) s"
|
||||||
|
# 2) compile, each artifact into its own build dir: one env comes in
|
||||||
|
# up to four flag sets
|
||||||
|
compile() {
|
||||||
|
local env flags suffix variant
|
||||||
|
IFS='|' read -r env flags suffix variant <<<"${spec[$1]}"
|
||||||
|
export FW_OTA_VARIANT=$variant PLATFORMIO_BUILD_DIR="$bdir/$1" PLATFORMIO_BUILD_FLAGS="$PUB_FLAGS $flags"
|
||||||
|
pio run -j "$PIO_JOBS" -e "$env" || return 1
|
||||||
|
[ -f "$bdir/$1/$env/firmware.zip" ] || pio run -j "$PIO_JOBS" -t mergebin -e "$env" # ESP32
|
||||||
|
}
|
||||||
|
t1=$SECONDS
|
||||||
|
par compile "${arts[@]}"
|
||||||
|
echo "compiled ${#arts[@]} artifacts in $((SECONDS - t1)) s ($PARALLEL at a time)"
|
||||||
|
report "build" "${arts[@]}"
|
||||||
# 2) package in order: manifest.json, deltas and the version are
|
# 2) package in order: manifest.json, deltas and the version are
|
||||||
# written one artifact at a time. The OTA tools read .pio/build/<env>,
|
# written one artifact at a time. The OTA tools read .pio/build/<env>,
|
||||||
# so that points at the artifact being packaged.
|
# so that points at the artifact being packaged.
|
||||||
mkdir -p .pio/build
|
mkdir -p .pio/build
|
||||||
for a in "${arts[@]}"; do
|
for a in "${arts[@]}"; do
|
||||||
IFS='|' read -r env flags suffix variant <<<"$a"
|
IFS='|' read -r env flags suffix variant <<<"${spec[$a]}"
|
||||||
b="$bdir/$env$suffix/$env"
|
b="$bdir/$a/$env"
|
||||||
echo "::group::package $env$suffix"
|
echo "::group::package $env$suffix"
|
||||||
if [ -f "$b/firmware.zip" ]; then # nRF52
|
if [ -f "$b/firmware.zip" ]; then # nRF52
|
||||||
python3 bin/uf2conv/uf2conv.py "$b/firmware.hex" -c -o "$b/firmware.uf2" -f 0xADA52840
|
python3 bin/uf2conv/uf2conv.py "$b/firmware.hex" -c -o "$b/firmware.uf2" -f 0xADA52840
|
||||||
@@ -306,7 +339,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
echo "::endgroup::"
|
echo "::endgroup::"
|
||||||
done
|
done
|
||||||
echo "built and packaged in $((SECONDS - t0)) s"
|
echo "installed, built and packaged in $((SECONDS - t0)) s"
|
||||||
jq --arg c "$(git rev-parse HEAD)" --arg t "$TAG" '.commit = $c | .tag = $t' \
|
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"
|
"$dist/manifest.json" >"$dist/m.tmp" && mv "$dist/m.tmp" "$dist/manifest.json"
|
||||||
cd "$dist"
|
cd "$dist"
|
||||||
|
|||||||
Reference in new issue
Block a user