Repository navigation
218 lines (195 loc) · 7.14 KB
/
Copy pathrelease.yml
File metadata and controls
218 lines (195 loc) · 7.14 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: Release
on:
push:
tags:
- 'v[0-9]*'
- '!v[0-9]*-rc*'
workflow_dispatch:
inputs:
release_type:
description: Release type
required: true
default: release_candidate
type: choice
options:
- release_candidate
- stable
permissions:
contents: write
packages: write
pull-requests: read
jobs:
state:
name: Resolve release target
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.state.outputs.tag_name }}
head_sha: ${{ steps.state.outputs.head_sha }}
is_prerelease: ${{ steps.state.outputs.is_prerelease }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
ref: main
# Pushed tags remain stable releases. Manual runs can publish either a
# stable release or the next automatically numbered RC from current main.
- name: Resolve release target
id: state
env:
RELEASE_TYPE: ${{ inputs.release_type || 'stable' }}
run: |
set -euo pipefail
event_name="${{ github.event_name }}"
if [[ "$event_name" == "push" ]]; then
{
echo "tag_name=${{ github.ref_name }}"
echo "head_sha=${{ github.sha }}"
echo "is_prerelease=false"
} >> "$GITHUB_OUTPUT"
exit 0
fi
VERSION_NAME="$(jq -r '."version-name"' metadata.json)"
if [[ "$RELEASE_TYPE" == "release_candidate" ]]; then
TAG_PREFIX="v${VERSION_NAME}-rc"
LAST_RC="$(
git tag --list "${TAG_PREFIX}*" |
awk -v prefix="$TAG_PREFIX" '
index($0, prefix) == 1 {
number = substr($0, length(prefix) + 1)
if (number ~ /^[0-9]+$/) print number
}
' |
sort -n |
tail -n 1
)"
NEXT_RC=$(( ${LAST_RC:-0} + 1 ))
TAG_NAME="${TAG_PREFIX}${NEXT_RC}"
IS_PRERELEASE=true
else
TAG_NAME="v${VERSION_NAME}"
IS_PRERELEASE=false
fi
if git rev-parse --verify --quiet "refs/tags/${TAG_NAME}" > /dev/null; then
echo "Tag ${TAG_NAME} already exists; refusing to replace an existing release." >&2
exit 1
fi
HEAD_SHA="$(git rev-parse HEAD)"
{
echo "tag_name=${TAG_NAME}"
echo "head_sha=${HEAD_SHA}"
echo "is_prerelease=${IS_PRERELEASE}"
} >> "$GITHUB_OUTPUT"
echo "Release ${TAG_NAME} will be built from ${HEAD_SHA}." >> "$GITHUB_STEP_SUMMARY"
ci:
if: ${{ github.event_name == 'workflow_dispatch' || !contains(github.ref_name, '-') }}
needs: [state]
uses: ./.github/workflows/ci.yml
with:
checkout_ref: ${{ needs.state.outputs.head_sha }}
release:
name: Create GitHub Release
if: ${{ github.event_name == 'workflow_dispatch' || !contains(github.ref_name, '-') }}
runs-on: ubuntu-latest
needs: [state, ci]
steps:
- uses: actions/checkout@v7
with:
ref: ${{ needs.state.outputs.head_sha }}
- name: Download extension zip
uses: actions/download-artifact@v8
with:
name: extension-zip
path: dist/target/
- name: Resolve previous release
id: previous_release
env:
GH_TOKEN: ${{ github.token }}
IS_PRERELEASE: ${{ needs.state.outputs.is_prerelease }}
TAG_NAME: ${{ needs.state.outputs.tag_name }}
run: |
set -euo pipefail
PREVIOUS_TAG="$(
gh release list --limit 1000 --json tagName,isPrerelease,isDraft |
jq -r \
--arg target "$TAG_NAME" \
--argjson is_prerelease "$IS_PRERELEASE" '
def is_release_candidate:
.isPrerelease and (.tagName | test("-rc[0-9]+$"));
def is_stable_release:
(.isPrerelease | not)
and (.tagName | test("^v[0-9]+([.][0-9]+)*$"));
[
.[]
| select(.isDraft | not)
| select(.tagName != $target)
| select(
if $is_prerelease then
is_release_candidate or is_stable_release
else
is_stable_release
end
)
]
| first
| .tagName // empty
'
)"
echo "tag=${PREVIOUS_TAG}" >> "$GITHUB_OUTPUT"
if [[ -n "$PREVIOUS_TAG" ]]; then
echo "Release notes will compare ${PREVIOUS_TAG} with ${TAG_NAME}." >> "$GITHUB_STEP_SUMMARY"
elif [[ "$IS_PRERELEASE" == "true" ]]; then
echo "No previous stable release or release candidate was found." >> "$GITHUB_STEP_SUMMARY"
else
echo "No previous stable release was found." >> "$GITHUB_STEP_SUMMARY"
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.state.outputs.tag_name }}
target_commitish: ${{ needs.state.outputs.head_sha }}
name: ${{ needs.state.outputs.tag_name }}
files: |
dist/target/aurora-shell@luminusos.github.io.shell-extension.zip
dist/target/aurora-shell@luminusos.github.io.development.shell-extension.zip
generate_release_notes: true
previous_tag: ${{ steps.previous_release.outputs.tag }}
prerelease: ${{ needs.state.outputs.is_prerelease }}
# RCs replace the nightly line but do not remove earlier RCs.
- name: Delete superseded nightly pre-releases
if: ${{ needs.state.outputs.is_prerelease == 'true' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
gh release list \
--limit 1000 \
--json tagName,isPrerelease \
--jq '
.[]
| select(.isPrerelease)
| select(.tagName | test("-nightly[0-9]+$"))
| .tagName
' |
while IFS= read -r nightly_tag; do
gh release delete "$nightly_tag" --cleanup-tag --yes
echo "Deleted superseded nightly ${nightly_tag}." >> "$GITHUB_STEP_SUMMARY"
done
- name: Create maintenance branch
if: ${{ needs.state.outputs.is_prerelease == 'false' }}
env:
TAG_NAME: ${{ needs.state.outputs.tag_name }}
run: |
set -euo pipefail
if [[ ! "$TAG_NAME" =~ ^v([0-9]+) ]]; then
echo "Could not read the major version from ${TAG_NAME}." >&2
exit 1
fi
MAJOR="${BASH_REMATCH[1]}"
BRANCH="release/v${MAJOR}.x"
if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then
echo "Branch $BRANCH already exists, skipping."
else
echo "Creating branch $BRANCH"
git checkout -b "$BRANCH"
git push origin "$BRANCH"
fi