-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (87 loc) · 3.07 KB
/
release.yaml
File metadata and controls
112 lines (87 loc) · 3.07 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Release
on:
workflow_dispatch:
push:
branches:
- main
paths:
- VERSION
- .github/workflows/release.yaml
permissions:
contents: write
jobs:
release:
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Verify main branch
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_REF_NAME}" != "main" ]]; then
echo "Releases can only be published from main" >&2
exit 1
fi
- name: Resolve version
id: version
shell: bash
run: |
set -euo pipefail
raw_version=$(tr -d '[:space:]' < VERSION)
version=${raw_version#v}
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "VERSION must contain a semantic version like 1.2.3 or v1.2.3" >&2
exit 1
fi
semver_tag="v$version"
major_tag="v${version%%.*}"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "semver_tag=$semver_tag" >> "$GITHUB_OUTPUT"
echo "major_tag=$major_tag" >> "$GITHUB_OUTPUT"
- name: Check existing tags
id: tags
shell: bash
run: |
set -euo pipefail
git fetch --tags --force
semver_tag='${{ steps.version.outputs.semver_tag }}'
current_sha=$(git rev-parse HEAD)
if git rev-parse "$semver_tag" >/dev/null 2>&1; then
existing_sha=$(git rev-list -n 1 "$semver_tag")
if [[ "$existing_sha" == "$current_sha" ]]; then
echo "publish=false" >> "$GITHUB_OUTPUT"
echo "message=Tag $semver_tag already exists on this commit" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Version tag $semver_tag already exists on a different commit" >&2
exit 1
fi
echo "publish=true" >> "$GITHUB_OUTPUT"
echo "message=Publishing $semver_tag from $current_sha" >> "$GITHUB_OUTPUT"
- name: Create release tags
if: steps.tags.outputs.publish == 'true'
shell: bash
run: |
set -euo pipefail
semver_tag='${{ steps.version.outputs.semver_tag }}'
major_tag='${{ steps.version.outputs.major_tag }}'
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git tag -a "$semver_tag" -m "Release $semver_tag"
git tag -fa "$major_tag" -m "Release $semver_tag"
git push origin "refs/tags/$semver_tag"
git push origin "refs/tags/$major_tag" --force
- name: Write summary
shell: bash
run: |
{
echo "## Release"
echo
echo "- Version: ${{ steps.version.outputs.semver_tag }}"
echo "- Major tag: ${{ steps.version.outputs.major_tag }}"
echo "- Result: ${{ steps.tags.outputs.message }}"
} >> "$GITHUB_STEP_SUMMARY"