111 lines
3.8 KiB
YAML
111 lines
3.8 KiB
YAML
# Builds a release when a version tag (vX.Y.Z) is pushed: the image is tagged
|
|
# :X.Y.Z, :X.Y, :X and :latest in the Gitea registry, and a Gitea release is
|
|
# created with the matching section of CHANGELOG.md as notes. Nothing is
|
|
# deployed; Tom's Unraid follows :main through deploy.yml.
|
|
#
|
|
# A pre-release tag such as v0.2.0-rc.1 only gets its own :0.2.0-rc.1 tag and a
|
|
# release marked as pre-release; :latest and the short tags stay on the last
|
|
# stable version.
|
|
#
|
|
# Required repository secrets: REGISTRY_USER, REGISTRY_TOKEN (see deploy.yml).
|
|
# The release itself uses the job's built-in token.
|
|
|
|
name: Release
|
|
|
|
on:
|
|
push:
|
|
tags: ["v*"]
|
|
|
|
env:
|
|
IMAGE: gitea.anticarnist.de/tom/flypaper
|
|
|
|
jobs:
|
|
image:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
version: ${{ steps.version.outputs.version }}
|
|
prerelease: ${{ steps.version.outputs.prerelease }}
|
|
steps:
|
|
- name: Check out the source
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Read the version from the tag
|
|
id: version
|
|
run: |
|
|
version="${GITHUB_REF_NAME#v}"
|
|
if ! echo "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
|
|
echo "Tag $GITHUB_REF_NAME is not vX.Y.Z" >&2
|
|
exit 1
|
|
fi
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
{
|
|
echo "tags<<EOF"
|
|
echo "$IMAGE:$version"
|
|
case "$version" in
|
|
*-*) ;;
|
|
*)
|
|
echo "$IMAGE:${version%.*}"
|
|
echo "$IMAGE:${version%%.*}"
|
|
echo "$IMAGE:latest"
|
|
;;
|
|
esac
|
|
echo "EOF"
|
|
} >> "$GITHUB_OUTPUT"
|
|
case "$version" in
|
|
*-*) echo "prerelease=true" >> "$GITHUB_OUTPUT" ;;
|
|
*) echo "prerelease=false" >> "$GITHUB_OUTPUT" ;;
|
|
esac
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to the Gitea registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: gitea.anticarnist.de
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Build and push the release tags
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: true
|
|
build-args: |
|
|
VERSION=${{ steps.version.outputs.version }}
|
|
tags: ${{ steps.version.outputs.tags }}
|
|
|
|
release:
|
|
needs: image
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check out the source
|
|
uses: actions/checkout@v4
|
|
|
|
# The notes are the CHANGELOG.md section of this version, from its heading
|
|
# up to the next one. If the API call fails, the images are still pushed;
|
|
# the release can then be created by hand (deploy/unraid/README.md).
|
|
- name: Create the Gitea release
|
|
env:
|
|
VERSION: ${{ needs.image.outputs.version }}
|
|
PRERELEASE: ${{ needs.image.outputs.prerelease }}
|
|
TOKEN: ${{ github.token }}
|
|
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases
|
|
run: |
|
|
notes=$(awk -v version="$VERSION" '
|
|
/^## \[/ { if (found) exit; if (index($0, "[" version "]")) { found = 1; next } }
|
|
/^\[[^]]+\]: / { if (found) exit }
|
|
found { print }
|
|
' CHANGELOG.md)
|
|
[ -n "$notes" ] || notes="See CHANGELOG.md."
|
|
jq -n \
|
|
--arg tag "$GITHUB_REF_NAME" \
|
|
--arg name "Flypaper $VERSION" \
|
|
--arg body "$notes" \
|
|
--argjson prerelease "$PRERELEASE" \
|
|
'{tag_name: $tag, name: $name, body: $body, prerelease: $prerelease}' > release.json
|
|
curl -fsS -X POST "$API" \
|
|
-H "Authorization: token $TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
--data @release.json
|