Files
jcoffey-dev a38d735f50
ci / test (pull_request) Successful in 1m46s
ci: bump discourse-release to ba4cde7 (Releases / Release Candidates)
Stable releases are announced in the forum's Releases category and
pre-releases in Release Candidates (muted, kept out of Latest), instead of
Announcements.
2026-11-19 13:25:41 -07:00

100 lines
4.6 KiB
YAML

# SPDX-FileCopyrightText: 2026 Coffey Labs LLC
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# A v* tag is a release: the binaries for linux/amd64 and linux/arm64, with
# SHA256SUMS, attached to a Gitea Release, then announced.
#
# Built here, not on GitHub like the Rust and image builds: the installer is
# static Go, so both architectures cross-compile on this runner in under a
# minute, and the BUILD_ON switch has nothing to offload. GitHub's copy of the
# Release is made with ~/.config/gitea-mirror/release-sync.py.
#
# The tag must be annotated and on main or release/2026 (the dated line,
# which keeps getting fixes until 27.1 ships), and named v<year>.<month>.<day>[.<n>]
# (scripts/build-release.sh checks the name). Its annotation is the release
# notes. The Release is a draft until every file is attached, so it is never
# visible half-filled; a draft this run made is deleted if an upload fails.
#
# The job image is pinned by digest, and the only actions are coffey-labs/actions
# ones pinned by SHA.
name: release
on:
push:
tags: ["v*"]
defaults:
run:
shell: bash
jobs:
release:
runs-on: light
container:
image: golang:1.26-bookworm@sha256:dc40a13b61304647ed7e5d581d246b86413dfc29d63c6d018310feb93cd98fc0 # 1.26-bookworm (1.26.11)
env:
TAG: ${{ github.ref_name }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
# Full history and tags: the ancestry check and the tag's annotation
# both need them.
- uses: coffey-labs/actions/checkout@fab0c4d45e0162963965f1555df27b7bed5e20ec
with:
fetch-depth: 0
- name: The tag is annotated and on main or release/2026
run: |
set -eu
c="$(git rev-parse "$TAG^{commit}")"
git merge-base --is-ancestor "$c" origin/main \
|| git merge-base --is-ancestor "$c" origin/release/2026 \
|| { echo "$TAG is not on main or release/2026" >&2; exit 1; }
[ "$(git cat-file -t "refs/tags/$TAG")" = tag ] \
|| { echo "$TAG is a lightweight tag; its annotation is the release notes" >&2; exit 1; }
- run: go test -count=1 ./...
- run: scripts/build-release.sh "$TAG" dist
- name: Release on Gitea
run: |
set -euo pipefail
apt-get -qq update >/dev/null && apt-get -qq install -y --no-install-recommends jq >/dev/null
API="$CI_SERVER_INTERNAL/api/v1/repos/$GITHUB_REPOSITORY"
auth=(-H "Authorization: token $TOKEN")
notes="$(git for-each-ref "refs/tags/$TAG" --format='%(contents)' | sed -e '/^-----BEGIN [A-Z ]*SIGNATURE-----$/,$d')" # PGP or SSH
notes="$notes"$'\n\n'"Static binaries for linux/amd64 and linux/arm64. Verify with SHA256SUMS."
created=0
id="$(curl -fsS "${auth[@]}" "$API/releases/tags/$TAG" 2>/dev/null | jq -r '.id // empty' || true)"
if [ -z "$id" ]; then
id="$(curl -fsS "${auth[@]}" -H 'Content-Type: application/json' \
-d "$(jq -n --arg t "$TAG" --arg b "$notes" '{tag_name:$t, name:$t, draft:true, body:$b}')" \
"$API/releases" | jq -r '.id // empty')"
[ -n "$id" ] || { echo "could not create the release" >&2; exit 1; }
created=1
fi
have="$(curl -fsS "${auth[@]}" "$API/releases/$id/assets" | jq -r '.[].name')"
for f in dist/inbuxa-linux-amd64 dist/inbuxa-linux-arm64 dist/SHA256SUMS; do
n="$(basename "$f")"
if grep -qxF "$n" <<<"$have"; then echo "already attached: $n"; continue; fi
echo "uploading $n"
curl -fsS --retry 3 --retry-all-errors -o /dev/null "${auth[@]}" --form "attachment=@$f" "$API/releases/$id/assets?name=$n" || {
[ "$created" = 1 ] && curl -sS -o /dev/null "${auth[@]}" -X DELETE "$API/releases/$id"
exit 1
}
done
if [ "$created" = 1 ]; then
curl -fsS -o /dev/null "${auth[@]}" -H 'Content-Type: application/json' -X PATCH \
-d '{"draft":false}' "$API/releases/$id"
fi
echo "released $TAG"
# The Release above is made with the job's own token, and Gitea starts no
# workflow for what the Actions bot does, so announce.yml never sees it.
# The action makes one topic per tag, so a re-run cannot post twice.
announce:
needs: [release]
runs-on: light
steps:
- uses: coffey-labs/actions/discourse-release@ba4cde7c3b47cc9f93c0080da8ba838a1ef1845b
with:
api-key: ${{ secrets.DISCOURSE_RELEASE_KEY }}
discord-webhook: ${{ secrets.DISCORD_RELEASE_WEBHOOK }}
tag: ${{ github.ref_name }}