Skip to content

Commit ff596fe

Browse files
committed
Speculative rewrite of TPS lock check
1 parent 9e9ba88 commit ff596fe

File tree

3 files changed

+55
-69
lines changed

3 files changed

+55
-69
lines changed

.github/workflows/create-cli-release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ on:
1919
jobs:
2020
check-for-moratorium:
2121
if: fromJSON(inputs.isStableCandidate)
22-
uses: ./.github/workflows/ctc.yml
22+
run: ./scripts/release/tps_lock_check cli ${{ github.sha }}
23+
env:
24+
TPS_API_TOKEN: ${{ secrets.TPS_API_TOKEN_PARAM }}
2325

2426
get-version-channel:
2527
runs-on: ubuntu-latest

.github/workflows/ctc.yml

Lines changed: 0 additions & 68 deletions
This file was deleted.

scripts/release/tps_check_lock

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
set -eu
3+
set -o pipefail
4+
5+
if [ -z "$TPS_API_TOKEN" ]; then
6+
echo "Requires environment variable: TPS_API_TOKEN" >&2
7+
exit 1
8+
fi
9+
10+
# Argument overrides the environment variable
11+
component_slug="${1:-$COMPONENT_SLUG}"
12+
if [ -z "$component_slug" ]; then
13+
echo "Requires first argument: Heroku component slug" >&2
14+
exit 1
15+
fi
16+
17+
release_sha="${2:-$RELEASE_SHA}"
18+
if [ -z "$release_sha" ]; then
19+
echo "Requires second argument: SHA of the commit being released" >&2
20+
exit 1
21+
fi
22+
23+
response_status=0
24+
25+
tpsGetLock() {
26+
response_status="$(curl --w '%{http_code}' \
27+
-X PUT \
28+
-H "Accept: application/json" \
29+
-H "Content-Type: application/json" \
30+
-H "Authorization: Token ${TPS_API_TOKEN}" \
31+
-d "{\"lock\": {\"sha\": \"${release_sha}\", \"component_slug\": \"${component_slug}\"}}" \
32+
https://tps.heroku.tools/api/ctc)"
33+
}
34+
35+
echo "Requesting deployment lock from tps.heroku.tools…" >&2
36+
retry_count=0
37+
set +e
38+
tpsGetLock
39+
until [ "$response_status" == "200" -a "$response_status" == "201" ]
40+
do
41+
tpsGetLock
42+
((retry_count++))
43+
if [ $retry_count -gt 40 ]
44+
then
45+
echo "❌ Could not aquire deployment lock for \"$component_name\" after retrying for 10-minutes." >&2
46+
exit 2
47+
fi
48+
echo "⏳ Response status \"$response_status\". Retry in 15-seconds…" >&2
49+
sleep 15
50+
done
51+
set -e
52+
echo "✅ Lock acquired" >&2

0 commit comments

Comments
 (0)