Skip to content

Commit b816b43

Browse files
oluwolenpbcoluwolenpbc
and
oluwolenpbc
authored
PLT-642 Adding verify scripts and deployment verification workflow (#1402)
## 🎫 Ticket https://jira.cms.gov/browse/PLT-642 ## ℹ️ Context This is a new addition to our github actions workflows to verify our deployments ## 🧪 Validation The test will be validated by github actions test runs. --------- Co-authored-by: oluwolenpbc <[email protected]>
1 parent 5eb242f commit b816b43

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed

.github/workflows/pull-request.yml

+6
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ jobs:
4545
with:
4646
environment: test
4747
secrets: inherit
48+
verify-deployment:
49+
needs: [e2e-test]
50+
uses: ./.github/workflows/verify-deploy.yml
51+
with:
52+
environment: test
53+
secrets: inherit

.github/workflows/push-main.yml

+6
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ jobs:
4444
with:
4545
environment: test
4646
secrets: inherit
47+
verify-deployment:
48+
needs: [e2e-test]
49+
uses: ./.github/workflows/verify-deploy.yml
50+
with:
51+
environment: test
52+
secrets: inherit

.github/workflows/verify-deploy.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Verify deployment
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: false
8+
type: string
9+
workflow_dispatch:
10+
inputs:
11+
environment:
12+
required: true
13+
type: choice
14+
options:
15+
- dev
16+
- test
17+
- sbx
18+
- prod
19+
20+
jobs:
21+
test:
22+
runs-on: self-hosted
23+
24+
steps:
25+
- name: Checkout Code
26+
uses: actions/checkout@v4
27+
28+
- name: Assume role in AB2D account for this environment
29+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
30+
env:
31+
ACCOUNT: ${{ inputs.environment == '' && 'test' || inputs.environment }}
32+
with:
33+
aws-region: ${{ vars.AWS_REGION }}
34+
role-to-assume: arn:aws:iam::${{ secrets[format('{0}_ACCOUNT_ID', env.ACCOUNT)] }}:role/delegatedadmin/developer/ab2d-${{ env.ACCOUNT }}-github-actions
35+
36+
- name: Set environment-specific variables
37+
run: |
38+
ENVIRONMENT="${{ inputs.environment || 'test' }}"
39+
if [ "$ENVIRONMENT" == "test" ]; then
40+
echo "SECRET_ID=ab2d/ab2d-east-impl/jenkins-verify-api" >> $GITHUB_ENV
41+
echo "BASE_URL=https://impl.ab2d.cms.gov" >> $GITHUB_ENV
42+
echo "EXPORT_URL=https://impl.ab2d.cms.gov/api/v2/fhir/Patient/?_type=ExplanationOfBenefit&_since=2020-02-13T00:00:00.000-05:00&_outputFormat=application%2Ffhir%2Bndjson" >> $GITHUB_ENV
43+
elif [ "$ENVIRONMENT" == "dev" ]; then
44+
echo "SECRET_ID=ab2d/ab2d-dev/jenkins-verify-basic-auth" >> $GITHUB_ENV
45+
echo "BASE_URL=https://dev.ab2d.cms.gov" >> $GITHUB_ENV
46+
echo "EXPORT_URL=https://dev.ab2d.cms.gov/api/v2/fhir/Patient/?_type=ExplanationOfBenefit&_since=2020-02-13T00:00:00.000-05:00&_outputFormat=application%2Ffhir%2Bndjson" >> $GITHUB_ENV
47+
elif [ "$ENVIRONMENT" == "sbx" ]; then
48+
echo "SECRET_ID=ab2d/ab2d-sbx-sandbox/jenkins-verify-basic-auth" >> $GITHUB_ENV
49+
echo "BASE_URL=https://sbx.ab2d.cms.gov" >> $GITHUB_ENV
50+
echo "EXPORT_URL=https://sbx.ab2d.cms.gov/api/v2/fhir/Patient/?_type=ExplanationOfBenefit&_since=2020-02-13T00:00:00.000-05:00&_outputFormat=application%2Ffhir%2Bndjson" >> $GITHUB_ENV
51+
elif [ "$ENVIRONMENT" == "prod" ]; then
52+
echo "SECRET_ID=ab2d/ab2d-east-prod/jenkins-verify-basic-auth" >> $GITHUB_ENV
53+
echo "BASE_URL=https://api.ab2d.cms.gov" >> $GITHUB_ENV
54+
echo "EXPORT_URL=https://api.ab2d.cms.gov/api/v2/fhir/Patient/?_type=ExplanationOfBenefit&_since=2020-02-13T00:00:00.000-05:00&_outputFormat=application%2Ffhir%2Bndjson" >> $GITHUB_ENV
55+
else
56+
echo "Invalid environment: $ENVIRONMENT"
57+
exit 1
58+
fi
59+
60+
- name: Set script file based on environment
61+
run: echo "script=./scripts/verify-deployment.sh" >> $GITHUB_ENV
62+
63+
- name: Run deployment verification script
64+
run: |
65+
chmod +x ./scripts/verify-deployment.sh
66+
./scripts/verify-deployment.sh "$SECRET_ID" "$BASE_URL" "$EXPORT_URL"
67+
env:
68+
SECRET_ID: ${{ env.SECRET_ID }}
69+
BASE_URL: ${{ env.BASE_URL }}
70+
EXPORT_URL: ${{ env.EXPORT_URL }}

scripts/verify-deployment.sh

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
set -e
3+
set -x # Enable verbose mode for debugging
4+
5+
# Input parameters
6+
SECRET_ID="${1}"
7+
BASE_URL="${2}"
8+
EXPORT_URL="${3}"
9+
10+
# Validate inputs
11+
if [ -z "$SECRET_ID" ] || [ -z "$BASE_URL" ] || [ -z "$EXPORT_URL" ]; then
12+
echo "Usage: $0 <SECRET_ID> <BASE_URL> <EXPORT_URL>"
13+
exit 1
14+
fi
15+
16+
# Wait for dependencies to initialize
17+
sleep 30
18+
19+
# Fetch the secret for basic authentication
20+
BASIC_AUTH=$(aws secretsmanager get-secret-value --secret-id "$SECRET_ID" --query SecretString --output text) || {
21+
echo "Failed to retrieve secret"; exit 3;
22+
}
23+
24+
# Check API status
25+
echo "Checking API status..."
26+
max_attempts=90
27+
STATE=""
28+
attempts=0
29+
30+
while [ "$STATE" != "401" ]; do
31+
if [[ $attempts -eq $max_attempts ]]; then
32+
echo "Max attempts reached, timing out."
33+
exit 1
34+
fi
35+
36+
STATE=$(curl -sLk -w "%{http_code}" "$BASE_URL" -o /dev/null) || {
37+
echo "Failed to reach API. Curl request failed."; exit 3;
38+
}
39+
echo "Current state: $STATE"
40+
41+
if [ "$STATE" != "401" ]; then
42+
echo "API not ready. Retrying in 10 seconds..."
43+
attempts=$((attempts + 1))
44+
sleep 10
45+
fi
46+
done
47+
48+
echo "AB2D API is online."
49+
50+
# Refresh token
51+
echo "Refreshing token..."
52+
TOKEN=$(curl -s --location --request POST 'https://test.idp.idm.cms.gov/oauth2/aus2r7y3gdaFMKBol297/v1/token?grant_type=client_credentials&scope=clientCreds' \
53+
--header 'Content-Type: application/x-www-form-urlencoded' \
54+
--header "Authorization: Basic $BASIC_AUTH" \
55+
--header 'Cookie: JSESSIONID=3E7BD665DE5673C73A82647BBD9E548A' \
56+
| jq -r '.access_token') || {
57+
echo "Token refresh failed."; exit 3;
58+
}
59+
60+
61+
echo "Starting PDP-100 job..."
62+
JOB=$(curl -k -s --head --location --request GET 'https://impl.ab2d.cms.gov/api/v2/fhir/Patient/$export?_type=ExplanationOfBenefit&_since=2020-02-13T00:00:00.000-05:00&_outputFormat=application%2Ffhir%2Bndjson' \
63+
--header "Prefer: respond-async" \
64+
--header "Authorization: Bearer $TOKEN" \
65+
| awk -v FS=": " "/^content-location/{print \$2}" | sed 's/content-location: //' | tr -d '\r')
66+
67+
echo "$JOB"
68+
69+
70+
# Check on job status
71+
echo "Checking job status..."
72+
STATUS=""
73+
while [ -z "$STATUS" ]; do
74+
sleep 5
75+
echo "$JOB"
76+
STATUS=$(curl -k -s --location --request GET "${JOB}" \
77+
--header "Authorization: Bearer $TOKEN")
78+
done
79+
80+
echo "Complete"

0 commit comments

Comments
 (0)