|
17 | 17 | - name: Trigger nhs-notify-internal dynamic environment workflow |
18 | 18 | shell: bash |
19 | 19 | run: | |
20 | | - set -x |
21 | 20 | this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2) |
22 | 21 |
|
23 | 22 | DISPATCH_EVENT=$(jq -ncM \ |
@@ -46,10 +45,70 @@ jobs: |
46 | 45 | } |
47 | 46 | }') |
48 | 47 |
|
49 | | - curl --fail -L \ |
| 48 | + curl --fail -L -s \ |
50 | 49 | -X POST \ |
51 | 50 | -H "Accept: application/vnd.github+json" \ |
52 | 51 | -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \ |
53 | 52 | -H "X-GitHub-Api-Version: 2022-11-28" \ |
54 | 53 | https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-dynamic-env.yaml/dispatches \ |
55 | 54 | -d "${DISPATCH_EVENT}" |
| 55 | +
|
| 56 | + echo "Workflow triggered. Waiting for the workflow to complete.." |
| 57 | +
|
| 58 | + # Poll GitHub API to check the workflow status |
| 59 | + workflow_run_url="" |
| 60 | + for i in {1..12}; do |
| 61 | + workflow_run_url=$(curl -s \ |
| 62 | + -H "Accept: application/vnd.github+json" \ |
| 63 | + -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \ |
| 64 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 65 | + "https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch&status=in_progress" \ |
| 66 | + | jq -r '.workflow_runs[] |
| 67 | + | select(.name |
| 68 | + | contains("'pr${{ github.event.number }}'") and |
| 69 | + contains("'nhs-notify-supplier-api-dev'") and |
| 70 | + contains("'api'") and |
| 71 | + contains("'apply'")) |
| 72 | + | .url') |
| 73 | +
|
| 74 | + if [[ -n "$workflow_run_url" && "$workflow_run_url" != null ]]; then |
| 75 | + ui_url=${workflow_run_url/api./} |
| 76 | + ui_url=${ui_url/\/repos/} |
| 77 | + echo "Found workflow run url: $ui_url" |
| 78 | + echo "workflow_run_url=$workflow_run_url" >> $GITHUB_ENV |
| 79 | + break |
| 80 | + fi |
| 81 | +
|
| 82 | + echo "Waiting for workflow to start..." |
| 83 | + sleep 10 |
| 84 | + done |
| 85 | +
|
| 86 | + if [[ -z "$workflow_run_url" || "$workflow_run_url" == null ]]; then |
| 87 | + echo "Failed to get the workflow run url. Exiting." |
| 88 | + exit 1 |
| 89 | + fi |
| 90 | +
|
| 91 | + # Wait for workflow completion |
| 92 | + while true; do |
| 93 | + sleep 10 |
| 94 | + response=$(curl -s -L \ |
| 95 | + -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \ |
| 96 | + -H "Accept: application/vnd.github+json" \ |
| 97 | + $workflow_run_url) |
| 98 | +
|
| 99 | + status=$(echo "$response" | jq -r '.status') |
| 100 | + conclusion=$(echo "$response" | jq -r '.conclusion') |
| 101 | +
|
| 102 | + if [ "$status" == "completed" ]; then |
| 103 | + if [ "$conclusion" == "success" ]; then |
| 104 | + echo "Workflow completed successfully." |
| 105 | + exit 0 |
| 106 | + else |
| 107 | + echo "Workflow failed with conclusion: $conclusion" |
| 108 | + exit 1 |
| 109 | + fi |
| 110 | + fi |
| 111 | +
|
| 112 | + echo "Workflow still running..." |
| 113 | + sleep 20 |
| 114 | + done |
0 commit comments