-
Notifications
You must be signed in to change notification settings - Fork 0
ci(town-crier): producer workflow (announce + resolve on close) #36
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
e225f9e
ci(town-crier): producer workflow (announce + resolve on close)
jasperboerhof 3535b3b
ci(town-crier): least-privilege permissions + fail-open producer (rev…
jasperboerhof 2f80889
ci(town-crier): config-error fails loud, bus-hiccup fails open (revie…
jasperboerhof 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,67 @@ | ||
| # Drop this into a repo at .github/workflows/announce-pr.yml to make it a town-crier producer. | ||
| # | ||
| # Setup (once per repo or org): | ||
| # - Variable TOWN_CRIER_URL = https://<app>.fly.dev | ||
| # - Secret TOWN_CRIER_TOKEN = the bearer token minted for "github-action" | ||
| # | ||
| # Produces BOTH sides of a request's lifecycle, so the bus never drifts from GitHub: | ||
| # - announce: when "Agent Review Requested" lands on a PR, tell the crier once. | ||
| # - resolve: when that PR closes/merges, retire its thread — otherwise a landed PR | ||
| # sits "open" on the bus forever (there is no GitHub->bus merge sync) and | ||
| # joined harnesses keep getting offered already-merged work. | ||
| # Joined harnesses pick up open requests from the bus — this workflow does NOT poll or review. | ||
| # | ||
| # The bus is fail-open: a town-crier hiccup (cold start, transient 5xx) must never red a | ||
| # PR's checks, so both jobs use continue-on-error + a curl --max-time. Neither job touches | ||
| # the GITHUB_TOKEN (they auth to the bus with TOWN_CRIER_TOKEN), so permissions are dropped. | ||
| name: town-crier producer (announce + resolve) | ||
|
|
||
| permissions: {} | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [labeled, closed] | ||
|
|
||
| jobs: | ||
| announce: | ||
| if: github.event.action == 'labeled' && github.event.label.name == 'Agent Review Requested' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Announce to the crier | ||
| continue-on-error: true | ||
| env: | ||
| CRIER_URL: ${{ vars.TOWN_CRIER_URL }} | ||
| CRIER_TOKEN: ${{ secrets.TOWN_CRIER_TOKEN }} | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| REPO: ${{ github.repository }} | ||
| TITLE: ${{ github.event.pull_request.title }} | ||
|
jasperboerhof marked this conversation as resolved.
|
||
| REQUESTER: ${{ github.event.pull_request.user.login }} | ||
| run: | | ||
| # jq builds the JSON so a PR title with quotes can't break the payload. | ||
| curl -fsS --max-time 10 -X POST "$CRIER_URL/announce" \ | ||
| -H "Authorization: Bearer $CRIER_TOKEN" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d "$(jq -n \ | ||
| --arg pr "$PR_URL" \ | ||
| --arg repo "$REPO" \ | ||
| --arg title "$TITLE" \ | ||
| --arg requester "$REQUESTER" \ | ||
| '{pr_url:$pr, repo:$repo, title:$title, requester:$requester}')" | ||
|
|
||
| resolve: | ||
| if: github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'Agent Review Requested') | ||
|
jasperboerhof marked this conversation as resolved.
|
||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Resolve on the crier | ||
| continue-on-error: true | ||
| env: | ||
| CRIER_URL: ${{ vars.TOWN_CRIER_URL }} | ||
| CRIER_TOKEN: ${{ secrets.TOWN_CRIER_TOKEN }} | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| MERGED: ${{ github.event.pull_request.merged }} | ||
| run: | | ||
| NOTE=$([ "$MERGED" = "true" ] && echo "merged" || echo "closed without merge") | ||
| curl -fsS --max-time 10 -X POST "$CRIER_URL/resolve" \ | ||
| -H "Authorization: Bearer $CRIER_TOKEN" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d "$(jq -n --arg pr "$PR_URL" --arg note "$NOTE" '{pr_url:$pr, note:$note}')" | ||
Oops, something went wrong.
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.