-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ci: dispatch PR lifecycle events to a downstream repo #3926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ericallam
wants to merge
1
commit into
main
Choose a base branch
from
ci/pr-events-dispatch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+50
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| name: 📣 Dispatch PR events | ||
|
|
||
| # Notifies downstream consumers (via repository_dispatch) when pull requests | ||
| # change state, so they can react to PR lifecycle events without polling. | ||
| # Mirrors the main-image dispatch in publish.yml: target repo defaults to the | ||
| # canonical value and can be overridden by a repository variable. | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, closed, ready_for_review, converted_to_draft, edited] | ||
| push: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| dispatch: | ||
| name: Send repository_dispatch | ||
| runs-on: ubuntu-latest | ||
| permissions: {} | ||
| # Same-repo events only: fork PRs have no secrets, and title-only edits are | ||
| # the only `edited` payloads downstream cares about. | ||
| if: >- | ||
| github.repository == (vars.PR_EVENTS_DISPATCH_REPO || 'triggerdotdev/trigger.dev') && | ||
| (github.event_name == 'push' || | ||
| (github.event.pull_request.head.repo.full_name == github.repository && | ||
| (github.event.action != 'edited' || github.event.changes.title))) | ||
| steps: | ||
| - name: Build dispatch payload | ||
| id: payload | ||
| env: | ||
| EVENT_NAME: ${{ github.event_name }} | ||
| ACTION: ${{ github.event.action }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| COMMIT: ${{ github.sha }} | ||
| run: | | ||
| set -euo pipefail | ||
| # jq --arg JSON-escapes every value so nothing can inject into the payload. | ||
| if [[ "$EVENT_NAME" == "push" ]]; then | ||
| payload=$(jq -nc --arg c "$COMMIT" '{action: "push", commit: $c}') | ||
| else | ||
| payload=$(jq -nc --arg a "$ACTION" --arg n "$PR_NUMBER" '{action: $a, number: ($n | tonumber)}') | ||
| fi | ||
| echo "client_payload=$payload" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Send repository_dispatch | ||
| uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # v4.0.1 | ||
| with: | ||
| token: ${{ secrets.CROSS_REPO_PAT }} | ||
| repository: ${{ vars.PR_EVENTS_DISPATCH_TARGET || 'triggerdotdev/cloud' }} | ||
| event-type: oss-pr-event | ||
| client-payload: ${{ steps.payload.outputs.client_payload }} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.