Skip to content

Commit cf9b89d

Browse files
authored
Rewrite of TPS integrations using basic bash scripts (#3090)
* Speculative rewrite of TPS lock check * Fix executable * Fix curl error * More curl request fixes * Logic fix & formatting * Improve error reporting in TPS lock check * Include environment to get TPS secrets * Rewrite TPS release recorder to match other TPS script * Continue on error when recording the release * Document usage of TPS scripts * fix spelling * Fix record release to drop app_id (CLI does not have this) and honor the 204 status for success * Clarify missing argument messages * Corrections based on PR feedback * Stable CLI releases are always "production" * No longer need the TPS_API_STAGE secret * Fix to set the release stage in description too * Always output TPS response status * Move retry attempt to end of loop
1 parent ce7c59b commit cf9b89d

File tree

7 files changed

+163
-163
lines changed

7 files changed

+163
-163
lines changed

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

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

2427
get-version-channel:
2528
runs-on: ubuntu-latest

.github/workflows/ctc.yml

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

.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 }}
61+
# Failure to record the release should not fail the workflow
62+
continue-on-error: true
6963
steps:
64+
# Checkout required to get github.sha
7065
- uses: actions/checkout@v3
71-
- run: yarn --immutable --network-timeout 1000000
72-
- run: ./scripts/postrelease/change_management
66+
- run: ./scripts/postrelease/tps_record_release cli ${{ github.sha }}
67+
environment: ChangeManagement
68+
env:
69+
ACTOR_EMAIL: ${{ secrets.TPS_API_RELEASE_ACTOR_EMAIL }}
70+
TPS_API_TOKEN: ${{ secrets.TPS_API_TOKEN_PARAM }}
7371

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

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ node_modules
2626

2727
# TEMP
2828
/packages/**/converted/*
29-
29+
tpsGetLock_response.txt
30+
tpsRecordRelease_response.txt

scripts/postrelease/change_management

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

scripts/release/tps_check_lock

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

0 commit comments

Comments
 (0)