Initial sandbox proxy deploy #316
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Create Environment | |
| on: | |
| pull_request: | |
| types: [labeled, opened, synchronize, reopened, unlabeled, edited] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| create-dynamic-environment: | |
| name: Create Dynamic Environment | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Trigger nhs-notify-internal dynamic environment workflow | |
| shell: bash | |
| run: | | |
| this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2) | |
| DISPATCH_EVENT=$(jq -ncM \ | |
| --arg infraRepoName "${this_repo_name}" \ | |
| --arg releaseVersion "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \ | |
| --arg targetProject "nhs" \ | |
| --arg targetEnvironment "pr${{ github.event.number }}" \ | |
| --arg targetAccountGroup "nhs-notify-supplier-api-dev" \ | |
| --arg targetComponent "api" \ | |
| --arg terraformAction "apply" \ | |
| --arg overrides "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \ | |
| --arg overrideProjectName "nhs" \ | |
| --arg overrideRoleName "nhs-main-acct-supplier-api-github-deploy" \ | |
| '{ "ref": "main", | |
| "inputs": { | |
| "infraRepoName", $infraRepoName, | |
| "releaseVersion", $releaseVersion, | |
| "targetProject", $targetProject, | |
| "targetEnvironment", $targetEnvironment, | |
| "targetAccountGroup", $targetAccountGroup, | |
| "targetComponent", $targetComponent, | |
| "terraformAction", $terraformAction, | |
| "overrides", $overrides, | |
| "overrideProjectName", $overrideProjectName, | |
| "overrideRoleName", $overrideRoleName, | |
| } | |
| }') | |
| curl --fail -L -s \ | |
| -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-dynamic-env.yaml/dispatches \ | |
| -d "${DISPATCH_EVENT}" | |
| echo "Workflow triggered. Waiting for the workflow to complete.." | |
| # Poll GitHub API to check the workflow status | |
| workflow_run_url="" | |
| for i in {1..12}; do | |
| workflow_run_url=$(curl -s \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| "https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch&status=in_progress" \ | |
| | jq -r '.workflow_runs[] | |
| | select(.name | |
| | contains("'pr${{ github.event.number }}'") and | |
| contains("'nhs-notify-supplier-api-dev'") and | |
| contains("'api'") and | |
| contains("'apply'")) | |
| | .url') | |
| if [[ -n "$workflow_run_url" && "$workflow_run_url" != null ]]; then | |
| ui_url=${workflow_run_url/api./} | |
| ui_url=${ui_url/\/repos/} | |
| echo "Found workflow run url: $ui_url" | |
| echo "workflow_run_url=$workflow_run_url" >> $GITHUB_ENV | |
| break | |
| fi | |
| echo "Waiting for workflow to start..." | |
| sleep 10 | |
| done | |
| if [[ -z "$workflow_run_url" || "$workflow_run_url" == null ]]; then | |
| echo "Failed to get the workflow run url. Exiting." | |
| exit 1 | |
| fi | |
| # Wait for workflow completion | |
| while true; do | |
| sleep 10 | |
| response=$(curl -s -L \ | |
| -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| $workflow_run_url) | |
| status=$(echo "$response" | jq -r '.status') | |
| conclusion=$(echo "$response" | jq -r '.conclusion') | |
| if [ "$status" == "completed" ]; then | |
| if [ "$conclusion" == "success" ]; then | |
| echo "Workflow completed successfully." | |
| exit 0 | |
| else | |
| echo "Workflow failed with conclusion: $conclusion" | |
| exit 1 | |
| fi | |
| fi | |
| echo "Workflow still running..." | |
| sleep 20 | |
| done |