-
Notifications
You must be signed in to change notification settings - Fork 11
53 lines (49 loc) · 2.39 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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' && steps.version.outputs.exists == 'false' && 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 }}