diff --git a/.github/release-notes.sh b/.github/release-notes.sh new file mode 100755 index 00000000..26a504b8 --- /dev/null +++ b/.github/release-notes.sh @@ -0,0 +1,155 @@ +#!/usr/bin/env bash +# The changes part of a public release's notes (pub-release.yml): our commits +# since BASE, one computed line for the build dependencies that moved, and +# upstream's merged PRs. Prints Markdown to stdout. +# +# Usage: .github/release-notes.sh +# Preview: in a clone of tth-pub/meshcore-tth checked out at (the +# library line compares platformio.lock in the working tree with ). +# +# What a commit puts into the notes (body lines, AGENTS.md "Commit = řádek +# veřejného changelogu"; .tth/tools/git-hooks/commit-msg enforces them): +# Changelog: replaces the subject; "Changelog: -" = left out +# Changelog-cs: the notes show " · **" +# Changelog-topic: commits with the same topic in one release are +# ONE item: the newest one's text, all links -- +# a fix of a fix, a pin moved twice, a +# superseded step no longer show up as two items +# Commits that touch the firmware (paths in $fwre) come first, the rest is +# folded. Build dependencies are not taken from commit messages but diffed: +# the nRF52 platform and toolchain pins in platformio.ini and every library in +# platformio.lock (tools/pio_lock.py moved), so the daily lock refresh and +# Renovate commits carry "Changelog: -" and a release still says what moved. +set -euo pipefail +case "${1:-}" in -h | --help) + sed -n '2,/^[^#]/{/^#/s/^# \{0,1\}//p}' "$0" + exit 0 + ;; +esac +[ $# -eq 3 ] || { + echo "usage: $0 " >&2 + exit 2 +} +base=$1 sha=$2 web=$3 +gh=https://github.com/meshcore-dev/MeshCore +max=60 +fwre='^(src|examples|variants|lib|boards|arch)/|^platformio\.(ini|lock)$' + +trailer() { git log -1 --format=%b "$1" | sed -n "s/^$2: *//p" | head -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 + +# items, newest first; a topic seen before only adds its link +declare -A text=() links=() isfw=() +keys=() +for c in "${ourc[@]}"; do + en=$(trailer "$c" Changelog) + [ "$en" = "-" ] && continue + [ -n "$en" ] || en=$(git log -1 --format=%s "$c") + cs=$(trailer "$c" Changelog-cs) + key=$(trailer "$c" Changelog-topic) + key=${key:-$c} + link="[${c:0:8}]($web/commit/$c)" + if [ -z "${text[$key]+x}" ]; then + keys+=("$key") + if [ -n "$cs" ]; then text[$key]="$cs · *$en*"; else text[$key]=$en; fi + links[$key]=$link + else + links[$key]+=", $link" + fi + git diff-tree --no-commit-id --name-only -r "$c" | grep -qE "$fwre" && isfw[$key]=1 +done + +# build dependencies that moved between base and sha +deps=() +pin() { git show "$1:platformio.ini" 2>/dev/null | grep -m1 -oE "$2@[0-9][^[:space:]]*" | cut -d@ -f2 || true; } +for p in nordicnrf52 toolchain-gccarmnoneeabi; do + o=$(pin "$base" "platformio/$p") n=$(pin "$sha" "platformio/$p") + [ "$o" = "$n" ] || deps+=("$p ${o:-unpinned} → ${n:-unpinned}") +done +if git cat-file -e "$base:platformio.lock" 2>/dev/null && [ -f platformio.lock ]; then + if [ "$(git rev-parse HEAD)" = "$(git rev-parse "$sha^{commit}")" ]; then + while IFS= read -r l; do + [ -n "$l" ] && deps+=("${l/ -> / → }") + done < <(python3 tools/pio_lock.py moved --base "$base") + else + echo "release-notes: checkout is not $sha, libraries left out" >&2 + fi +fi + +fw="" other="" nother=0 +for k in "${keys[@]}"; do + line="- ${text[$k]} (${links[$k]})" + if [ -n "${isfw[$k]:-}" ]; then + fw+="$line"$'\n' + else + other+="$line"$'\n' + nother=$((nother + 1)) + fi +done +if [ "${#deps[@]}" -gt 0 ]; then + d=$(printf '%s, ' "${deps[@]}") + fw+="- Závislosti buildu · *build dependencies*: ${d%, }"$'\n' +fi +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. 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 seen=() 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[@]} + +echo "### Změny firmwaru · firmware changes" +echo "${fw:-- žádné · none}" +echo +if [ "$nother" -gt 0 ]; then + echo "
Dokumentace, nástroje, CI · docs, tools, CI ($nother)" + echo + echo "$other" + echo + echo "
" + echo +fi +echo "### Z upstreamu MeshCore · from upstream ($n)" +if [ "$n" -gt 0 ]; then printf '%s\n' "${ups[@]:0:$max}"; else echo "- žádné · none"; fi +[ "$n" -le "$max" ] || echo "- … a dalších $((n - max)) · and $((n - max)) more" diff --git a/.github/workflows/pub-release.yml b/.github/workflows/pub-release.yml index 2df88731..7b5f88ce 100644 --- a/.github/workflows/pub-release.yml +++ b/.github/workflows/pub-release.yml @@ -21,7 +21,9 @@ # 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: " line in a commit body replaces its subject there. +# in, generated by .github/release-notes.sh (preview it locally; its header +# lists the commit trailers: Changelog, Changelog-cs, Changelog-topic) with +# one computed line for the build dependencies that moved. # nRF52: .uf2 (drag onto the bootloader drive) and .zip (DFU over BLE or # serial); ESP32: -merged.bin (fresh install at 0x0) and .bin (update). # @@ -451,8 +453,6 @@ jobs: 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 @@ -470,73 +470,9 @@ jobs: | 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: " 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[@]} + # our commits, moved build dependencies, upstream PRs -- the + # generator is a script so the notes can be previewed locally + changes=$(bash .github/release-notes.sh "$base" "$SHA" "$web") body=$( echo "$TITLE" echo @@ -546,20 +482,7 @@ jobs: 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 "
Dokumentace, nástroje, CI · docs, tools, CI ($nother)" - echo - echo "$other" - echo - echo "
" - 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 "$changes" echo echo "### Po flashi · after flashing" echo