Nightly: update the release in place, and publish after each build of main

The publish step deleted the release first and then made a new one.
When the token could not make the release (HTTP 403), the release was
gone. The script now moves the tag, edits the release and uploads the
files with --clobber. It makes a release only when there is none.

If DMODEM_BUMP_TOKEN fails, a second step tries with the GITHUB_TOKEN.

The workflow also runs each time a run of Build on main completes, so
the release follows main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRTrw1ffsyY5bhTghu1
This commit is contained in:
Claude committed 2026-11-25 04:03:16 +00:00
1 parent d67c460485
commit 661a9cb066
2 files changed
+72 -20

No files matched your search

+47 -9
View File
@@ -1,8 +1,13 @@
#!/usr/bin/env bash
# nightly-publish.sh SHA NOTES DIR
#
# Replaces the "nightly" pre-release with a new one: its tag at SHA, its
# text from the file NOTES, its files all the files in DIR.
# Updates the "nightly" pre-release: its tag to SHA, its text from the
# file NOTES, and its files to all the files in DIR. If there is no
# release, it makes one.
#
# The script does not delete the release. If a step fails, the old
# release stays (with its old files or some new files), and the next run
# tries again.
#
# It needs GH_TOKEN and GH_REPO.
set -euo pipefail
@@ -11,12 +16,45 @@ sha=$1 notes=$2 dir=$3
shopt -s nullglob
files=("$dir"/*)
[ ${#files[@]} -gt 0 ] || { echo "::error::No files to publish in $dir"; exit 1; }
title="Nightly build ($(date -u +%Y-%m-%d), ${sha:0:7})"
gh release delete nightly --yes --cleanup-tag 2>/dev/null || true
# (a tag that has no release)
gh api -X DELETE "repos/$GH_REPO/git/refs/tags/nightly" 2>/dev/null || true
# release_id: prints the ID of the "nightly" release, or nothing
release_id() {
gh api "repos/$GH_REPO/releases/tags/nightly" --jq .id 2>/dev/null || true
}
gh release create nightly "${files[@]}" \
--prerelease --latest=false --target "$sha" \
--title "Nightly build ($(date -u +%Y-%m-%d), ${sha:0:7})" \
--notes-file "$notes"
# move_tag: puts the "nightly" tag at $sha, and makes the tag if it is
# not there
move_tag() {
if gh api "repos/$GH_REPO/git/ref/tags/nightly" --jq .object.sha >/dev/null 2>&1; then
gh api -X PATCH "repos/$GH_REPO/git/refs/tags/nightly" \
-f sha="$sha" -F force=true >/dev/null
else
gh api -X POST "repos/$GH_REPO/git/refs" \
-f ref=refs/tags/nightly -f sha="$sha" >/dev/null
fi
}
id=$(release_id)
if [ -z "$id" ]; then
# (no release: a new one, its tag made at $sha)
gh release create nightly "${files[@]}" \
--prerelease --latest=false --target "$sha" \
--title "$title" --notes-file "$notes"
exit 0
fi
move_tag
gh release edit nightly --prerelease --latest=false \
--title "$title" --notes-file "$notes"
gh release upload nightly "${files[@]}" --clobber
# the old files that this build did not make
keep=$(for f in "${files[@]}"; do basename "$f"; done)
gh api "repos/$GH_REPO/releases/$id/assets" --paginate --jq '.[] | "\(.id) \(.name)"' |
while read -r aid name; do
if ! grep -qxF "$name" <<<"$keep"; then
echo "Removing the old file $name"
gh api -X DELETE "repos/$GH_REPO/releases/assets/$aid"
fi
done