ci(release): use shared reusable go-release workflow
All checks were successful
CI / Test (push) Successful in 55s
Release / release (push) Successful in 2m25s
CI / Build (push) Successful in 42s

Replace the self-contained release.yml with a thin caller of
gmgauthier/gitea-workflows/.gitea/workflows/go-release.yml@v1. Standardizes
on the shared pipeline (make cross + jq-built idempotent release). Release
notes are now the standard install-instructions body.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Greg Gauthier 2026-06-13 13:43:38 +01:00
parent 6637ecc9e2
commit fd4694a02b

View File

@ -10,160 +10,7 @@ permissions:
jobs:
release:
name: Create Release
runs-on: ubuntu-gitea
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: gmgauthier/gitea-workflows/.gitea/workflows/go-release.yml@v1
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.2'
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download Go modules
run: go mod download
- name: Build for multiple platforms
shell: bash
run: |
VERSION=${GITHUB_REF#refs/tags/}
COMMIT=$(git rev-parse --short HEAD)
DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
go mod tidy
make cross VERSION="$VERSION" COMMIT="$COMMIT" DATE="$DATE"
# go mod tidy ensures go.sum is complete for this Go version in CI (common fix for "missing go.sum entry" during cross builds)
# make cross (with deps) handles the loop + ldflags
- name: Prepare assets
shell: bash
run: |
VERSION=${GITHUB_REF#refs/tags/}
# Tar each platform binary and remove the raw binary as we go, so we
# ship only the .tar.gz files (matrix-agnostic; the glob expands once
# at loop start, before any tarballs exist).
for bin in build/gostations-* ; do
[ -f "$bin" ] || continue
OSARCH=$(basename "$bin" | sed 's/gostations-//' | sed 's/\.exe$//')
tar czf "build/gostations-${OSARCH}-${VERSION}.tar.gz" -C build "$(basename "$bin")"
rm -f "$bin"
done
sha256sum build/gostations-*.tar.gz | tee build/checksums.txt
# Include useful scripts from repo (if present)
[ -f scripts/gostations-install.sh ] && cp scripts/gostations-install.sh build/
[ -f scripts/gostations-install.ps1 ] && cp scripts/gostations-install.ps1 build/
- name: Install dependencies
run: apt update && apt install -y jq
- name: Create Release & Upload Assets
shell: bash
env:
GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }}
# Public DNS name of this instance, used for the user-facing download
# links in the release body. Set per instance, e.g.
# staging: PUBLIC_HOST=gitea.scriptorium
# prod: PUBLIC_HOST=repos.gmgauthier.com
PUBLIC_HOST: ${{ vars.PUBLIC_HOST }}
run: |
set -euo pipefail
# API calls go to the instance the runner is already talking to
# (GITHUB_SERVER_URL — correct scheme/host/port, reachable from CI).
GITEA_API=${GITHUB_SERVER_URL%/}/api/v1
# Public host for the download links baked into the release body.
HOST=${PUBLIC_HOST:?PUBLIC_HOST variable is not set on this Gitea instance}
echo "API base: ${GITEA_API}"
echo "Public host for release links: ${HOST}"
VERSION=${GITHUB_REF#refs/tags/}
REPO=${GITHUB_REPOSITORY}
echo "Creating release for tag ${VERSION} on ${REPO}..."
# Create the release, or reuse it if one already exists for this tag.
# This keeps the step idempotent: re-runs and duplicate tag triggers
# don't fail, and a run that died mid-upload can be retried cleanly.
HTTP_CODE=$(curl --silent --show-error -o release.json -w '%{http_code}' \
-X POST "${GITEA_API}/repos/${REPO}/releases" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"${VERSION}\",
\"name\": \"gostations ${VERSION}\",
\"target\": \"${GITHUB_SHA}\",
\"draft\": false,
\"body\": \"## Quick Install\n\n### Bash (Linux/macOS)\n\n\`\`\`bash\ncurl -L https://${HOST}/${REPO}/releases/download/${VERSION}/gostations-install.sh | VERSION=${VERSION} bash\n\`\`\`\n\n### PowerShell (Windows/macOS/Linux)\n\n\`\`\`powershell\nirm https://${HOST}/${REPO}/releases/download/${VERSION}/gostations-install.ps1 | iex\n\`\`\`\n\nPlatform binaries (tar.gz) + checksums.txt are attached. See README.md and CHANGELOG (if present) for details. Legacy wmenu UI still available with --legacy.\"
}")
echo "Create response (HTTP ${HTTP_CODE}):"
cat release.json; echo
case "${HTTP_CODE}" in
201)
RELEASE_ID=$(jq -r '.id // empty' release.json)
echo "Release created with ID: ${RELEASE_ID}"
;;
409)
echo "Release for ${VERSION} already exists; reusing it (idempotent re-run)."
RELEASE_ID=$(curl --fail --silent --show-error \
"${GITEA_API}/repos/${REPO}/releases/tags/${VERSION}" \
-H "Authorization: token ${GITEA_TOKEN}" | jq -r '.id // empty')
;;
*)
echo "ERROR: unexpected HTTP ${HTTP_CODE} creating release. Check the response above and your RELEASE_TOKEN secret (needs write access)."
exit 1
;;
esac
if [ -z "${RELEASE_ID}" ]; then
echo "ERROR: could not determine release ID for ${VERSION}."
exit 1
fi
echo "Using release ID: ${RELEASE_ID}"
# Existing assets on this release, so re-runs replace rather than 409.
EXISTING_ASSETS=$(curl --fail --silent --show-error \
"${GITEA_API}/repos/${REPO}/releases/${RELEASE_ID}/assets" \
-H "Authorization: token ${GITEA_TOKEN}")
for asset in build/* ; do
name=$(basename "$asset")
mime="application/octet-stream"
[[ "$name" =~ \.tar\.gz$ ]] && mime="application/gzip"
[[ "$name" =~ \.(txt|sh|ps1)$ ]] && mime="text/plain"
# If an asset of this name already exists, delete it first so the
# upload replaces it instead of returning a conflict.
OLD_ID=$(printf '%s' "${EXISTING_ASSETS}" | jq -r --arg n "$name" \
'.[] | select(.name == $n) | .id' | head -n1)
if [ -n "${OLD_ID}" ]; then
echo "Replacing existing asset: $name (id ${OLD_ID})"
curl --fail --silent --show-error -X DELETE \
"${GITEA_API}/repos/${REPO}/releases/${RELEASE_ID}/assets/${OLD_ID}" \
-H "Authorization: token ${GITEA_TOKEN}"
fi
echo "Uploading asset: $name"
curl --fail --silent --show-error -X POST "${GITEA_API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${name}" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: ${mime}" \
--data-binary "@$asset"
done
echo "All assets uploaded successfully."
app_name: gostations
secrets: inherit