Skip to content

Commit 8b1f762

Browse files
committed
Verify image was published before dispatching to consumers
A manual workflow_dispatch can be run against any ref at any time, including a feature branch commit whose Main build hasn't finished publishing an image yet. Query the Actions API for the most recent completed Main run at that commit and fail loudly if it didn't succeed, before notifying any consumer.
1 parent 5d5538d commit 8b1f762

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

.github/workflows/notify-consumers.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
determine-inputs:
3030
name: "Determine trigger inputs"
3131
runs-on: ubuntu-24.04
32+
permissions:
33+
actions: read
3234
if: >-
3335
github.event_name == 'workflow_dispatch' ||
3436
(github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main')
@@ -49,6 +51,20 @@ jobs:
4951
fi
5052
echo "run_url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> "$GITHUB_OUTPUT"
5153
54+
# A manual dispatch can be run against any ref at any time, including
55+
# before Main has built and published an image for that commit.
56+
- name: Verify image was published for this commit
57+
env:
58+
GH_TOKEN: ${{ github.token }}
59+
COMMIT: ${{ steps.inputs.outputs.commit }}
60+
run: |
61+
conclusion=$(gh api "repos/${{ github.repository }}/actions/runs?head_sha=$COMMIT&status=completed" \
62+
--jq '[.workflow_runs[] | select(.name == "Main")] | sort_by(.run_started_at) | last | .conclusion // "none"')
63+
if [ "$conclusion" != "success" ]; then
64+
echo "::error::No successful Main run found for commit $COMMIT (found: $conclusion). The image for this commit may not be published yet."
65+
exit 1
66+
fi
67+
5268
notify:
5369
name: "Notify ${{ matrix.repo }}"
5470
needs: determine-inputs

0 commit comments

Comments
 (0)