Files
uptimesebi/.gitea/workflows/release.yaml
T
Sebastian UnterschützandClaude Opus 5.5 8cc5c0266a
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 9m11s
ci / lint (pull_request) Successful in 12m40s
ci / build (pull_request) Canceled after 0s
ci / image (pull_request) Canceled after 0s
fix(release): publish the Helm chart only once the images exist
The release job finished about 20 minutes before the ci workflow had
pushed the tag's images. Clusters following the chart repository then
rolled out a release whose image did not exist yet: the migrate hook
sat in ImagePullBackOff until its deadline and the upgrade failed
(0.2.1, 0.3.0 and 0.4.0 on app.uptimesebi.net).

Wait up to 90 minutes for the API, checker and status page images of
the tag before publishing the chart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 19:59:29 +01:00

133 lines
6.5 KiB
YAML

name: release
# Runs for release tags, which `make release` creates. Only the Owners team
# may push v* tags (tag protection), and only tags on main are released.
# The image of a tag is built by the ci workflow.
on:
push:
tags: ["v*"]
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
# The notes need the history back to the previous release.
fetch-depth: 0
- name: Install Go
run: |
v="$(awk '/^go /{print $2}' go.mod)"
curl -fsSL "https://go.dev/dl/go${v}.linux-amd64.tar.gz" | tar -C /usr/local -xz
echo /usr/local/go/bin >> "$GITHUB_PATH"
- name: Check tag
run: |
go run ./tools/release check "$GITHUB_REF_NAME"
# Only code that reached main through a protected merge is
# released, this workflow included: a tag on any other commit,
# e.g. one with a changed workflow, publishes nothing.
git fetch -q origin main
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
echo "::error::$GITHUB_REF_NAME does not point to a commit on main; not releasing."
exit 1
fi
- name: Build frontend
run: npm ci --no-audit --no-fund && npm run build
- name: Package Helm chart
run: |
curl -fsSL "https://get.helm.sh/helm-v3.19.0-linux-amd64.tar.gz" | tar -xz -C /usr/local/bin --strip-components=1 linux-amd64/helm
# Chart and app version follow the release; image tags drop the v.
helm package deploy/helm/uptimesebi --version "${GITHUB_REF_NAME#v}" --app-version "${GITHUB_REF_NAME#v}" -d dist
- name: Build binaries
run: |
set -eu
pkg=git.zb-server.de/ZB-Server/uptimesebi/internal/buildinfo
commit="$(git rev-parse --short=12 HEAD)"
for platform in linux/amd64 linux/arm64 linux/arm/v7 linux/arm/v6; do
IFS=/ read -r os arch variant <<< "$platform"
dir="uptimesebi_${GITHUB_REF_NAME#v}_${os}_${arch}${variant}"
CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=${variant#v} go build -trimpath \
-ldflags "-s -w -X $pkg.Version=$GITHUB_REF_NAME -X $pkg.Commit=$commit" \
-o "dist/$dir/" ./cmd/...
cp LICENSE README.md .env.example "dist/$dir/"
tar -C dist -czf "dist/$dir.tar.gz" "$dir"
done
go run ./tools/release sbom "$GITHUB_REF_NAME" dist/uptimesebi_*_linux_amd64/{api,checker,statuspage} > dist/sbom.spdx.json
(cd dist && sha256sum ./*.tar.gz ./*.tgz ./sbom.spdx.json | sed 's| \./| |' > SHA256SUMS)
cat dist/SHA256SUMS
- name: Sign checksums
env:
RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }}
run: |
if [ -z "$RELEASE_SIGNING_KEY" ]; then
echo "::warning::RELEASE_SIGNING_KEY is not set; the release is not signed."
exit 0
fi
go run ./tools/release sign dist/SHA256SUMS "$GITHUB_REF_NAME"
go run ./tools/release verify dist/SHA256SUMS
- name: Publish release
env:
TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
set -eu
api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY"
if curl -fsS -o /dev/null -H "Authorization: token $TOKEN" "$api/releases/tags/$GITHUB_REF_NAME"; then
echo "Release $GITHUB_REF_NAME exists already; delete it to publish again." >&2
exit 1
fi
go run ./tools/release notes -json "$GITHUB_REF_NAME" > release.json
id="$(curl -fsS -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
--data-binary @release.json "$api/releases" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)"
for f in dist/*.tar.gz dist/*.tgz dist/sbom.spdx.json dist/SHA256SUMS dist/SHA256SUMS.minisig; do
[ -f "$f" ] || continue
curl -fsS -o /dev/null -X POST -H "Authorization: token $TOKEN" \
-F "attachment=@$f" "$api/releases/$id/assets?name=$(basename "$f")"
done
# The ci workflow builds the images of this tag after lint and tests,
# which takes longer than this job. A chart published before them makes
# clusters that follow the chart repository roll out a release whose
# images do not exist yet (ImagePullBackOff in the migrate hook).
- name: Wait for the images
env:
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
run: |
set -eu
if [ -z "$PACKAGE_TOKEN" ]; then
echo "::warning::PACKAGE_TOKEN is not set; not waiting for the images."
exit 0
fi
host="${GITHUB_SERVER_URL#*://}"
owner="$(printf '%s' "${GITHUB_REPOSITORY%/*}" | tr 'A-Z' 'a-z')"
tag="${GITHUB_REF_NAME#v}"
accept="application/vnd.oci.image.index.v1+json,application/vnd.oci.image.manifest.v1+json,application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.docker.distribution.manifest.v2+json"
deadline=$(( $(date +%s) + 90 * 60 ))
for repo in uptimesebi uptimesebi-checker uptimesebi-statuspage; do
until
token="$(curl -fsS --user "$GITHUB_ACTOR:$PACKAGE_TOKEN" \
"$GITHUB_SERVER_URL/v2/token?service=container_registry&scope=repository:$owner/$repo:pull" \
| sed -n 's/.*"token":"\([^"]*\)".*/\1/p')"
curl -fsS -o /dev/null -I -H "Authorization: Bearer $token" -H "Accept: $accept" \
"$GITHUB_SERVER_URL/v2/$owner/$repo/manifests/$tag"
do
if [ "$(date +%s)" -ge "$deadline" ]; then
echo "::error::$host/$owner/$repo:$tag did not appear within 90 minutes; the chart is not published."
exit 1
fi
echo "waiting for $host/$owner/$repo:$tag"
sleep 30
done
echo "$host/$owner/$repo:$tag is there"
done
# helm repo add uptimesebi <server>/api/packages/<owner>/helm
- name: Publish Helm chart
env:
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
run: |
if [ -z "$PACKAGE_TOKEN" ]; then
echo "::warning::PACKAGE_TOKEN is not set; the chart is only attached to the release."
exit 0
fi
owner="$(printf '%s' "${GITHUB_REPOSITORY%/*}" | tr 'A-Z' 'a-z')"
curl -fsS --user "$GITHUB_ACTOR:$PACKAGE_TOKEN" -X POST --upload-file dist/uptimesebi-*.tgz \
"$GITHUB_SERVER_URL/api/packages/$owner/helm/api/charts"