Repository navigation
219 lines (212 loc) · 7.97 KB
/
Copy pathrelease.yml
File metadata and controls
219 lines (212 loc) · 7.97 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
219
name: 'Ionic Production Release'
on:
workflow_call:
inputs:
version:
description: 'Which version should be published?'
required: true
type: string
tag:
description: 'Which npm tag should this be published to?'
required: true
type: string
preid:
description: 'Which prerelease identifier should be used? This is only needed when version is "prepatch", "preminor", "premajor", or "prerelease".'
required: false
type: string
permissions:
contents: read
id-token: write
jobs:
validate_version:
name: ✅ Validate Version Input
runs-on: ubuntu-latest
steps:
- name: 🔎 Ensure version is allowed
env:
VERSION: ${{ inputs.version }}
run: |
case "$VERSION" in
patch|minor|major|prepatch|preminor|premajor|prerelease)
exit 0
;;
*)
echo "::error::Invalid version input: '$VERSION'. Allowed values: patch, minor, major, prepatch, preminor, premajor, prerelease."
exit 1
;;
esac
shell: bash
release-ionic:
needs: [validate_version]
permissions:
contents: read
id-token: write
uses: ./.github/workflows/release-ionic.yml
with:
tag: ${{ inputs.tag }}
version: ${{ inputs.version }}
preid: ${{ inputs.preid }}
finalize-release:
needs: [release-ionic]
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ secrets.IONITRON_TOKEN }}
fetch-depth: 0
- name: Configure Identity
# Commits from github-actions do not
# trigger other GitHub Actions. As a result,
# we publish releases from Ionitron instead
# so actions run when merging the release branch
# back into main.
run: |
git config user.name ionitron
git config user.email hi@ionicframework.com
shell: bash
- name: Create GitHub Release
run: lerna version ${{ inputs.version }} --yes --force-publish='*' --conventional-commits --create-release github --preid=${{ inputs.preid }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
update-package-lock:
# This needs to run after finalize-release
# because we also push to the repo in that
# job. If these jobs ran in parallel then it is
# possible for them to push at the same time.
needs: [finalize-release]
runs-on: ubuntu-latest
# This is a backstop for the retry loop in
# Resolve Package Locks, which fails with its
# own message first.
timeout-minutes: 30
permissions:
contents: write
id-token: write
outputs:
# This says the new versions resolved on npm,
# which is not the same as the job passing.
resolved: ${{ steps.resolve.outputs.resolved }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Pull the latest version of the reference
# branch instead of the revision that triggered
# the workflow otherwise we won't get the commit
# created in the previous job and this next job
# will fail.
with:
ref: ${{ github.ref }}
- name: Configure Identity
# Commits from github-actions do not
# trigger other GitHub Actions. As a result,
# we push from Ionitron instead so actions
# run when merging the release branch
# back into main.
run: |
git config user.name ionitron
git config user.email hi@ionicframework.com
shell: bash
# Lerna does not automatically bump versions
# of Ionic dependencies that have changed, so
# we do that here. The install fails with
# ETARGET until the versions published earlier
# resolve on npm, so retry. The
# `--prefer-online` flag matters because npm
# caches the failed lookup, and an `npm view`
# probe would read a different cached document.
- name: Resolve Package Locks
id: resolve
env:
SLEEP_SECONDS: 15
DEADLINE_SECONDS: 900
run: |
set -euo pipefail
# We bound this on the wall clock so the loop reports its own
# error before `timeout-minutes` kills the job. The `timeout`
# call caps an attempt that hangs rather than fails, which would
# never reach the check below.
deadline=$(( SECONDS + DEADLINE_SECONDS ))
attempt=0
until timeout --kill-after=30 300 lerna exec "npm install --package-lock-only --prefer-online"; do
attempt=$(( attempt + 1 ))
if [ "$SECONDS" -ge "$deadline" ]; then
echo "::error::npm install --package-lock-only failed $attempt times over ${SECONDS}s; see the last attempt above for the error"
exit 1
fi
echo "Attempt $attempt failed, retrying in ${SLEEP_SECONDS}s"
sleep "$SLEEP_SECONDS"
done
echo "resolved=true" >> "$GITHUB_OUTPUT"
shell: bash
# This is split from the retry so `resolved`
# does not depend on the commit and the push
# working.
- name: Commit Package Locks
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git add .
# Re-running this job after the locks were already committed
# would otherwise fail on an empty commit.
if git diff --cached --quiet; then
echo "No package lock changes to commit"
exit 0
fi
git commit -m "chore(): update package lock files"
git push
shell: bash
purge-cdn-cache:
# This runs after `update-package-lock` so the
# new versions have resolved on npm. Purging
# earlier re-caches `@ionic/core@latest` at the
# previous release. A failed `finalize-release`
# skips this too, so a half-finished release
# that did reach npm needs a manual purge.
needs: [update-package-lock]
if: ${{ !cancelled() && needs.update-package-lock.outputs.resolved == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Purge JSDelivr Cache
run: |
set -euo pipefail
if ! response=$(curl -sS --max-time 60 --retry 3 --retry-all-errors \
--retry-max-time 120 \
-w '\n%{http_code}' -X POST \
https://purge.jsdelivr.net/ \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"path": [
"/npm/@ionic/core@6/dist/ionic/ionic.esm.js",
"/npm/@ionic/core@7/dist/ionic/ionic.esm.js",
"/npm/@ionic/core@8/dist/ionic/ionic.esm.js",
"/npm/@ionic/core@9/dist/ionic/ionic.esm.js",
"/npm/@ionic/core@latest/dist/ionic/ionic.esm.js",
"/npm/@ionic/core@next/dist/ionic/ionic.esm.js",
"/npm/@ionic/core@6/css/ionic.bundle.css",
"/npm/@ionic/core@7/css/ionic.bundle.css",
"/npm/@ionic/core@8/css/ionic.bundle.css",
"/npm/@ionic/core@9/css/ionic.bundle.css",
"/npm/@ionic/core@latest/css/ionic.bundle.css",
"/npm/@ionic/core@next/css/ionic.bundle.css"
]}'); then
echo "::warning::jsDelivr purge request failed"
exit 0
fi
status=${response##*$'\n'}
echo "${response%$'\n'*}"
# `curl` exits 0 whatever jsDelivr answers, so check the status.
# A 4xx means we sent a bad payload, which is otherwise silent.
# Anything else is jsDelivr being down, which should not fail
# a release.
case "$status" in
2*) ;;
4*) echo "::error::jsDelivr rejected the purge with HTTP $status"; exit 1 ;;
*) echo "::warning::jsDelivr purge did not complete (HTTP $status)" ;;
esac
shell: bash