Skip to content

Commit

Permalink
Merge pull request #62 from govuk-one-login/bau-update-deployment
Browse files Browse the repository at this point in the history
BAU: Minor fixes to jest config and deployment script
  • Loading branch information
surajkumar authored Dec 18, 2023
2 parents 8c725da + 979d800 commit 8c2613e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
34 changes: 34 additions & 0 deletions .github/refresh-hmrc-token.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
set -eu

expiry_parameter=$(aws ssm describe-parameters \
--parameter-filters Key=Name,Option=Contains,Values=BearerTokenExpiry \
--query "Parameters[0].Name" --output text)

expiry_ms=$(aws ssm get-parameter --name "$expiry_parameter" --query "Parameter.Value" --output text)
refresh_ms=$(("$expiry_ms" - 20 * 60 * 1000))
current_ms=$(($(date +%s) * 1000))

if [[ $current_ms -lt $refresh_ms ]]; then
remaining_ms=$(("$expiry_ms" - "$current_ms"))
echo "Token expires in $(("$remaining_ms" / 1000 / 60)) minutes"
exit
fi

echo "Refreshing token..."

otg_arn=$(aws stepfunctions list-state-machines \
--query "stateMachines[?contains(name, 'OAuthTokenGenerator')] | [0].stateMachineArn" \
--output text)

execution_arn=$(aws stepfunctions start-execution --state-machine-arn "$otg_arn" | jq --raw-output .executionArn)

echo "Waiting for state machine execution..."
while [[ ${status:-RUNNING} == RUNNING ]]; do
status=$(aws stepfunctions describe-execution --execution-arn "$execution_arn" --query status --output text)
sleep 1
done

[[ $status == SUCCEEDED ]] && echo "Token has been refreshed" && exit

echo "Token refresh has failed"
exit 1
6 changes: 5 additions & 1 deletion .github/workflows/run-aws-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ concurrency:

defaults:
run:
working-directory: integration-tests
shell: bash

jobs:
Expand All @@ -43,7 +42,12 @@ jobs:
role-to-assume: ${{ vars.DEPLOYMENT_ROLE_ARN }}
aws-region: ${{ inputs.aws-region }}

- name: Refresh HMRC OAuth token
run: .github/refresh-hmrc-token.sh
shell: bash

- name: Run tests
working-directory: integration-tests
env:
AWS_REGION: ${{ inputs.aws-region }}
STACK_NAME: ${{ inputs.stack-name }}
Expand Down
2 changes: 1 addition & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stack_name="${1:-}"
common_stack_name="${2:-}"

if ! [[ "$stack_name" ]]; then
[[ $(aws whoami --query Arn --output text) =~ \/([^\/\.]+)\. ]] && user="${BASH_REMATCH[1]}" || exit
[[ $(aws sts get-caller-identity --query Arn --output text) =~ \/([^\/\.]+)\. ]] && user="${BASH_REMATCH[1]}" || exit
stack_name="$user-kbv-hmrc-api"
echo "» Using stack name '$stack_name'"
fi
Expand Down
1 change: 1 addition & 0 deletions integration-tests/tests/aws/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import baseConfig from "../../jest.config";

export default {
...baseConfig,
projects: [],
displayName: "integration-tests/aws",
} satisfies Config;
1 change: 1 addition & 0 deletions integration-tests/tests/mocked/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import baseConfig from "../../jest.config";

export default {
...baseConfig,
projects: [],
testTimeout: 30_000,
displayName: "integration-tests/mocked",
} satisfies Config;

0 comments on commit 8c2613e

Please sign in to comment.