Skip to content

Commit df964ea

Browse files
authored
feat(ci): dispatch a repository event when the main webapp image is published (#3875)
## Summary On every `main` build, once the webapp image is pushed to the registry, the publish workflow emits a cross-repo `repository_dispatch` event (`main-image-published`) carrying a digest-pinned image ref. Other repositories in the org can subscribe to that event and build or deploy from the exact artifact, instead of chasing the moving `main` tag. ## Design `publish-webapp.yml` now exposes the pushed multi-arch index digest as a workflow output. `publish.yml` adds a `dispatch-main-image` job (after `publish-webapp`) that builds `<image_repo>@<digest>` and sends the dispatch via the same pinned `peter-evans/repository-dispatch` action already used elsewhere in this repo, authed with `CROSS_REPO_PAT`. It fires only when the published tag is `main`, so semver releases and other tag builds are excluded, and only from the canonical repo so forks never dispatch. The payload is JSON-escaped with `jq`.
1 parent 1b0f2c7 commit df964ea

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

.github/workflows/publish-webapp.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ on:
2929
image_repo:
3030
description: The image repository the build was published to (without tag)
3131
value: ${{ jobs.publish.outputs.image_repo }}
32+
digest:
33+
description: Multi-arch index digest (sha256:...) of the published image
34+
value: ${{ jobs.publish.outputs.digest }}
3235
secrets:
3336
SENTRY_AUTH_TOKEN:
3437
required: false
@@ -42,6 +45,7 @@ jobs:
4245
version: ${{ steps.get_tag.outputs.tag }}
4346
short_sha: ${{ steps.get_commit.outputs.sha_short }}
4447
image_repo: ${{ steps.set_tags.outputs.image_repo }}
48+
digest: ${{ steps.build_push.outputs.digest }}
4549
steps:
4650
- name: 🏭 Setup Depot CLI
4751
uses: depot/setup-action@15c09a5f77a0840ad4bce955686522a257853461 # v1.7.1

.github/workflows/publish.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ on:
1515
required: false
1616
SENTRY_AUTH_TOKEN:
1717
required: false
18+
CROSS_REPO_PAT:
19+
required: false
1820
push:
1921
branches:
2022
- main
@@ -112,3 +114,45 @@ jobs:
112114
uses: ./.github/workflows/trivy-image-webapp.yml
113115
with:
114116
image-ref: ${{ needs.publish-webapp.outputs.image_repo }}:${{ needs.publish-webapp.outputs.version }}
117+
118+
# Announce the freshly published mutable `main` webapp image to subscriber
119+
# repos in the org via repository_dispatch, handing them a digest-pinned ref to
120+
# build or deploy from. Fires only for the `main` tag — never semver releases or
121+
# other tag builds — and only from the canonical repo (forks have no PAT).
122+
dispatch-main-image:
123+
name: 📣 Dispatch main image
124+
needs: [publish-webapp]
125+
if: github.repository == 'triggerdotdev/trigger.dev' && needs.publish-webapp.outputs.version == 'main'
126+
runs-on: ubuntu-latest
127+
permissions: {}
128+
steps:
129+
- name: Build dispatch payload
130+
id: payload
131+
env:
132+
IMAGE_REPO: ${{ needs.publish-webapp.outputs.image_repo }}
133+
DIGEST: ${{ needs.publish-webapp.outputs.digest }}
134+
COMMIT: ${{ github.sha }}
135+
run: |
136+
set -euo pipefail
137+
# Pin to the exact multi-arch index just pushed so subscribers resolve a
138+
# single immutable artifact rather than chasing the moving `main` tag.
139+
if [[ -z "${DIGEST}" ]]; then
140+
echo "::error::publish-webapp produced no image digest; refusing to dispatch"
141+
exit 1
142+
fi
143+
image="${IMAGE_REPO}@${DIGEST}"
144+
# jq --arg JSON-escapes every value, so the ref/commit can't break out of
145+
# or inject into the client payload.
146+
payload=$(jq -nc \
147+
--arg img "$image" \
148+
--arg c "$COMMIT" \
149+
'{image: $img, commit: $c}')
150+
echo "client_payload=$payload" >> "$GITHUB_OUTPUT"
151+
152+
- name: Send repository_dispatch
153+
uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # v4.0.1
154+
with:
155+
token: ${{ secrets.CROSS_REPO_PAT }}
156+
repository: triggerdotdev/cloud
157+
event-type: main-image-published
158+
client-payload: ${{ steps.payload.outputs.client_payload }}

0 commit comments

Comments
 (0)