Skip to content

release: v0.7.2

release: v0.7.2 #4

Workflow file for this run

name: Release
on:
pull_request:
paths: ['internal/version/version.go']
push:
branches: ['main']
paths: ['internal/version/version.go']
jobs:
validate:
runs-on: ubuntu-latest
permissions:
contents: write # To be able to create draft releases
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
cache-dependency-path: '**/*.sum'
# 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))
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) && (github.event.pull_request.title != 'release: ${{ steps.version.outputs.tag }}')"
run: |-
echo 'Please update the PR title to "release: ${{ steps.version.outputs.tag }}" (instead of "${{ github.event.pull_request.title }}")'
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 --draft --generate-notes --target="${{ github.sha }}" --title="${{ steps.version.outputs.tag }}" ${{ contains(steps.version.outputs.tag, '-') && '--prerelease' || '' }}
env:
GH_TOKEN: ${{ github.token }}