Files
meshcore-tth/.github/workflows/pub-release.yml
T
tthandClaude Opus 5.5 03d17d8863 All nRF52 images: platform 10.12.0, toolchain and every library pinned
Changelog: All nRF52 images build on a pinned platform (nordicnrf52 10.12.0, as the masts and the bench) and exact library versions from platformio.lock, so a build no longer depends on the day it ran
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 21:19:24 +01:00

580 lines
30 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Public firmware builds of this fork -- runs only in the published repo
# (git.rfa.cz tth-pub/meshcore-tth), skipped anywhere else.
#
# Generic envs only: upstream's placeholder BLE PIN (123456) and admin
# password ("password") -- change both on the node after flashing. Nothing
# here carries a site's identity or real secrets.
#
# Defaults follow the Czech mesh (meshcore.cz wiki: nastaveni_site_meshcore_cz,
# instalace_repeateru, regiony), PUB_FLAGS below. They apply to a node with
# no saved settings (fresh, or after an erase); a reflash keeps what is set.
#
# Runs on a push to main that touches the firmware -- the export pushes there
# after every upstream sync (private repo, tth-upstream-sync) -- and by hand.
# Documentation, the enclosure and CI files alone build nothing (paths-ignore):
# a release would only make every -ota node update itself to the same code.
# tools/ is NOT ignored: build_version.py and ota_ramlib.py are build inputs.
# Release tag v1.18.0+tth.<commit date>[.n] (the n-th release of that day),
# titled "v1.18.0+tth · 12. 11. 2026"; assets carry the tag in their names, the
# body the version the node reports (`ver`: v1.18.0-tth<sha>). Until 12. 11.
# 2026 the tags were tth-<sha8>; pruning and the changelog know both;
# the newest KEEP releases stay, older ones are deleted. The body is a
# changelog since the previous release: our own firmware commits, our docs /
# tools / CI commits folded, then the upstream PRs the upstream merges brought
# in. A "Changelog: <text>" line in a commit body replaces its subject there.
# nRF52: .uf2 (drag onto the bootloader drive) and .zip (DFU over BLE or
# serial); ESP32: -merged.bin (fresh install at 0x0) and .bin (update).
#
# EXPERIMENTAL -ota images (docs/ota-public-plan.md): every nRF52 env with a
# text console (OTA_ENVS) is built once more with -D FW_OTA=1 (admin-pushed
# update, FwUpdate), the observer ones as -observer-ota too. Each comes with a
# full .mcfw package and a delta from the same image of every kept earlier
# release (its zip's firmware.bin, checked against that release's SHA256SUMS);
# over the mesh a node takes only deltas, and none older than itself.
# Packages and SHA256SUMS are signed with OTA_SIGNING_KEY (meshcore-ota@tth-pub,
# tools/ota_allowed_signers); manifest.json lists what is there.
#
# dry_run: the same build anywhere (the private repo too), no release -- the
# result goes up as a workflow artifact. Delta bases always come from the
# public repo's releases. A pull request that changes a dependency pin
# (platformio.ini, platformio.lock -- Renovate's) runs as a dry run too, and is
# what Renovate waits for before it merges.
#
# Libraries come from platformio.lock (tools/pio_lock.py): installed before
# each env's first build, and the build fails when anything else resolved.
# Platform and toolchain are pinned in platformio.ini. With every input
# pinned, ~/.platformio and .pio/libdeps are cached under a key of the pin
# files: the same pins, the same packages.
name: pub-release
"on":
pull_request:
branches: [main]
paths:
- "platformio.ini"
- "platformio.lock"
- "variants/**/platformio.ini"
- ".github/workflows/pub-release.yml"
- ".github/fw-flags.sh"
push:
branches: [main]
paths-ignore:
- "**/*.md"
- "docs/**"
- "hardware/**"
- ".github/**"
workflow_dispatch:
inputs:
ref:
description: "commit to build: FULL sha, branch or tag (checkout takes no short sha)"
required: false
default: "main"
replace:
description: "replace an existing release of this commit"
required: false
default: "false"
dry_run:
description: "build and package only, no release (runs in the private repo too)"
required: false
default: "false"
bases_repo:
description: "dry run only: take delta bases from this repo's releases instead (testing the delta path)"
required: false
default: ""
only:
description: "dry run only: build just these artifacts (e.g. Xiao_nrf52_repeater-ota), space separated"
required: false
default: ""
concurrency:
group: pub-release
cancel-in-progress: false
env:
GITEA: https://git.rfa.cz
KEEP: 5
# PUB_FLAGS / OBS_FLAGS: .github/fw-flags.sh (shared with the private mast
# release, which builds the same observer image). RAM 37-39 %, flash 41-58 %.
OBS_ENVS: >-
Xiao_nrf52_repeater SenseCap_Solar_repeater RAK_4631_repeater t1000e_repeater Heltec_t114_repeater
# nRF52 envs with a text console: also released as experimental -ota images
OTA_ENVS: >-
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
RAK_4631_repeater RAK_4631_companion_radio_ble RAK_4631_room_server
t1000e_repeater t1000e_companion_radio_ble
Heltec_t114_repeater Heltec_t114_companion_radio_ble
Heltec_v3_repeater Heltec_v3_companion_radio_ble
jobs:
release:
if: >-
github.repository == 'tth-pub/meshcore-tth' || github.event.inputs.dry_run == 'true'
|| github.event_name == 'pull_request'
runs-on: ubuntu-latest
env:
DRY: ${{ github.event.inputs.dry_run == 'true' || github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.ref || github.sha }}
- name: Commit and tag
id: src
env:
TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
REPLACE: ${{ github.event.inputs.replace }}
run: |
set -euo pipefail
git fetch -q --tags
# the private repo carries no upstream release tags (the export brings
# them along): a dry run there fetches them, or the version base is "nover"
if [ "$DRY" = "true" ]; then
git fetch -q --no-tags https://github.com/meshcore-dev/MeshCore.git 'refs/tags/*:refs/tags/*'
fi
sha=$(git rev-parse HEAD)
# upstream base as tools/build_version.py finds it: "companion-v1.18.0" -> v1.18.0
desc=$(git describe --tags --abbrev=0 --match '*v[0-9]*' --exclude '*+tth*' --exclude 'backup/*' HEAD)
[[ $desc =~ v[0-9].* ]] && base=${BASH_REMATCH[0]} || base=$desc
# the COMMIT's date (Prague), so a rebuild of the same commit keeps its tag
day=$(TZ=Europe/Prague git show -s --format=%cd --date=format-local:%Y%m%d HEAD)
human=$(TZ=Europe/Prague git show -s --format=%cd --date=format-local:'%-d. %-m. %Y' HEAD)
api="$GITEA/api/v1/repos/$GITHUB_REPOSITORY"
auth="header = \"Authorization: token $TOKEN\""
enc() { jq -rn --arg s "$1" '$s|@uri'; }
# v1.18.0+tth.20261112, a second release of the day .2, ...
n=1
while :; do
tag="$base+tth.$day"
[ "$n" -eq 1 ] || tag="$tag.$n"
rel=$(curl -sS --config - "$api/releases/tags/$(enc "$tag")" <<<"$auth")
id=$(jq -r '.id // empty' <<<"$rel")
[ -n "$id" ] || break
if [ "$(jq -r .target_commitish <<<"$rel")" = "$sha" ]; then
if [ "$REPLACE" != "true" ]; then
echo "::error::release $tag already exists (id $id); set replace=true to rebuild it"
exit 1
fi
curl -sSf --config - -X DELETE "$api/releases/$id" <<<"$auth"
curl -sSf --config - -X DELETE "$api/tags/$(enc "$tag")" <<<"$auth" || true
echo "removed old $tag"
break
fi
n=$((n + 1))
done
title="$base+tth · $human"
[ "$n" -eq 1 ] || title="$title ($n)"
echo "release $tag: $title (commit $sha)"
{
echo "sha=$sha"
echo "tag=$tag"
echo "title=$title"
} >>"$GITHUB_OUTPUT"
# every input is pinned (see the header): the key is the pin files
- name: PlatformIO packages and locked libraries
uses: actions/cache@v5
with:
path: |
~/.platformio/platforms
~/.platformio/packages
.pio/libdeps
key: pub-pio-${{ hashFiles('platformio.ini', 'variants/**/platformio.ini', 'platformio.lock') }}
- name: Setup Build Environment
uses: ./.github/actions/setup-build-environment
- name: Build and package
id: build
env:
TAG: ${{ steps.src.outputs.tag }}
OTA_SIGNING_KEY: ${{ secrets.OTA_SIGNING_KEY }}
TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
BASES_REPO: ${{ github.event.inputs.bases_repo }}
ONLY: ${{ github.event.inputs.only }}
run: |
set -euo pipefail
source .github/fw-flags.sh
sha=$(git rev-parse --short=8 HEAD)
dist="$GITHUB_WORKSPACE/dist"
mkdir -p "$dist"
version=""
[ -n "$OTA_SIGNING_KEY" ] || { echo "::error::OTA_SIGNING_KEY secret missing"; exit 1; }
okey="$RUNNER_TEMP/ota_signing_key"
(umask 077 && printf '%s\n' "$OTA_SIGNING_KEY" >"$okey")
trap 'rm -f "$okey"' EXIT
pip install -q detools==0.53.0 cryptography
echo '{}' >"$dist/manifest.json"
# earlier public releases (newest first): delta bases for the -ota images
[ "$DRY" = "true" ] && [ -n "$BASES_REPO" ] && PUB_REPO=$BASES_REPO
[ "$DRY" = "true" ] || ONLY="" # a real release always builds everything
api="$GITEA/api/v1/repos/$PUB_REPO"
auth="header = \"Authorization: token $TOKEN\""
bases="$RUNNER_TEMP/bases"
mkdir -p "$bases"
curl -sSf --config - "$api/releases?limit=50" <<<"$auth" |
jq -c --arg t "$TAG" '[.[] | select(.tag_name | startswith("tth-") or test("[+]tth[.]")) | select(.tag_name != $t)]
| sort_by(.created_at) | reverse | .[]' >"$bases/releases.jsonl" || : >"$bases/releases.jsonl"
asset() { jq -r --arg n "$2" '.assets[] | select(.name == $n) | .browser_download_url' <<<"$1"; }
# ota_package <env> <artifact>: full package + deltas from earlier releases
ota_package() {
local env=$1 art=$2 b=".pio/build/$1" tags img rel ptag url dir out
tools/ota_check_ramfunc.sh "$env"
tags=$(grep -aoE 'MCFW-TAGS target=[!-~]+ epoch=[0-9]+' "$b/firmware.elf" | head -1)
img=$(sha256sum <"$b/firmware.bin" | cut -d' ' -f1)
python3 tools/ota_pack.py pack "$env" --key "$okey" --out "$dist/$art-$TAG.mcfw"
jq --arg a "$art" --arg z "$art-$TAG.zip" --arg f "$art-$TAG.mcfw" --arg i "$img" --arg t "${tags#MCFW-TAGS }" \
'.envs[$a] = {zip: $z, ota: {image_sha256: $i, tags: $t, full: $f, deltas: {}}}' \
"$dist/manifest.json" >"$dist/m.tmp" && mv "$dist/m.tmp" "$dist/manifest.json"
while read -r rel; do
ptag=$(jq -r .tag_name <<<"$rel")
url=$(asset "$rel" "$art-$ptag.zip")
[ -n "$url" ] || continue # that release had no such -ota image yet
dir="$bases/$ptag"
mkdir -p "$dir"
[ -f "$dir/SHA256SUMS" ] || curl -sSfL --config - -o "$dir/SHA256SUMS" "$(asset "$rel" SHA256SUMS)" <<<"$auth"
curl -sSfL --config - -o "$dir/$art-$ptag.zip" "$url" <<<"$auth"
(cd "$dir" && grep " $art-$ptag.zip\$" SHA256SUMS | sha256sum -c --quiet -)
unzip -p "$dir/$art-$ptag.zip" firmware.bin >"$dir/$art.bin"
out="$art-$TAG.from-$ptag.mcfw"
if python3 tools/ota_pack.py diff "$env" --base "$dir/$art.bin" --key "$okey" --out "$dist/$out"; then
jq --arg a "$art" --arg p "$ptag" --arg f "$out" --arg s "$(sha256sum <"$dir/$art.bin" | cut -d' ' -f1)" \
'.envs[$a].ota.deltas[$p] = {file: $f, base_sha256: $s}' \
"$dist/manifest.json" >"$dist/m.tmp" && mv "$dist/m.tmp" "$dist/manifest.json"
else
echo "::warning::$art: no delta from $ptag, full package only"
rm -f "$dist/$out"
fi
done <"$bases/releases.jsonl"
}
# The artifacts: <env>|<extra flags>|<name suffix>|<ota variant>.
# PlatformIO appends PLATFORMIO_BUILD_FLAGS after each env's flags:
# last -D wins.
arts=()
declare -A spec=()
add() {
if [ -n "$ONLY" ] && [[ " $ONLY " != *" $1$3 "* ]]; then return 0; fi
arts+=("$1$3")
spec[$1$3]="$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
# Builds run PARALLEL at a time: one by one they took 38 of the run's
# 40 minutes on a 24-core runner that sat mostly idle.
bdir="$RUNNER_TEMP/build" logs="$RUNNER_TEMP/logs"
mkdir -p "$bdir" "$logs"
# par <function> <name>...: `<function> <name>` PARALLEL at a time,
# output to $logs/<name>.log, exit code to $logs/<name>.rc
par() {
local fn=$1 n running=0
shift
for n in "$@"; do
if [ "$running" -ge "$PARALLEL" ]; then wait -n || :; running=$((running - 1)); fi
(set +e; "$fn" "$n"; echo $? >"$logs/$n.rc") >"$logs/$n.log" 2>&1 &
running=$((running + 1))
done
wait
}
# report <title> <name>...: each log as a group, in this order; fails
# the step, with the tails of the failed ones, if any failed
report() {
local title=$1 n rc failed=()
shift
for n in "$@"; do
rc=$(cat "$logs/$n.rc" 2>/dev/null || echo "?")
echo "::group::$n (rc $rc)"
cat "$logs/$n.log"
echo "::endgroup::"
[ "$rc" = 0 ] || failed+=("$n")
done
[ ${#failed[@]} -eq 0 ] && return 0
for n in "${failed[@]}"; do echo "== $n"; tail -n 30 "$logs/$n.log"; done
echo "::error::$title failed: ${failed[*]}"
exit 1
}
# 1) install the platforms. Nothing is cached here (reproducible),
# so each run downloads platforms, toolchains and libraries: 8 min
# env by env up front. One env per distinct platform (+
# platform_packages) installs those first, one at a time -- they
# are shared in ~/.platformio, concurrent installs would race.
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")
# deps <env>: the locked libraries first, then whatever lib_deps still
# miss (platform, toolchain, git/file pins), then the lock check --
# once per env: the flock keeps its other flag sets waiting
locks="$RUNNER_TEMP/locks"
mkdir -p "$locks"
deps() {
flock "$locks/$1" sh -c "python3 tools/pio_lock.py install -e '$1' && pio pkg install -e '$1' -s &&
python3 tools/pio_lock.py check -e '$1'"
}
install() { deps "${1#install-}"; }
t0=$SECONDS
for env in "${first[@]}"; do par install "install-$env"; done
report "install" "${first[@]/#/install-}"
echo "installed ${#first[@]} platforms in $((SECONDS - t0)) s"
# 2) compile, each artifact into its own build dir (one env comes in
# up to four flag sets). An env's libraries come with its first
# build (deps), into its own .pio/libdeps/<env>, while other envs
# compile; the check fails the build when anything is not exactly
# platformio.lock.
compile() {
local env flags suffix variant
IFS='|' read -r env flags suffix variant <<<"${spec[$1]}"
deps "$env" || return 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[@]}"
# 3) package in order: manifest.json, deltas and the version are
# written one artifact at a time. The OTA tools read .pio/build/<env>,
# so that points at the artifact being packaged.
mkdir -p .pio/build
for a in "${arts[@]}"; do
IFS='|' read -r env flags suffix variant <<<"${spec[$a]}"
b="$bdir/$a/$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"
cp "$b/firmware.zip" "$dist/$env$suffix-$TAG.zip"
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"
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
cp "$b/firmware.bin" "$dist/$env$suffix-$TAG.bin"
cp "$b/firmware-merged.bin" "$dist/$env$suffix-$TAG-merged.bin"
fi
echo "::endgroup::"
done
echo "installed, 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"
sha256sum -- * >SHA256SUMS
ssh-keygen -q -Y sign -f "$okey" -n meshcore-ota SHA256SUMS
ssh-keygen -Y verify -f "$GITHUB_WORKSPACE/tools/ota_allowed_signers" -I meshcore-ota@tth-pub \
-n meshcore-ota -s SHA256SUMS.sig <SHA256SUMS
cat SHA256SUMS
echo "version=${version:-tth-$sha}" >>"$GITHUB_OUTPUT"
- name: Dry run artifact
if: env.DRY == 'true'
uses: actions/upload-artifact@v4
with:
name: pub-release-dry-run
path: dist/
- name: Release
if: env.DRY != 'true'
env:
TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
SHA: ${{ steps.src.outputs.sha }}
TAG: ${{ steps.src.outputs.tag }}
TITLE: ${{ steps.src.outputs.title }}
VERSION: ${{ steps.build.outputs.version }}
run: |
set -euo pipefail
api="$GITEA/api/v1/repos/$GITHUB_REPOSITORY"
auth="header = \"Authorization: token $TOKEN\""
readme="$GITEA/$GITHUB_REPOSITORY#o-tomto-forku-meshcore-tth"
note=$(cat <<EOF
- **BLE PIN \`123456\` a admin heslo \`password\` jsou zástupné.** Po nahrání je změň: \`password <nové>\` (nejvýš 15
znaků), \`ble pin <6 číslic>\`.
- **Výchozí nastavení pro český mesh** ([meshcore.cz](https://meshcore.cz/)): 869,432 MHz / 62,5 kHz / SF7 / CR5;
repeater a room server: zero-hop advert vypnutý, flood advert á 25 h, duty cycle 10 % (\`get dutycycle\`); repeater:
regiony \`cz\` a \`cs\`. **Platí jen pro nový nebo smazaný uzel** – nové nahrání ponechá uložené nastavení.
- **\`*-observer\`**: repeater s BLE konzolí a buffery \`rxlog\` / \`pktlog\` pro repeater observer. BLE je po nahrání
vypnuté: nejdřív \`ble pin\`, pak \`ble on\`.
- **RX duty cycle** (\`set radio.rxps\`, jen SX1262) je zabudovaný a vypnutý.
- **EXPERIMENTÁLNÍ \`*-ota\` / \`*-observer-ota\`**: totéž s aktualizací firmwaru od admina (\`fw ...\`, i přes
mesh). Ke každému plný balíček \`.mcfw\` (USB/BLE) a delta \`.from-<vydání>.mcfw\` od předchozích vydání –
přes mesh uzel přijme jen deltu a nikdy starší verzi. Balíčky i \`SHA256SUMS\` jsou podepsané klíčem
\`meshcore-ota@tth-pub\` (\`tools/ota_allowed_signers\`).
- Ověření: \`ver\` ukáže verzi z řádku *Verze v uzlu* výše. Co fork mění proti upstreamu: [README]($readme).
<details><summary>English</summary>
- **BLE PIN \`123456\` and admin password \`password\` are placeholders.** Change them after flashing: \`password
<new>\` (15 characters at most), \`ble pin <6 digits>\`.
- **Czech mesh defaults** ([meshcore.cz](https://meshcore.cz/)): 869.432 MHz / 62.5 kHz / SF7 / CR5; repeater and room
server: zero-hop advert off, flood advert every 25 h, 10 % duty cycle (\`get dutycycle\`); repeater: regions \`cz\`
and \`cs\`. **A fresh or erased node only** – a reflash keeps the saved settings.
- **\`*-observer\`**: repeater with a BLE console and the \`rxlog\` / \`pktlog\` rings for the repeater observer. BLE
is off after flashing: \`ble pin\` first, then \`ble on\`.
- **RX duty cycle** (\`set radio.rxps\`, SX1262 only) is built in and off.
- **EXPERIMENTAL \`*-ota\` / \`*-observer-ota\`**: the same with admin-pushed firmware update (\`fw ...\`, over the
mesh too). Each with a full \`.mcfw\` package (USB/BLE) and a delta \`.from-<release>.mcfw\` from earlier
releases -- over the mesh a node takes only a delta and never an older version. Packages and \`SHA256SUMS\`
are signed by \`meshcore-ota@tth-pub\` (\`tools/ota_allowed_signers\`).
- Check: \`ver\` shows the version from the *Verze v uzlu* (node version) line above. What the fork changes against
upstream: [README]($readme).
</details>
EOF
)
web="$GITEA/$GITHUB_REPOSITORY"
gh=https://github.com/meshcore-dev/MeshCore
max=60
# changelog against the newest older release that HEAD descends from
prev="" base=""
while read -r t c; do
# the tag, not the release's target_commitish: Gitea keeps the
# commitish from creation, and after a rewrite of the public
# history (26. 11. 2026) it named commits no longer in it -- no
# base was found and the notes listed the last 20 commits
c=$(git rev-parse -q --verify "refs/tags/$t^{commit}" 2>/dev/null || echo "$c")
if [ "$c" != "$SHA" ] && git merge-base --is-ancestor "$c" "$SHA" 2>/dev/null; then
prev=$t base=$c
break
fi
done < <(curl -sSf --config - "$api/releases?limit=50" <<<"$auth" |
jq -r --arg t "$TAG" 'map(select(.tag_name | startswith("tth-") or test("[+]tth[.]")) | select(.tag_name != $t))
| sort_by(.created_at) | reverse | .[] | "\(.tag_name) \(.target_commitish)"')
# no older release: the last 20 commits of our own line
[ -n "$base" ] || base=$(git rev-list --first-parent --max-count=21 "$SHA" | tail -1)
# ours: commits on our main itself (first parent); a merge of one of
# our own branches (feat/...) is unfolded into the branch's commits,
# an upstream merge is left to the upstream list below
ourc=()
for c in $(git log --first-parent --format=%H "$base..$SHA"); do
if git rev-parse -q --verify "$c^2" >/dev/null; then
git log -1 --format=%s "$c" | grep -q '^Merge upstream' && continue
# ^base: a merge of main into a branch carries what is released already
mapfile -t -O "${#ourc[@]}" ourc < <(git log --no-merges --format=%H "$c^1..$c^2" "^$base")
else
ourc+=("$c")
fi
done
# Firmware changes first; docs, CI, tools and tests folded away. Sorted
# by the files a commit touches, so it holds even for a poor subject.
# A "Changelog: <text>" line in the body replaces the subject in the
# notes ("Changelog: -" leaves the commit out), so the subject can stay
# technical while the notes say what changes for the node.
fw="" other="" nother=0
for c in "${ourc[@]}"; do
line=$(git log -1 --format=%b "$c" | sed -n 's/^Changelog: *//p' | head -1)
[ "$line" = "-" ] && continue
[ -n "$line" ] || line=$(git log -1 --format=%s "$c")
line="- $line ([${c:0:8}]($web/commit/$c))"
if git diff-tree --no-commit-id --name-only -r "$c" |
grep -qE '^(src|examples|variants|lib|boards|arch)/|^platformio\.ini$'; then
fw+="$line"$'\n'
else
other+="$line"$'\n'
nother=$((nother + 1))
fi
done
fw=${fw%$'\n'} other=${other%$'\n'}
# upstream: the first-parent line of each merged upstream branch,
# PR merges as their title, direct commits as their subject
declare -A seen=()
# A direct upstream commit (no PR) links to GitHub by its ORIGINAL
# id: the public export (filter-repo) gives every upstream commit a
# new one, which GitHub does not know (30. 11. 2026: "* sec patch"
# linked to a 404). Author email + author time survive the rewrite.
declare -A upid=()
if git fetch -q --no-tags "$gh.git" '+refs/heads/main:refs/upstream/main' '+refs/heads/dev:refs/upstream/dev'; then
while read -r h k; do upid[$k]=$h; done < <(git log --format='%H %ae/%at' refs/upstream/main refs/upstream/dev)
fi
ups=()
for m in $(git log --first-parent --merges --grep='^Merge upstream' --format=%H "$base..$SHA"); do
for c in $(git log --first-parent --format=%H "$m^1..$m^2"); do
s=$(git log -1 --format=%s "$c")
if [[ $s =~ ^Merge\ pull\ request\ \#([0-9]+)\ from\ ([^/]+)/(.*)$ ]]; then
pr=${BASH_REMATCH[1]}
[ -z "${seen[$pr]:-}" ] || continue
seen[$pr]=1
t=$(git log -1 --format=%b "$c" | sed -n '/./{p;q}')
ups+=("- ${t:-${BASH_REMATCH[3]}} ([#$pr]($gh/pull/$pr), ${BASH_REMATCH[2]})")
elif [[ $s != Merge* ]]; then
[ -z "${seen[$c]:-}" ] || continue
seen[$c]=1
u=${upid[$(git log -1 --format='%ae/%at' "$c")]:-}
if [ -n "$u" ]; then
ups+=("- $s ([${u:0:7}]($gh/commit/$u))")
else
ups+=("- $s ([${c:0:7}]($web/commit/$c))")
fi
fi
done
done
n=${#ups[@]}
body=$(
echo "$TITLE"
echo
echo "Verze v uzlu · \`ver\`: $VERSION"
echo
if [ -n "$prev" ]; then
echo "Od předchozího vydání · since [$prev]($web/releases/tag/$(jq -rn --arg s "$prev" '$s|@uri'))"
echo
fi
echo "### Změny firmwaru · firmware changes"
echo "${fw:-- žádné · none}"
echo
if [ "$nother" -gt 0 ]; then
echo "<details><summary>Dokumentace, nástroje, CI · docs, tools, CI ($nother)</summary>"
echo
echo "$other"
echo
echo "</details>"
echo
fi
echo "### Z upstreamu MeshCore · from upstream ($n)"
[ "$n" -gt 0 ] && printf '%s\n' "${ups[@]:0:$max}" || echo "- žádné · none"
[ "$n" -le "$max" ] || echo "- … a dalších $((n - max)) · and $((n - max)) more"
echo
echo "### Po flashi · after flashing"
echo
echo "$note"
echo
echo "commit $SHA, run $GITHUB_RUN_NUMBER"
)
jq -n --arg t "$TAG" --arg c "$SHA" --arg n "$TITLE" --arg b "$body" \
'{tag_name: $t, target_commitish: $c, name: $n, body: $b}' >"$RUNNER_TEMP/rel.json"
id=$(curl -sSf --config - -X POST -H 'Content-Type: application/json' \
--data-binary "@$RUNNER_TEMP/rel.json" "$api/releases" <<<"$auth" | jq -r .id)
for f in dist/*; do
curl -sSf --config - -X POST -F "attachment=@$f" \
"$api/releases/$id/assets?name=$(jq -rn --arg s "${f##*/}" '$s|@uri')" <<<"$auth" >/dev/null
echo "uploaded $(basename "$f")"
done
echo "released $TAG = $VERSION (id $id)"
# keep the newest $KEEP, oldest go (with their tags)
curl -sSf --config - "$api/releases?limit=50" <<<"$auth" |
jq -r --argjson k "$KEEP" 'map(select(.tag_name | startswith("tth-") or test("[+]tth[.]")))
| sort_by(.created_at) | reverse | .[$k:][] | "\(.id) \(.tag_name)"' |
while read -r old_id old_tag; do
curl -sSf --config - -X DELETE "$api/releases/$old_id" <<<"$auth"
curl -sSf --config - -X DELETE "$api/tags/$(jq -rn --arg s "$old_tag" '$s|@uri')" <<<"$auth" || true
echo "pruned $old_tag"
done