Skip to content

Commit ef263f1

Browse files
authored
CCM-11726: Add run ID to trigger and filter (#648)
1 parent 1660e6a commit ef263f1

File tree

1 file changed

+48
-28
lines changed

1 file changed

+48
-28
lines changed

.github/workflows/dispatch_internal_repo_workflow.yaml

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,32 @@ jobs:
5858
- name: Trigger nhs-notify-internal workflow
5959
shell: bash
6060
run: |
61+
callerRunId="${GITHUB_RUN_ID}-${{ inputs.jobName }}-${GITHUB_RUN_ATTEMPT}"
62+
6163
DISPATCH_EVENT=$(jq -ncM \
62-
--arg infraRepoName "${{ inputs.infraRepoName }}" \
63-
--arg releaseVersion ${{ inputs.releaseVersion }} \
64-
--arg targetEnvironment ${{ inputs.targetEnvironment }} \
65-
--arg targetAccountGroup ${{ inputs.targetAccountGroup }} \
66-
--arg targetComponent ${{ inputs.targetComponent }} \
67-
--arg terraformAction "${{ inputs.terraformAction }}" \
68-
'{
69-
"ref": "${{ inputs.internalRef }}",
70-
"inputs": (
71-
(if $infraRepoName != "" then { "infraRepoName": $infraRepoName } else {} end) +
72-
(if $terraformAction != "" then { "terraformAction": $terraformAction } else {} end) +
73-
{
74-
"releaseVersion": $releaseVersion,
75-
"targetEnvironment": $targetEnvironment,
76-
"targetAccountGroup": $targetAccountGroup,
77-
"targetComponent": $targetComponent
78-
}
79-
)
80-
}')
64+
--arg infraRepoName "${{ inputs.infraRepoName }}" \
65+
--arg releaseVersion "${{ inputs.releaseVersion }}" \
66+
--arg targetEnvironment "${{ inputs.targetEnvironment }}" \
67+
--arg targetAccountGroup "${{ inputs.targetAccountGroup }}" \
68+
--arg targetComponent "${{ inputs.targetComponent }}" \
69+
--arg terraformAction "${{ inputs.terraformAction }}" \
70+
--arg callerRunId "$callerRunId" \
71+
--arg targetWorkflow "${{ inputs.targetWorkflow }}" \
72+
'{
73+
"ref": "${{ inputs.internalRef }}",
74+
"inputs": (
75+
(if $infraRepoName != "" then { "infraRepoName": $infraRepoName } else {} end) +
76+
(if $terraformAction != "" then { "terraformAction": $terraformAction } else {} end) +
77+
{
78+
"releaseVersion": $releaseVersion,
79+
"targetEnvironment": $targetEnvironment,
80+
"targetAccountGroup": $targetAccountGroup,
81+
"targetComponent": $targetComponent
82+
} +
83+
(if ($targetWorkflow | test("dispatch-(acceptance|contextual|product|security)-tests-.*\\.yaml"))
84+
then { "callerRunId": $callerRunId } else {} end)
85+
)
86+
}')
8187
8288
# Trigger The workflow
8389
curl -L \
@@ -93,20 +99,34 @@ jobs:
9399
echo "Workflow triggered. Waiting for the workflow to complete.."
94100
95101
# Poll GitHub API to check the workflow status
102+
96103
workflow_run_url=""
97-
for i in {1..12}; do
104+
for i in {1..18}; do
98105
workflow_run_url=$(curl -s \
99106
-H "Accept: application/vnd.github+json" \
100107
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
101108
-H "X-GitHub-Api-Version: 2022-11-28" \
102-
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch&status=in_progress" \
103-
| jq -r '.workflow_runs[]
104-
| select(.name
105-
| contains("'${{ inputs.targetEnvironment }}'") and
106-
contains("'${{ inputs.targetAccountGroup }}'") and
107-
contains("'${{ inputs.targetComponent }}'") and
108-
contains("'${{ inputs.terraformAction }}'"))
109-
| .url')
109+
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch" \
110+
| jq -r \
111+
--arg callerRunId "$callerRunId" \
112+
--arg targetWorkflow "${{ inputs.targetWorkflow }}" \
113+
--arg targetEnvironment "${{ inputs.targetEnvironment }}" \
114+
--arg targetAccountGroup "${{ inputs.targetAccountGroup }}" \
115+
--arg targetComponent "${{ inputs.targetComponent }}" \
116+
--arg terraformAction "${{ inputs.terraformAction }}" \
117+
'.workflow_runs[]
118+
| select(.path == ".github/workflows/" + $targetWorkflow)
119+
| select(.name
120+
| contains($targetEnvironment)
121+
and contains($targetAccountGroup)
122+
and contains($targetComponent)
123+
and contains($terraformAction)
124+
)
125+
| if ($targetWorkflow | test("dispatch-(acceptance|contextual|product|security)-tests-.*\\.yaml"))
126+
then select(.name | contains("caller:" + $callerRunId))
127+
else .
128+
end
129+
| .url')
110130
111131
if [[ -n "$workflow_run_url" && "$workflow_run_url" != null ]]; then
112132
ui_url=${workflow_run_url/api./}

0 commit comments

Comments
 (0)