Skip to content

Commit 8661f4c

Browse files
committed
Rewrite TPS release recorder to match other TPS script
1 parent 94d456d commit 8661f4c

File tree

4 files changed

+87
-93
lines changed

4 files changed

+87
-93
lines changed

.github/workflows/promote-release.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,16 @@ jobs:
5858
change-management:
5959
needs: [ promote ]
6060
if: fromJSON(inputs.isStableRelease)
61-
runs-on: ubuntu-latest
62-
environment: ChangeManagement
63-
env:
64-
TPS_API_APP_ID: ${{ secrets.TPS_API_APP_ID }}
65-
TPS_API_RELEASE_ACTOR_EMAIL: ${{ secrets.TPS_API_RELEASE_ACTOR_EMAIL }}
66-
TPS_API_STAGE: ${{ secrets.TPS_API_STAGE }}
67-
TPS_API_TOKEN_PARAM: ${{ secrets.TPS_API_TOKEN_PARAM }}
68-
TPS_API_URL_PARAM: ${{ secrets.TPS_API_URL_PARAM }}
6961
steps:
62+
# Checkout required to get github.sha
7063
- uses: actions/checkout@v3
71-
- run: yarn --immutable --network-timeout 1000000
72-
- run: ./scripts/postrelease/change_management
64+
- run: ./scripts/postrelease/tps_record_release cli ${{ github.sha }}
65+
environment: ChangeManagement
66+
env:
67+
ACTOR_EMAIL: ${{ secrets.TPS_API_RELEASE_ACTOR_EMAIL }}
68+
APP_ID: ${{ secrets.TPS_API_APP_ID }}
69+
STAGE: ${{ secrets.TPS_API_STAGE }}
70+
TPS_API_TOKEN: ${{ secrets.TPS_API_TOKEN_PARAM }}
7371

7472
create-fig-autocomplete-pr:
7573
if: fromJSON(inputs.isStableRelease)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ node_modules
2727
# TEMP
2828
/packages/**/converted/*
2929
tpsGetLock_response.txt
30+
tpsRecordRelease_response.txt

scripts/postrelease/change_management

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
set -eu
3+
set -o pipefail
4+
5+
if [ -z "${TPS_HOSTNAME:-}" ]; then
6+
TPS_HOSTNAME="tps.heroku.tools"
7+
fi
8+
9+
if [ -z "${TPS_API_TOKEN:-}" ]; then
10+
echo "Requires environment variable: TPS_API_TOKEN" >&2
11+
exit 1
12+
fi
13+
14+
# Argument overrides the environment variable
15+
component_slug="${1:-$COMPONENT_SLUG}"
16+
if [ -z "$component_slug" ]; then
17+
echo "Requires first argument: Heroku component slug" >&2
18+
exit 1
19+
fi
20+
21+
release_sha="${2:-$RELEASE_SHA}"
22+
if [ -z "$release_sha" ]; then
23+
echo "Requires second argument: SHA of the commit being released" >&2
24+
exit 1
25+
fi
26+
27+
actor_email="${3:-$ACTOR_EMAIL}"
28+
if [ -z "$actor_email" ]; then
29+
echo "Requires third argument: email of actor performing the release" >&2
30+
exit 1
31+
fi
32+
33+
app_id="${3:-$APP_ID}"
34+
if [ -z "$app_id" ]; then
35+
echo "Requires fourth argument: UUID of app being released" >&2
36+
exit 1
37+
fi
38+
39+
stage="${3:-$STAGE}"
40+
if [ -z "$stage" ]; then
41+
echo "Requires fifth argument: stage of the release" >&2
42+
exit 1
43+
fi
44+
45+
description="Deploy ${release_sha} of ${component_slug} in ${stage}"
46+
47+
response_status=0
48+
49+
tpsRecordRelease() {
50+
response_status="$(curl --silent \
51+
-o tpsRecordRelease_response.txt -w "%{response_code}" \
52+
-X POST \
53+
-H "Accept: */*" \
54+
-H "Content-Type: application/json" \
55+
-H "Authorization: Bearer ${TPS_API_TOKEN}" \
56+
-d "{\"release\": {\"sha\": \"${release_sha}\", \"component_slug\": \"${component_slug}\", \"actor_email\": \"${actor_email}\", \"app_id\": \"${app_id}\", \"stage\": \"${stage}\", \"description\": \"${description}\"}}" \
57+
https://${TPS_HOSTNAME}/api/component/${component_slug}/releases)"
58+
}
59+
60+
echo "Recording release with ${TPS_HOSTNAME}" >&2
61+
retry_count=0
62+
set +e
63+
tpsRecordRelease
64+
until [ "$response_status" == "200" -o "$response_status" == "201" ]
65+
do
66+
tpsRecordRelease
67+
((retry_count++))
68+
if [ $retry_count -gt 120 ]
69+
then
70+
echo "❌ Could not record release for \"$component_name\" after retrying for 30-minutes." >&2
71+
exit 2
72+
fi
73+
echo Response status $response_status: $(cat tpsRecordRelease_response.txt) >&2
74+
echo "⏳ Retry in 15-seconds…" >&2
75+
sleep 15
76+
done
77+
set -e
78+
echo "✅ Release recorded" >&2

0 commit comments

Comments
 (0)