Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite of TPS integrations using basic bash scripts #3090

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/create-cli-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ on:
jobs:
check-for-moratorium:
if: fromJSON(inputs.isStableCandidate)
uses: ./.github/workflows/ctc.yml
run: ./scripts/release/tps_check_lock cli ${{ github.sha }}
environment: ChangeManagement
env:
TPS_API_TOKEN: ${{ secrets.TPS_API_TOKEN_PARAM }}

get-version-channel:
runs-on: ubuntu-latest
Expand Down
68 changes: 0 additions & 68 deletions .github/workflows/ctc.yml

This file was deleted.

18 changes: 8 additions & 10 deletions .github/workflows/promote-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,16 @@ jobs:
change-management:
needs: [ promote ]
if: fromJSON(inputs.isStableRelease)
runs-on: ubuntu-latest
environment: ChangeManagement
env:
TPS_API_APP_ID: ${{ secrets.TPS_API_APP_ID }}
TPS_API_RELEASE_ACTOR_EMAIL: ${{ secrets.TPS_API_RELEASE_ACTOR_EMAIL }}
TPS_API_STAGE: ${{ secrets.TPS_API_STAGE }}
TPS_API_TOKEN_PARAM: ${{ secrets.TPS_API_TOKEN_PARAM }}
TPS_API_URL_PARAM: ${{ secrets.TPS_API_URL_PARAM }}
# Failure to record the release should not fail the workflow
continue-on-error: true
steps:
# Checkout required to get github.sha
- uses: actions/checkout@v3
- run: yarn --immutable --network-timeout 1000000
- run: ./scripts/postrelease/change_management
- run: ./scripts/postrelease/tps_record_release cli ${{ github.sha }}
environment: ChangeManagement
env:
ACTOR_EMAIL: ${{ secrets.TPS_API_RELEASE_ACTOR_EMAIL }}
TPS_API_TOKEN: ${{ secrets.TPS_API_TOKEN_PARAM }}

create-fig-autocomplete-pr:
if: fromJSON(inputs.isStableRelease)
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ node_modules

# TEMP
/packages/**/converted/*

tpsGetLock_response.txt
tpsRecordRelease_response.txt
83 changes: 0 additions & 83 deletions scripts/postrelease/change_management

This file was deleted.

84 changes: 84 additions & 0 deletions scripts/postrelease/tps_record_release
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
set -eu
set -o pipefail

# Usage: ./scripts/postrelease/tps_record_release
# Required env vars: TPS_API_TOKEN, COMPONENT_SLUG, RELEASE_SHA, ACTOR_EMAIL

# Alternate Usage: ./scripts/postrelease/tps_record_release <component-slug> <release-id>
# Required env vars: TPS_API_TOKEN, ACTOR_EMAIL

# Alternate Usage: ./scripts/postrelease/tps_record_release <component-slug> <release-id> <email>
# Required env vars: TPS_API_TOKEN

if [ -z "${TPS_HOSTNAME:-}" ]; then
TPS_HOSTNAME="tps.heroku.tools"
fi

if [ -z "${TPS_API_TOKEN:-}" ]; then
echo "Requires environment variable: TPS_API_TOKEN" >&2
exit 1
fi

# Argument overrides the environment variable
component_slug="${1:-$COMPONENT_SLUG}"
if [ -z "$component_slug" ]; then
echo "Requires first argument or env var COMPONENT_SLUG: Heroku component slug" >&2
exit 1
fi

release_sha="${2:-$RELEASE_SHA}"
if [ -z "$release_sha" ]; then
echo "Requires second argument or env var RELEASE_SHA: SHA of the commit being released" >&2
exit 1
fi

actor_email="${3:-$ACTOR_EMAIL}"
if [ -z "$actor_email" ]; then
echo "Requires third argument or env var ACTOR_EMAIL: email of actor performing the release" >&2
exit 1
fi

# No app_id for cli releases
# app_id="${4:-$APP_ID}"
# if [ -z "$app_id" ]; then
# echo "Requires fourth argument: UUID of app being released" >&2
# exit 1
# fi

stage="production"
description="Deploy ${release_sha} of ${component_slug} in ${stage}"

response_status=0

tpsRecordRelease() {
response_status="$(curl --silent \
-o tpsRecordRelease_response.txt -w "%{response_code}" \
-X POST \
-H "Accept: */*" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TPS_API_TOKEN}" \
-d "{\"component_slug\": \"${component_slug}\", \"release\": {\"sha\": \"${release_sha}\", \"actor_email\": \"${actor_email}\", \"stage\": \"${stage}\", \"description\": \"${description}\"}}" \
https://${TPS_HOSTNAME}/api/component/${component_slug}/releases)"

echo Response status $response_status: $(cat tpsRecordRelease_response.txt) >&2
}

echo "Recording release with ${TPS_HOSTNAME}…" >&2
retry_count=0
set +e
tpsRecordRelease
until [ "$response_status" == "204" ]
do
((retry_count++))
if [ $retry_count -gt 120 ]
then
echo "❌ Could not record release for \"$component_slug\" after retrying for 30-minutes." >&2
exit 2
fi
echo "⏳ Retry in 15-seconds…" >&2
sleep 15
tpsRecordRelease
done
set -e
echo "✅ Release recorded" >&2
65 changes: 65 additions & 0 deletions scripts/release/tps_check_lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
set -eu
set -o pipefail

# Usage: ./scripts/release/tps_check_lock
# Required env vars: TPS_API_TOKEN, COMPONENT_SLUG, RELEASE_SHA
#
# Alternate Usage: ./scripts/release/tps_check_lock <component-slug> <release-id>
# Required env vars: TPS_API_TOKEN

if [ -z "${TPS_HOSTNAME:-}" ]; then
TPS_HOSTNAME="tps.heroku.tools"
fi

if [ -z "${TPS_API_TOKEN:-}" ]; then
echo "Requires environment variable: TPS_API_TOKEN" >&2
exit 1
fi

# Argument overrides the environment variable
component_slug="${1:-$COMPONENT_SLUG}"
if [ -z "$component_slug" ]; then
echo "Requires first argument or env var COMPONENT_SLUG: Heroku component slug" >&2
exit 1
fi

release_sha="${2:-$RELEASE_SHA}"
if [ -z "$release_sha" ]; then
echo "Requires second argument or env var RELEASE_SHA: SHA of the commit being released" >&2
exit 1
fi

response_status=0

tpsGetLock() {
response_status="$(curl --silent \
-o tpsGetLock_response.txt -w "%{response_code}" \
-X PUT \
-H "Accept: */*" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TPS_API_TOKEN}" \
-d "{\"lock\": {\"sha\": \"${release_sha}\", \"component_slug\": \"${component_slug}\"}}" \
https://${TPS_HOSTNAME}/api/ctc)"

echo Response status $response_status: $(cat tpsGetLock_response.txt) >&2
}

echo "Requesting deployment lock from ${TPS_HOSTNAME}…" >&2
retry_count=0
set +e
tpsGetLock
until [ "$response_status" == "200" -o "$response_status" == "201" ]
do
((retry_count++))
if [ $retry_count -gt 40 ]
then
echo "❌ Could not get deployment lock for \"$component_slug\" after retrying for 10-minutes." >&2
exit 2
fi
echo "⏳ Retry in 15-seconds…" >&2
sleep 15
tpsGetLock
done
set -e
echo "✅ Lock acquired" >&2
Loading