release: v0.9.0 #45
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
pull_request: | |
paths: [internal/version/version.go] | |
push: | |
branches: [main] | |
paths: [internal/version/version.go] | |
permissions: read-all | |
jobs: | |
validate: | |
name: Validate Release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # To be able to create draft releases | |
steps: | |
- name: Checkout | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
- name: Setup go | |
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 | |
with: | |
go-version: stable | |
cache-dependency-path: '**/go.mod' | |
# Obtains the current configured version tag from source, and verifies it is a valid tag name. | |
# Also checks whether the tag already exists. | |
- name: Determine version | |
id: version | |
run: |- | |
set -euo pipefail | |
# From https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string, with added v prefix. | |
VERSION_TAG_REGEX='^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-((0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$' | |
version=$(grep -E "${VERSION_TAG_REGEX}" <(go run . version | cut -d' ' -f 2)) | |
echo "tag=${version}" >> "${GITHUB_OUTPUT}" | |
if gh release view "${version}" --json isDraft; then | |
echo "exists=true" >> "${GITHUB_OUTPUT}" | |
else | |
echo "exists=false" >> "${GITHUB_OUTPUT}" | |
fi | |
env: | |
GH_TOKEN: ${{ github.token }} | |
# If this is a pull request, and the release does not yet exist, the PR title must be "release: <tag>" | |
- name: 'Pull Request title must be "release: ${{ steps.version.outputs.tag }}"' | |
if: "github.event_name == 'pull_request' && !fromJSON(steps.version.outputs.exists) && format('release: {0}', steps.version.outputs.tag) != github.event.pull_request.title" | |
run: |- | |
echo "Please update the PR title to \"release: ${{ steps.version.outputs.tag }}\" (instead of ${EVENT_PR_TITLE})" | |
exit 1 | |
env: | |
EVENT_PR_TITLE: ${{ toJSON(github.event.pull_request.title) }} | |
# Release must not already exist (if the PR title suggests this is intended to be a release) | |
- name: Release ${{ steps.version.outputs.tag }} already exists | |
if: github.event_name == 'pull_request' && fromJSON(steps.version.outputs.exists) && startsWith(github.event.pull_request.title, 'release:') | |
run: |- | |
echo 'A release already exists for tag ${{ steps.version.outputs.tag }}. Please update to another version.' | |
exit 1 | |
# If the release does not yet exist, create a draft release targeting this commit. | |
- name: Create draft release | |
if: github.event_name == 'push' && steps.version.outputs.exists == 'false' | |
run: |- | |
gh release create '${{ steps.version.outputs.tag }}' --draft --generate-notes --target='${{ github.sha }}' --title='${{ steps.version.outputs.tag }}' ${{ contains(steps.version.outputs.tag, '-') && '--prerelease' || '' }} | |
env: | |
GH_TOKEN: ${{ github.token }} |