Skip to content

Commit 3aed72d

Browse files
Merge pull request #25 from devopsabcs-engineering/feature/2110-fix-dispatch-race
fix(workflows): resolve dispatch run ID race condition in deploy-all Fixes AB#2110
2 parents 64123f1 + 4f28504 commit 3aed72d

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

.github/workflows/deploy-all.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,43 @@ jobs:
3838
env:
3939
GH_TOKEN: ${{ secrets.DISPATCH_PAT }}
4040
run: |
41-
echo "Dispatching ci-cd workflow for ${{ matrix.name }}..."
41+
# Record timestamp before dispatch to identify the new run
42+
BEFORE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
43+
echo "before=$BEFORE" >> "$GITHUB_ENV"
44+
echo "Dispatching ci-cd workflow for ${{ matrix.name }} (after $BEFORE)..."
4245
gh workflow run ci-cd.yml \
4346
--repo devopsabcs-engineering/${{ matrix.repo }} \
4447
--ref main \
4548
--field skip_teardown=true
4649
echo "Dispatch sent to ${{ matrix.repo }} (teardown skipped)"
4750
48-
- name: Wait for workflow to start
51+
- name: Wait for workflow run to appear
4952
env:
5053
GH_TOKEN: ${{ secrets.DISPATCH_PAT }}
5154
run: |
52-
echo "Waiting for workflow run to appear..."
53-
sleep 10
54-
RUN_ID=$(gh run list \
55-
--repo devopsabcs-engineering/${{ matrix.repo }} \
56-
--workflow ci-cd.yml \
57-
--limit 1 \
58-
--json databaseId \
59-
--jq '.[0].databaseId')
60-
echo "Workflow run started: $RUN_ID"
61-
echo "run_id=$RUN_ID" >> "$GITHUB_ENV"
55+
echo "Waiting for workflow run created after ${{ env.before }}..."
56+
for i in $(seq 1 30); do
57+
RUN_ID=$(gh run list \
58+
--repo devopsabcs-engineering/${{ matrix.repo }} \
59+
--workflow ci-cd.yml \
60+
--json databaseId,createdAt,event \
61+
--jq "[.[] | select(.createdAt >= \"${{ env.before }}\" and .event == \"workflow_dispatch\")] | .[0].databaseId")
62+
if [ -n "$RUN_ID" ] && [ "$RUN_ID" != "null" ]; then
63+
echo "Found workflow run: $RUN_ID"
64+
echo "run_id=$RUN_ID" >> "$GITHUB_ENV"
65+
exit 0
66+
fi
67+
echo "Attempt $i: run not found yet, waiting 10s..."
68+
sleep 10
69+
done
70+
echo "::error::Timed out waiting for workflow run to appear"
71+
exit 1
6272
6373
- name: Wait for workflow to complete
6474
env:
6575
GH_TOKEN: ${{ secrets.DISPATCH_PAT }}
6676
run: |
67-
echo "Watching workflow run ${{ env.run_id }}..."
77+
echo "Watching workflow run ${{ env.run_id }} in ${{ matrix.repo }}..."
6878
gh run watch ${{ env.run_id }} \
6979
--repo devopsabcs-engineering/${{ matrix.repo }} \
7080
--exit-status

0 commit comments

Comments
 (0)