-
Notifications
You must be signed in to change notification settings - Fork 6
324 lines (270 loc) · 11.8 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
name: Release New Version
on:
workflow_dispatch:
inputs:
releaseType:
description: 'Release type - major, minor or patch'
required: false
default: ''
preReleaseFlavor:
description: 'Pre-Release flavor - rc, beta, or anything'
required: false
default: ''
jobs:
create-release-draft:
runs-on: ubuntu-latest
steps:
- name: Check Tag
id: prep
run: |
TAG_NAME=$(curl -s -H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases | \
jq -r "[.[] | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .tag_name | select (. != null)")
IS_DRAFT=$(curl -s -H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases | \
jq -r "[.[] | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .draft | select (. != null)")
if [ -n "${TAG_NAME}" ] && [ "${IS_DRAFT}" == "false" ];then
echo "A release has already been published for this run_id (${{ github.run_id }} / ${TAG_NAME})."
exit 1
fi
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v4
if: ${{ steps.prep.outputs.tag_name == '' }}
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Setup Node
if: ${{ steps.prep.outputs.tag_name == '' }}
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Setup Git
if: ${{ steps.prep.outputs.tag_name == '' }}
run: |
git config --global user.name "devx-sauce-bot"
git config --global user.email "devx.bot@saucelabs.com"
- name: Install Dependencies
if: ${{ steps.prep.outputs.tag_name == '' }}
run: npm ci
- name: Generate (Pre-)Release Draft
if: ${{ steps.prep.outputs.tag_name == '' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
if [ -z "${{ github.event.inputs.releaseType }}" ] && [ -z "${{ github.event.inputs.preReleaseFlavor }}" ];then
echo "No release type provided."
exit 1
fi
if [ -n "${{ github.event.inputs.preReleaseFlavor }}" ];then
PRE_RELEASE_ARGS="--preRelease=${{ github.event.inputs.preReleaseFlavor }} --github.preRelease"
fi
npx release-it ${{ github.event.inputs.releaseType }} ${PRE_RELEASE_ARGS}
release-windows-bundle:
runs-on: windows-latest
needs: [create-release-draft]
steps:
- name: Find Matching Draft Tag
# Fetches the `asset_id` of the uploaded bundle. A non-empty `asset_id` signals a successful upload, preventing duplicate uploads in retry attempts.
id: prep
run: |
$res = Invoke-WebRequest -Uri "https://api.github.com/repos/${{ github.repository }}/releases" -Headers @{'Authorization' = "token ${{ github.token }}"}
$jsonObj = ConvertFrom-Json $([String]::new($res.Content))
$selectedRelease = $null
Foreach ($release in $jsonObj)
{
if ( ! $release.body -contains "- jobId: ${{ github.run_id }}}\\n") {
continue
}
if ( ! $release.draft ) {
continue
}
$selectedRelease = $release
break
}
if ( $null -eq $selectedRelease ) {
exit 1
}
$selectedAsset = $null
Foreach ($asset in $selectedRelease.assets) {
if ($asset.name -eq "cypress-windows-amd64.zip") {
$selectedAsset = $asset
}
}
$tagName = $selectedRelease.tag_name
$releaseId = $selectedRelease.id
$assetId = $selectedAsset.id
echo "version=$tagName" >> $Env:GITHUB_OUTPUT
echo "release_id=$releaseId" >> $Env:GITHUB_OUTPUT
echo "asset_id=$assetId" >> $Env:GITHUB_OUTPUT
- run: Write-Output "${{ steps.prep.outputs.release_id }} - ${{ steps.prep.outputs.version }} - ${{ steps.prep.outputs.asset_id }}"
- name: Checkout
uses: actions/checkout@v4
if: ${{ steps.prep.outputs.asset_id == '' }}
with:
ref: ${{ steps.prep.outputs.version }}
- name: Setup Node
if: ${{ steps.prep.outputs.asset_id == '' }}
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Update Release Version
if: ${{ steps.prep.outputs.asset_id == '' }}
run: |
npm version --no-git-tag-version ${{ steps.prep.outputs.version }}
- name: Install Dependencies
run: npm ci --production
if: ${{ steps.prep.outputs.asset_id == '' }}
- name: Bundle Directory
if: ${{ steps.prep.outputs.asset_id == '' }}
run: bash ./scripts/bundle.sh
- name: List Bundle Contents
if: ${{ steps.prep.outputs.asset_id == '' }}
run: ls -R bundle/
- name: Archive Bundle
if: ${{ steps.prep.outputs.asset_id == '' }}
uses: azure/powershell@v1
with:
inlineScript: |
Compress-Archive bundle/ cypress-windows-amd64.zip
azPSVersion: '3.1.0'
- name: Upload Release Asset
if: ${{ steps.prep.outputs.asset_id == '' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh release upload ${{ steps.prep.outputs.version }} cypress-windows-amd64.zip
release-macos-bundle:
# macos-latest is arm only
runs-on: macos-13
needs: [create-release-draft]
steps:
- name: Find Matching Draft Tag
# Fetches the `asset_id` of the uploaded bundle. A non-empty `asset_id` signals a successful upload, preventing duplicate uploads in retry attempts.
id: prep
run: |
VERSION=$(curl -s -H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases | \
jq -r "[.[] | select(.draft == true) | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .tag_name")
RELEASE_ID=$(curl -s -H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases | \
jq -r "[.[] | select(.draft == true) | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .id")
if [ "${VERSION}" = "" ];then
echo "No draft version found"
exit 1
fi
ASSET_ID=$(curl -s -H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases | \
jq -r "[.[] | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .assets | .[] | select(.name == \"cypress-macos-amd64.zip\") | .id | select(. != null)")
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "release_id=${RELEASE_ID}" >> $GITHUB_OUTPUT
echo "asset_id=${ASSET_ID}" >> $GITHUB_OUTPUT
- run: echo "${{ steps.prep.outputs.release_id }} - ${{ steps.prep.outputs.version }} - ${{ steps.prep.outputs.asset_id }}"
- name: Checkout
uses: actions/checkout@v4
if: ${{ steps.prep.outputs.asset_id == '' }}
with:
ref: ${{ steps.prep.outputs.version }}
- name: Setup Node
if: ${{ steps.prep.outputs.asset_id == '' }}
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Update Release Version
if: ${{ steps.prep.outputs.asset_id == '' }}
run: |
npm version --no-git-tag-version ${{ steps.prep.outputs.version }}
- name: Install Dependencies
run: npm ci --production
if: ${{ steps.prep.outputs.asset_id == '' }}
- name: Bundle Directory
if: ${{ steps.prep.outputs.asset_id == '' }}
run: bash ./scripts/bundle.sh
- name: List Bundle Contents
if: ${{ steps.prep.outputs.asset_id == '' }}
run: ls -R bundle/
- name: Archive Bundle
if: ${{ steps.prep.outputs.asset_id == '' }}
run: zip --symlinks -r cypress-macos-amd64.zip bundle/
- name: Upload Release Asset
if: ${{ steps.prep.outputs.asset_id == '' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh release upload ${{ steps.prep.outputs.version }} cypress-macos-amd64.zip
publish-release:
runs-on: ubuntu-latest
needs: [release-windows-bundle, release-macos-bundle]
steps:
- name: Find Matching Draft Tag
id: prep
run: |
RELEASE_ID=$(curl -s -H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases | \
jq -r "[.[] | select(.draft == true) | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .id")
if [ "${RELEASE_ID}" = "" ];then
echo "No draft version found"
exit 1
fi
echo "release_id=${RELEASE_ID}" >> $GITHUB_OUTPUT
- name: Publish Release
run: |
curl -f -X PATCH -H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases/${{ steps.prep.outputs.release_id }} \
-d '{"draft":"false"}'
# Post Deploy Tests
post-release-windows-tests:
runs-on: ubuntu-latest
needs: publish-release
env:
SAUCE_ACCESS_KEY: ${{secrets.SAUCE_ACCESS_KEY}}
SAUCE_USERNAME: ${{secrets.SAUCE_USERNAME}}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup saucectl
uses: saucelabs/saucectl-run-action@v4
env:
GITHUB_TOKEN: ${{ github.token }}
with:
skip-run: true
- name: Parse Release Version
id: parse_version
run: |
VERSION=$(curl -s -H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases | \
jq -r "[.[] | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .tag_name")
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Cloud Tests
working-directory: ./tests/post-release
run: |
saucectl run --runner-version "url: https://github.com/saucelabs/sauce-cypress-runner/releases/download/${{ steps.parse_version.outputs.version }}/cypress-windows-amd64.zip" --config ./.sauce/config_win.yml
post-release-macos-tests:
runs-on: ubuntu-latest
needs: publish-release
env:
SAUCE_ACCESS_KEY: ${{secrets.SAUCE_ACCESS_KEY}}
SAUCE_USERNAME: ${{secrets.SAUCE_USERNAME}}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup saucectl
uses: saucelabs/saucectl-run-action@v4
env:
GITHUB_TOKEN: ${{ github.token }}
with:
skip-run: true
- name: Parse Release Version
id: parse_version
run: |
VERSION=$(curl -s -H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/releases | \
jq -r "[.[] | select(.body | contains(\"- jobId: ${{ github.run_id }}\\n\"))] | first | .tag_name")
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Cloud Tests
working-directory: ./tests/post-release
run: |
saucectl run --runner-version "url: https://github.com/saucelabs/sauce-cypress-runner/releases/download/${{ steps.parse_version.outputs.version }}/cypress-macos-amd64.zip" --config ./.sauce/config_mac.yml