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: 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 ./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/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