Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 123 additions & 43 deletions .github/workflows/dmc-firmware-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ name: DMC Firmware Release
# after days with one runner per board (532 jobs on 2026-10-19, 1055 on 2026-11-23).
# A board that fails to build is listed in the run summary and left out of the release;
# the rest still publish.
#
# Caches (GitHub evicts above 10 GB per repository and after 7 days without use):
# pio-tc-* compilers and frameworks of one platform, installed and ready to use. The key
# only depends on what has to be installed, so every firmware set and every
# branch shares it. Written by the toolchains job, only when it is missing.
# pio-dl-* library archives and git mirrors of one batch, a few MB. The libraries are
# unpacked from it for every build, so a library that lives in the repository
# is always the one from the checked-out commit.

# Only the jobs that talk to the Releases API (guard, publish) get write access. The jobs
# that run repository code or third-party libraries do not.
Expand Down Expand Up @@ -88,6 +96,7 @@ jobs:
ref: ${{ steps.cfg.outputs.ref }}
sha: ${{ steps.envs.outputs.sha }}
short: ${{ steps.envs.outputs.short }}
week: ${{ steps.envs.outputs.week }}
matrix: ${{ steps.envs.outputs.matrix }}
envs: ${{ steps.envs.outputs.envs }}
toolchains: ${{ steps.envs.outputs.toolchains }}
Expand Down Expand Up @@ -178,6 +187,7 @@ jobs:
# Same shallow clone + command as build.sh, so the hash matches the filenames.
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
echo "week=$(date -u +%G-%V)" >> "$GITHUB_OUTPUT"
pio project config --json-output > "$RUNNER_TEMP/pio-config.json"
python3 - "$RUNNER_TEMP/pio-config.json" <<'PY'
import hashlib, json, os, re, sys
Expand All @@ -187,24 +197,59 @@ jobs:
# LilyGo_T3_STM32_*: 224 KB app flash; upstream's repeater already uses
# 94.7% and the DMC features push it 3.2 KB over (2026-11-23).
skip = re.compile(r"^LilyGo_T3_STM32_", re.I)
rows = []
platform_id = lambda o: hashlib.sha1(json.dumps(
[o.get("platform"), o.get("platform_packages")], sort_keys=True).encode()).hexdigest()[:12]

def needs(o):
# What decides which tools a platform installs for an env. Boards without a
# local definition count as themselves.
board = o.get("board") or ""
try:
with open(f"boards/{board}.json", encoding="utf-8") as f:
d = json.load(f)
board = [d["build"]["mcu"], d.get("upload", {}).get("protocol")]
except (OSError, KeyError, ValueError):
pass
return json.dumps([board, o.get("framework"), o.get("board_build.mcu"),
o.get("upload_protocol"), o.get("debug_tool")], sort_keys=True)

rows, options, kinds = [], {}, {}
for section, items in json.load(open(sys.argv[1])):
if not section.startswith("env:"):
continue
env = section[4:]
if not pattern.search(env) or skip.search(env):
continue
opts = dict(items)
# Toolchain cache key: envs on the same platform + packages share it.
ident = json.dumps([opts.get("platform"), opts.get("platform_packages")], sort_keys=True)
rows.append({"env": env, "toolchain": hashlib.sha1(ident.encode()).hexdigest()[:12]})
env, opts = section[4:], dict(items)
options[env] = opts
# Every env of the project counts, not only this firmware set, so that all
# sets resolve to the same toolchain cache.
kind = kinds.setdefault(platform_id(opts), {})
kind[needs(opts)] = min(env, kind.get(needs(opts), env))
if pattern.search(env) and not skip.search(env):
rows.append({"env": env, "platform": platform_id(opts)})
rows.sort(key=lambda r: r["env"].lower())
if not rows:
sys.exit("no envs match " + os.environ["PATTERN"])
groups = {}
for r in rows:
groups.setdefault(r["toolchain"], []).append(r["env"])
toolchains = [{"toolchain": k, "envs": " ".join(v)} for k, v in sorted(groups.items())]
groups.setdefault(r["platform"], []).append(r["env"])
# One env per distinct requirement is enough to install everything.
toolchains, tc_key = [], {}
for p in sorted(groups):
tc_key[p] = p + "-" + hashlib.sha1("\n".join(sorted(kinds[p])).encode()).hexdigest()[:8]
toolchains.append({"toolchain": tc_key[p], "envs": " ".join(sorted(kinds[p].values()))})

def libraries(part):
# Cache id for a batch's libraries, plus the git repositories among them.
deps = set()
for env in part:
d = options[env].get("lib_deps") or []
deps.update(x.strip() for x in (d.splitlines() if isinstance(d, str) else d))
git = set()
for d in deps:
m = re.search(r"(?:git\+)?(https://github\.com/[^/\s#@]+/[^/\s#@]+)(?:#\S+)?$", d)
if m and not m.group(1).endswith(".zip"):
git.add(m.group(1))
return hashlib.sha1("\n".join(sorted(deps)).encode()).hexdigest()[:12], " ".join(sorted(git))

# Split each toolchain's envs into even batches of at most BATCH, so a batch
# needs a single toolchain restore.
BATCH = 12
Expand All @@ -213,7 +258,9 @@ jobs:
n = -(-len(v) // BATCH)
for i in range(n):
part = v[len(v) * i // n : len(v) * (i + 1) // n]
batches.append({"batch": len(batches) + 1, "toolchain": k, "envs": " ".join(part)})
libs, git = libraries(part)
batches.append({"batch": len(batches) + 1, "toolchain": tc_key[k], "libs": libs,
"git": git, "envs": " ".join(part)})
if len(batches) > 256:
sys.exit(f"{len(batches)} batches exceeds the 256-job matrix limit")
with open(os.environ["GITHUB_OUTPUT"], "a") as out:
Expand Down Expand Up @@ -249,9 +296,9 @@ jobs:
echo "::error::release or tag '$TAG' already exists ${hit}"; exit 1
fi

# One job per platform/packages combination fills the toolchain cache with the
# packages of EVERY env on it (an ESP32 and an ESP32-S3 board share the platform
# but need different compilers), so the build jobs only ever restore it.
# Installs whatever the toolchain cache does not have yet. Normally that is nothing: the
# job only checks that the cache exists. The download archives are left out of the cache
# (the tools are already unpacked, and they would double its size).
toolchains:
name: toolchain ${{ matrix.toolchain }}
needs: [plan, guard]
Expand All @@ -261,12 +308,6 @@ jobs:
matrix:
include: ${{ fromJSON(needs.plan.outputs.toolchains) }}
steps:
- name: Clone Repo
uses: actions/checkout@v6
with:
ref: ${{ needs.plan.outputs.sha }}

# Look only, so an up-to-date cache is not downloaded just to find that out.
- name: Look up the toolchain cache
id: cache
uses: actions/cache/restore@v5
Expand All @@ -275,20 +316,13 @@ jobs:
path: |
~/.platformio/packages
~/.platformio/platforms
~/.platformio/.cache
key: pio-toolchain-${{ runner.os }}-${{ matrix.toolchain }}-${{ hashFiles('platformio.ini', 'variants/*/platformio.ini') }}
key: pio-tc-v2-${{ runner.os }}-${{ matrix.toolchain }}

- name: Cache PlatformIO toolchains
- name: Clone Repo
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache@v5
uses: actions/checkout@v6
with:
path: |
~/.platformio/packages
~/.platformio/platforms
~/.platformio/.cache
key: pio-toolchain-${{ runner.os }}-${{ matrix.toolchain }}-${{ hashFiles('platformio.ini', 'variants/*/platformio.ini') }}
restore-keys: |
pio-toolchain-${{ runner.os }}-${{ matrix.toolchain }}-
ref: ${{ needs.plan.outputs.sha }}

- name: Install Python
if: steps.cache.outputs.cache-hit != 'true'
Expand All @@ -306,6 +340,16 @@ jobs:
args=()
for e in $ENVS; do args+=(-e "$e"); done
pio pkg install "${args[@]}"
du -sh ~/.platformio/packages ~/.platformio/platforms

- name: Save the toolchain cache
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: |
~/.platformio/packages
~/.platformio/platforms
key: pio-tc-v2-${{ runner.os }}-${{ matrix.toolchain }}

build:
name: batch ${{ matrix.batch }}
Expand Down Expand Up @@ -340,20 +384,40 @@ jobs:
path: |
~/.platformio/packages
~/.platformio/platforms
~/.platformio/.cache
key: pio-toolchain-${{ runner.os }}-${{ matrix.toolchain }}-${{ hashFiles('platformio.ini', 'variants/*/platformio.ini') }}
restore-keys: |
pio-toolchain-${{ runner.os }}-${{ matrix.toolchain }}-

# Library downloads for this batch's envs. Compiled objects are not cached: build.sh
# injects a changing FIRMWARE_VERSION/BUILD_DATE that invalidates every object anyway.
- name: Cache batch libraries
uses: actions/cache@v5
key: pio-tc-v2-${{ runner.os }}-${{ matrix.toolchain }}

# Keyed by content and week: libraries with a version range get their updates in the
# new week's cache, everything else comes from last week's. Compiled objects are not
# cached: build.sh injects a changing FIRMWARE_VERSION/BUILD_DATE that invalidates
# every object anyway.
- name: Restore library downloads
id: dl
uses: actions/cache/restore@v5
with:
path: .pio/libdeps
key: pio-libdeps-${{ runner.os }}-${{ inputs.firmware }}-${{ matrix.batch }}-${{ hashFiles('platformio.ini', 'variants/*/platformio.ini') }}
path: |
~/.platformio/.cache/downloads
~/.cache/git-mirrors
key: pio-dl-v2-${{ runner.os }}-${{ matrix.libs }}-${{ needs.plan.outputs.week }}
restore-keys: |
pio-libdeps-${{ runner.os }}-${{ inputs.firmware }}-${{ matrix.batch }}-
pio-dl-v2-${{ runner.os }}-${{ matrix.libs }}-

# PlatformIO clones a git library again for every env; point it at a local mirror.
# Without a mirror it simply falls back to GitHub.
- name: Use local mirrors for git libraries
env:
GIT_LIBS: ${{ matrix.git }}
FRESH: ${{ steps.dl.outputs.cache-hit }}
run: |
mkdir -p ~/.cache/git-mirrors
for url in $GIT_LIBS; do
m=~/.cache/git-mirrors/$(printf '%s' "${url#https://github.com/}" | tr '/' '_')
if [ ! -d "$m" ]; then
git clone -q --mirror "$url" "$m" || { rm -rf "$m"; echo "no mirror for $url"; continue; }
elif [ "$FRESH" != 'true' ]; then
git -C "$m" remote update --prune >/dev/null || echo "could not refresh $url"
fi
git config --global "url.file://$m.insteadOf" "$url"
done

- name: Install PlatformIO
run: pip install --upgrade platformio
Expand Down Expand Up @@ -387,6 +451,22 @@ jobs:
done
echo "failed=${failed# }" >> "$GITHUB_OUTPUT"

# Library archives are small; anything large is a tool that was missing from the
# toolchain cache and does not belong here.
- name: Trim library downloads
if: always() && steps.dl.outputs.cache-hit != 'true'
run: find ~/.platformio/.cache/downloads -type f -size +20M -print -delete 2>/dev/null || true

- name: Save library downloads
if: steps.dl.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
continue-on-error: true
with:
path: |
~/.platformio/.cache/downloads
~/.cache/git-mirrors
key: pio-dl-v2-${{ runner.os }}-${{ matrix.libs }}-${{ needs.plan.outputs.week }}

- name: Upload firmware
if: always()
uses: actions/upload-artifact@v7
Expand Down
Loading