8585 # possible for them to push at the same time.
8686 needs : [finalize-release]
8787 runs-on : ubuntu-latest
88+ # This is a backstop for the retry loop in
89+ # Resolve Package Locks, which fails with its
90+ # own message first.
91+ timeout-minutes : 30
8892 permissions :
8993 contents : write
9094 id-token : write
95+ outputs :
96+ # This says the new versions resolved on npm,
97+ # which is not the same as the job passing.
98+ resolved : ${{ steps.resolve.outputs.resolved }}
9199 steps :
92100 - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
93101 # Pull the latest version of the reference
@@ -108,25 +116,74 @@ jobs:
108116 git config user.email hi@ionicframework.com
109117 shell : bash
110118 # Lerna does not automatically bump versions
111- # of Ionic dependencies that have changed,
112- # so we do that here.
113- - name : Bump Package Lock
119+ # of Ionic dependencies that have changed, so
120+ # we do that here. The install fails with
121+ # ETARGET until the versions published earlier
122+ # resolve on npm, so retry. The
123+ # `--prefer-online` flag matters because npm
124+ # caches the failed lookup, and an `npm view`
125+ # probe would read a different cached document.
126+ - name : Resolve Package Locks
127+ id : resolve
128+ env :
129+ SLEEP_SECONDS : 15
130+ DEADLINE_SECONDS : 900
131+ run : |
132+ set -euo pipefail
133+ # We bound this on the wall clock so the loop reports its own
134+ # error before `timeout-minutes` kills the job. The `timeout`
135+ # call caps an attempt that hangs rather than fails, which would
136+ # never reach the check below.
137+ deadline=$(( SECONDS + DEADLINE_SECONDS ))
138+ attempt=0
139+ until timeout --kill-after=30 300 lerna exec "npm install --package-lock-only --prefer-online"; do
140+ attempt=$(( attempt + 1 ))
141+ if [ "$SECONDS" -ge "$deadline" ]; then
142+ echo "::error::npm install --package-lock-only failed $attempt times over ${SECONDS}s; see the last attempt above for the error"
143+ exit 1
144+ fi
145+ echo "Attempt $attempt failed, retrying in ${SLEEP_SECONDS}s"
146+ sleep "$SLEEP_SECONDS"
147+ done
148+ echo "resolved=true" >> "$GITHUB_OUTPUT"
149+ shell : bash
150+ # This is split from the retry so `resolved`
151+ # does not depend on the commit and the push
152+ # working.
153+ - name : Commit Package Locks
154+ env :
155+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
114156 run : |
115- lerna exec "npm install --package-lock-only"
157+ set -euo pipefail
116158 git add .
159+ # Re-running this job after the locks were already committed
160+ # would otherwise fail on an empty commit.
161+ if git diff --cached --quiet; then
162+ echo "No package lock changes to commit"
163+ exit 0
164+ fi
117165 git commit -m "chore(): update package lock files"
118166 git push
119- env :
120- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
121167 shell : bash
122168
123169 purge-cdn-cache :
124- needs : [release-ionic]
170+ # This runs after `update-package-lock` so the
171+ # new versions have resolved on npm. Purging
172+ # earlier re-caches `@ionic/core@latest` at the
173+ # previous release. A failed `finalize-release`
174+ # skips this too, so a half-finished release
175+ # that did reach npm needs a manual purge.
176+ needs : [update-package-lock]
177+ if : ${{ !cancelled() && needs.update-package-lock.outputs.resolved == 'true' }}
125178 runs-on : ubuntu-latest
179+ timeout-minutes : 5
126180 steps :
127181 - name : Purge JSDelivr Cache
128182 run : |
129- curl -X POST \
183+ set -euo pipefail
184+ if ! response=$(curl -sS --max-time 60 --retry 3 --retry-all-errors \
185+ --retry-max-time 120 \
186+ -w '\n%{http_code}' -X POST \
130187 https://purge.jsdelivr.net/ \
131188 -H 'cache-control: no-cache' \
132189 -H 'content-type: application/json' \
@@ -142,7 +199,21 @@ jobs:
142199 "/npm/@ionic/core@7/css/ionic.bundle.css",
143200 "/npm/@ionic/core@8/css/ionic.bundle.css",
144201 "/npm/@ionic/core@9/css/ionic.bundle.css",
145- "/npm/@ionic/core@latest/css/ionic.bundle.css"
202+ "/npm/@ionic/core@latest/css/ionic.bundle.css",
146203 "/npm/@ionic/core@next/css/ionic.bundle.css"
147- ]}'
204+ ]}'); then
205+ echo "::warning::jsDelivr purge request failed"
206+ exit 0
207+ fi
208+ status=${response##*$'\n'}
209+ echo "${response%$'\n'*}"
210+ # `curl` exits 0 whatever jsDelivr answers, so check the status.
211+ # A 4xx means we sent a bad payload, which is otherwise silent.
212+ # Anything else is jsDelivr being down, which should not fail
213+ # a release.
214+ case "$status" in
215+ 2*) ;;
216+ 4*) echo "::error::jsDelivr rejected the purge with HTTP $status"; exit 1 ;;
217+ *) echo "::warning::jsDelivr purge did not complete (HTTP $status)" ;;
218+ esac
148219 shell : bash
0 commit comments