156 lines
6.0 KiB
Bash
Executable File
156 lines
6.0 KiB
Bash
Executable File
#!/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 <base> <sha> <web url of this repo>
|
|
# Preview: in a clone of tth-pub/meshcore-tth checked out at <sha> (the
|
|
# library line compares platformio.lock in the working tree with <base>).
|
|
#
|
|
# 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: <English line> replaces the subject; "Changelog: -" = left out
|
|
# Changelog-cs: <Czech line> the notes show "<cs> · *<en>*"
|
|
# Changelog-topic: <slug> 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 <base> <sha> <web url>" >&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 "<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)"
|
|
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"
|