@@ -81,72 +81,72 @@ jobs:
8181 }')
8282
8383 # Trigger The workflow
84- # curl -L \
85- # --fail \
86- # --silent \
87- # -X POST \
88- # -H "Accept: application/vnd.github+json" \
89- # -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
90- # -H "X-GitHub-Api-Version: 2022-11-28" \
91- # "https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/${{ inputs.targetWorkflow }}/dispatches" \
92- # -d "${DISPATCH_EVENT}"
93-
94- # echo "Workflow triggered. Waiting for the workflow to complete.."
95-
96- # # Poll GitHub API to check the workflow status
97- # workflow_run_url=""
98- # for i in {1..12}; do
99- # workflow_run_url=$(curl -s \
100- # -H "Accept: application/vnd.github+json" \
101- # -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
102- # -H "X-GitHub-Api-Version: 2022-11-28" \
103- # "https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch&status=in_progress" \
104- # | jq -r '.workflow_runs[]
105- # | select(.name
106- # | contains("'${{ inputs.targetEnvironment }}'") and
107- # contains("'${{ inputs.targetAccountGroup }}'") and
108- # contains("'${{ inputs.targetComponent }}'") and
109- # contains("'${{ inputs.terraformAction }}'"))
110- # | .url')
111-
112- # if [[ -n "$workflow_run_url" && "$workflow_run_url" != null ]]; then
113- # ui_url=${workflow_run_url/api./}
114- # ui_url=${ui_url/\/repos/}
115- # echo "Found workflow run url: $ui_url"
116- # echo "workflow_run_url=$workflow_run_url" >> $GITHUB_ENV
117- # break
118- # fi
119-
120- # echo "Waiting for workflow to start..."
121- # sleep 10
122- # done
123-
124- # if [[ -z "$workflow_run_url" || "$workflow_run_url" == null ]]; then
125- # echo "Failed to get the workflow run url. Exiting."
126- # exit 1
127- # fi
128-
129- # # Wait for workflow completion
130- # while true; do
131- # sleep 10
132- # response=$(curl -s -L \
133- # -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
134- # -H "Accept: application/vnd.github+json" \
135- # $workflow_run_url)
136-
137- # status=$(echo "$response" | jq -r '.status')
138- # conclusion=$(echo "$response" | jq -r '.conclusion')
139-
140- # if [ "$status" == "completed" ]; then
141- # if [ "$conclusion" == "success" ]; then
142- # echo "Workflow completed successfully."
143- # exit 0
144- # else
145- # echo "Workflow failed with conclusion: $conclusion"
146- # exit 1
147- # fi
148- # fi
149-
150- # echo "Workflow still running..."
151- # sleep 20
152- # done
84+ curl -L \
85+ --fail \
86+ --silent \
87+ -X POST \
88+ -H "Accept: application/vnd.github+json" \
89+ -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
90+ -H "X-GitHub-Api-Version: 2022-11-28" \
91+ "https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/${{ inputs.targetWorkflow }}/dispatches" \
92+ -d "${DISPATCH_EVENT}"
93+
94+ echo "Workflow triggered. Waiting for the workflow to complete.."
95+
96+ # Poll GitHub API to check the workflow status
97+ workflow_run_url=""
98+ for i in {1..12}; do
99+ workflow_run_url=$(curl -s \
100+ -H "Accept: application/vnd.github+json" \
101+ -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
102+ -H "X-GitHub-Api-Version: 2022-11-28" \
103+ "https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch&status=in_progress" \
104+ | jq -r '.workflow_runs[]
105+ | select(.name
106+ | contains("'${{ inputs.targetEnvironment }}'") and
107+ contains("'${{ inputs.targetAccountGroup }}'") and
108+ contains("'${{ inputs.targetComponent }}'") and
109+ contains("'${{ inputs.terraformAction }}'"))
110+ | .url')
111+
112+ if [[ -n "$workflow_run_url" && "$workflow_run_url" != null ]]; then
113+ ui_url=${workflow_run_url/api./}
114+ ui_url=${ui_url/\/repos/}
115+ echo "Found workflow run url: $ui_url"
116+ echo "workflow_run_url=$workflow_run_url" >> $GITHUB_ENV
117+ break
118+ fi
119+
120+ echo "Waiting for workflow to start..."
121+ sleep 10
122+ done
123+
124+ if [[ -z "$workflow_run_url" || "$workflow_run_url" == null ]]; then
125+ echo "Failed to get the workflow run url. Exiting."
126+ exit 1
127+ fi
128+
129+ # Wait for workflow completion
130+ while true; do
131+ sleep 10
132+ response=$(curl -s -L \
133+ -H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
134+ -H "Accept: application/vnd.github+json" \
135+ $workflow_run_url)
136+
137+ status=$(echo "$response" | jq -r '.status')
138+ conclusion=$(echo "$response" | jq -r '.conclusion')
139+
140+ if [ "$status" == "completed" ]; then
141+ if [ "$conclusion" == "success" ]; then
142+ echo "Workflow completed successfully."
143+ exit 0
144+ else
145+ echo "Workflow failed with conclusion: $conclusion"
146+ exit 1
147+ fi
148+ fi
149+
150+ echo "Workflow still running..."
151+ sleep 20
152+ done
0 commit comments