showcase
- v0.2.4
- 37 commits
- 1 branch
- 6 tags
- updated
- CI 2/2
release.yml
3.0 KB · 74 lines
1# Release: when a tag like v1.2.3 is pushed, build the image for the server2# (linux/amd64), push it as 1.2.3 and latest, and create the Gitea release3# with the image digest and the commits since the previous tag.4#5# To run it by hand (Actions → release → Run workflow), name an existing6# tag: its code is built with this workflow, and its release is updated.7#8# Needs a repo secret REGISTRY_TOKEN: a Gitea access token with9# write:package. GITEA_TOKEN is made by Gitea for each run.10name: release1112on:13 push:14 tags: ["v*.*.*"]15 workflow_dispatch:16 inputs:17 tag:18 description: Existing tag to release, like v1.2.319 required: true2021permissions:22 contents: write # the Gitea release2324# The push goes through the Docker daemon on the runner's host, so the image25# needs a name that host resolves: Gitea's tailnet name, not the address the26# runner uses for Gitea (GITHUB_SERVER_URL, a Docker network name here).27env:28 IMAGE: code.aardvark-halibut.ts.net/daniel/showcase2930jobs:31 release:32 runs-on: ubuntu-latest33 env:34 TAG: ${{ inputs.tag || github.ref_name }}35 steps:36 - name: Check the tag37 run: |38 [[ $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "::error::$TAG isn't a tag like v1.2.3"; exit 1; }3940 - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.041 with:42 ref: refs/tags/${{ env.TAG }}43 fetch-depth: 0 # the previous tag, for the notes4445 - name: Build and push the image46 env:47 TOKEN: ${{ secrets.REGISTRY_TOKEN }}48 run: |49 printf '%s' "$TOKEN" | docker login "${IMAGE%%/*}" -u "$GITHUB_REPOSITORY_OWNER" --password-stdin50 docker build --platform linux/amd64 -t "$IMAGE:${TAG#v}" -t "$IMAGE:latest" .51 docker push "$IMAGE:latest"52 pushed=$(docker push "$IMAGE:${TAG#v}")53 echo "$pushed"54 echo "DIGEST=$(echo "$pushed" | awk '/digest: sha256:/ {print $3}')" >> "$GITHUB_ENV"55 docker logout "${IMAGE%%/*}"5657 # a rerun rebuilds the image with a new digest, so it updates the release58 - name: Create or update the Gitea release59 env:60 TOKEN: ${{ secrets.GITEA_TOKEN }}61 run: |62 # the job container reaches Gitea at the runner's address for it63 api=$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/releases64 prev=$(git describe --tags --abbrev=0 "$TAG^" 2>/dev/null || true)65 notes=$(git log --format='- %s' "${prev:+$prev..}$TAG")66 body=$(jq -n --arg tag "$TAG" --arg body "$(printf 'Image: `%s@%s`\n\n%s' "$IMAGE" "$DIGEST" "$notes")" \67 '{tag_name: $tag, name: $tag, body: $body}')68 if id=$(curl -fsS -H "Authorization: token $TOKEN" "$api/tags/$TAG" | jq -e .id); then69 method=PATCH url=$api/$id70 else71 method=POST url=$api72 fi73 curl -fsS -o /dev/null -X "$method" -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \74 --data "$body" "$url"