Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 95 additions & 5 deletions .github/workflows/claude-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# A pull request opened by the review agent is reviewed without a membership lookup. The request asks for a review
# of the commits pushed, and of earlier ones not yet reviewed, with the whole pull request as context, and the
# decision names the commit after the push.
# It is not sent at once: the settle job waits for pushes to settle (the settle-minutes input) and sends it only if
# no newer commit was pushed and the pull request is still open and ready, so a burst of pushes gets one review.
name: Claude review

on:
Expand All @@ -46,6 +48,10 @@ on:
description: The login of the review agent, the account mentioned in a comment command or requested as a reviewer, whose pull requests are reviewed without a membership lookup and whose comments and reviewer requests never request a review.
type: string
default: cipherstash-agent
settle-minutes:
description: How many minutes a Push request waits for pushes to settle before it is sent, a whole number from 0 (no wait) to 30. A newer push in that time skips it as superseded. On a private repository, each push to a ready pull request holds a runner for the wait.
type: number
default: 5
secrets:
CLAUDE_ROUTINE_TOKEN:
description: The code-review routine's bearer token.
Expand All @@ -55,9 +61,16 @@ on:
required: true
outputs:
# For a caller that checks what happened, such as this repository's self-test (.github/workflows/self-test.yml).
# The final decision: for a Push request, the settle job's, and for every other kind, the decide job's. A
# skipped job's output is empty. A settle job that ran but left no output, such as one whose runner was lost,
# gives the settle-check-failed skip, never the decide job's fire.
decision:
description: The request decision, as JSON, such as {"decision":"skip","reason":"draft"}.
value: ${{ jobs.decide.outputs.decision }}
description: The final request decision, as JSON, such as {"decision":"skip","reason":"draft"}. For a Push request, it is the decision after the settle wait, such as {"decision":"skip","reason":"superseded"}.
value: ${{ fromJSON(jobs.decide.outputs.decision || '{}').decision == 'fire' && fromJSON(jobs.decide.outputs.decision || '{}').kind == 'push' && (jobs.settle.outputs.decision || '{"decision":"skip","reason":"settle-check-failed"}') || jobs.decide.outputs.decision }}
# The settle job's own decision, so a caller can tell a skip the settle wait made from one the decide job made.
settle-decision:
description: The settle job's decision, as JSON, for a Push request the decide job passed on, such as {"decision":"skip","reason":"superseded"}. Empty when the settle job did not run.
value: ${{ jobs.settle.outputs.decision }}
sent:
description: '"true" only when the routine trigger accepted the review request.'
value: ${{ jobs.fire.outputs.sent }}
Expand Down Expand Up @@ -214,11 +227,82 @@ jobs:
echo "Claude review: skipped (decision-failed)"
echo "Claude review: skipped (decision-failed)" >>"$GITHUB_STEP_SUMMARY"

# The settle wait: a Push request waits for pushes to settle, so a burst of pushes gets one review, of the last push.
# Runs only for a Push fire. After the wait it reads the pull request once, and passes the request on only if the pull
# request is still open, still ready and its head is still the commit after the push; otherwise it skips as
# superseded, draft or closed. Anything but a clear answer from GitHub is the settle-check-failed skip, with an error.
# It holds only pull-requests: read and no secrets, because it runs for minutes. It has no concurrency group, so a
# superseded request ends on its own as a green skip, never as a cancelled run, and a comment command or a requested
# reviewer never waits for it. The job itself stays green: its one step that can fail has continue-on-error, and
# its output falls back to the settle-check-failed skip.
settle:
needs: decide
if: fromJSON(needs.decide.outputs.decision).decision == 'fire' && fromJSON(needs.decide.outputs.decision).kind == 'push'
runs-on: ubuntu-latest
# The longest wait, 30 minutes, and the check's own time limits, with room to spare.
timeout-minutes: 40
permissions:
pull-requests: read
outputs:
# The final decision for a Push request: the decide job's decision, passed on as it was written, or a skip.
decision: ${{ steps.check.outputs.decision || '{"decision":"skip","reason":"settle-check-failed"}' }}
env:
# Where the checkout step below puts this repository's step files.
WORKFLOW_FILES: ${{ github.workspace }}/.cipherstash-workflows
steps:
# The settle check's step file, checked out from this repository at the commit the caller pinned, the same way
# as in the decide job: only the steps/ directory, no credentials kept, and skipped if either value is empty.
- name: Check out the step files
id: checkout
if: job.workflow_repository != '' && job.workflow_sha != ''
continue-on-error: true
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: .cipherstash-workflows
sparse-checkout: |
/steps/
sparse-checkout-cone-mode: false
persist-credentials: false

- name: Wait for pushes to settle
id: check
continue-on-error: true
env:
# The job's own token, which can only read pull requests.
GITHUB_TOKEN: ${{ github.token }}
DECISION: ${{ needs.decide.outputs.decision }}
SETTLE_MINUTES: ${{ inputs.settle-minutes }}
CHECKOUT_OUTCOME: ${{ steps.checkout.outcome }}
# The settle check's file, from this repository's checkout. Python's standard library only (3.10 features),
# so nothing is installed; tests/test_settle.py runs this file.
STEP_FILE: ${{ env.WORKFLOW_FILES }}/steps/settle.py
# Without the checked-out files (the checkout failed, or settle.py or its helper module is missing), or if the
# file cannot run, the lines below write the settle-check-failed skip, an error and the summary line; a later
# write of the same output name wins.
run: |
if [[ "$CHECKOUT_OUTCOME" == success && -f "$STEP_FILE" && -f "${STEP_FILE%/*}/helpers.py" ]] && python3 "$STEP_FILE"; then
exit 0
fi
echo 'decision={"decision":"skip","reason":"settle-check-failed"}' >>"$GITHUB_OUTPUT"
echo "::error::Could not check whether the push was superseded (checkout failed, or settle.py or helpers.py missing or broken); no review was requested"
echo "Claude review: skipped (settle-check-failed)"
echo "Claude review: skipped (settle-check-failed)" >>"$GITHUB_STEP_SUMMARY"

# Fires the routine trigger. It holds no permissions and sees only the decision: the event's free text reaches it only
# as the decision's text, which the send step's json module places in the request body.
# A Push request fires only if the settle job passed it on; every other kind fires on the decide job's decision, as
# the settle job does not run for it. The condition starts with !cancelled() because GitHub skips a job whose
# condition has no status function when any job before it was skipped, as the settle job is for every other kind.
fire:
needs: decide
if: fromJSON(needs.decide.outputs.decision).decision == 'fire'
needs: [decide, settle]
if: >-
${{ !cancelled()
&& needs.decide.result == 'success'
&& fromJSON(needs.decide.outputs.decision).decision == 'fire'
&& (fromJSON(needs.decide.outputs.decision).kind != 'push'
|| (needs.settle.result == 'success' && fromJSON(needs.settle.outputs.decision || '{}').decision == 'fire')) }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions: {}
Expand Down Expand Up @@ -291,9 +375,15 @@ jobs:
# reusable workflow's jobs cannot hold more than their caller.
# The checkout is given no contents permission. This relies on this repository being public, as for the decide and
# fire jobs, which hold no permissions at all; it is to be confirmed by the first live run (#20).
# The condition starts with !cancelled() for the same reason as the fire job's: the settle job before it is skipped
# for a comment command.
react:
needs: [decide, fire]
if: needs.fire.outputs.sent == 'true' && fromJSON(needs.decide.outputs.decision).react == true
if: >-
${{ !cancelled()
&& needs.fire.result == 'success'
&& needs.fire.outputs.sent == 'true'
&& fromJSON(needs.decide.outputs.decision).react == true }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
#
# Push reviews are off by default. To review the commits pushed to a pull request that is ready (not a draft), add
# `synchronize` to the pull_request types below: `types: [opened, reopened, ready_for_review, review_requested,
# synchronize]`. Each push to a ready pull request whose author is a team member, or the review agent, then requests a
# review of the commits pushed, and of an earlier push's commits that got no review of their own. Pushes to drafts,
# pushes by bots, and pushes to bots' pull requests or to pull requests from forks are never reviewed. The pinned
# release must have Push reviews; an older one skips the event, so adding it early does no harm.
# synchronize]`. Each push to a ready pull request whose author is a team member, or the review agent, then waits for
# pushes to settle (5 minutes; pass `settle-minutes` in `with:` to change it, 0 for no wait) and requests a review of
# the commits pushed if no newer commit was pushed in that time, so a burst of pushes gets one review, which also
# covers the earlier pushes' commits. On a private repository each push holds a runner for the wait, about 5 billed
# minutes. Pushes to drafts, pushes by bots, and pushes to bots' pull requests or to pull requests from forks are never
# reviewed. The pinned release must have Push reviews; an older one skips the event, so adding it early does no harm.
#
# Needs, as organisation or repository settings:
# secret CLAUDE_ROUTINE_TOKEN the code-review routine's bearer token
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/self-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
# commit that is running, not a pinned commit), with the stub's trigger id and token. The
# verify job then fails if the review workflow decided not to request a review, naming the skip reason, if the request
# was of the wrong kind for the event, or if it was not sent, and otherwise waits a few minutes for the stub's reply
# naming this run attempt.
# naming this run attempt. It passes a settle wait of 1 minute, so a run for a push stays quick; a push superseded by
# a newer push within that minute passes without a reply, because the newer push's own run is tested.
#
# A comment command, a new pull request comment whose first line is `@cipherstash-agent review`, runs the test too,
# and the verify job also checks that the comment got the review workflow's 👀 reaction. A comment always
Expand Down Expand Up @@ -139,6 +140,8 @@ jobs:
with:
routine-trigger-id: ${{ vars.CLAUDE_ROUTINE_INTEGRATION_TEST_TRIGGER_ID }}
app-client-id: ${{ vars.CLAUDE_REVIEW_APP_CLIENT_ID }}
# A short settle wait, so a run for a push stays quick. Two pushes within a minute still test the superseded skip.
settle-minutes: 1
secrets:
CLAUDE_ROUTINE_TOKEN: ${{ secrets.CLAUDE_ROUTINE_INTEGRATION_TEST_TOKEN }}
CLAUDE_REVIEW_APP_PRIVATE_KEY: ${{ secrets.CLAUDE_REVIEW_APP_PRIVATE_KEY }}
Expand All @@ -151,10 +154,12 @@ jobs:
if: ${{ !cancelled() && needs.review.result != 'skipped' }}
runs-on: ubuntu-latest
timeout-minutes: 10
# Reads the pull request's comments, and a comment's reactions. This repository is public, so the checkout below
# needs no contents permission, as the review workflow's own jobs show.
# Reads the pull request's comments, and a comment's reactions, and for a push the settle wait skipped, the pull
# request itself. This repository is public, so the checkout below needs no contents permission, as the review
# workflow's own jobs show.
permissions:
issues: read
pull-requests: read
env:
# Where the checkout step below puts this repository's step files, as in the review workflow's jobs.
WORKFLOW_FILES: ${{ github.workspace }}/.cipherstash-workflows
Expand All @@ -176,6 +181,13 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
DECISION: ${{ needs.review.outputs.decision }}
SENT: ${{ needs.review.outputs.sent }}
# The settle job's own decision, empty when it did not run: a push's superseded, draft or closed skip passes
# only when the settle wait made it.
SETTLE_DECISION: ${{ needs.review.outputs.settle-decision }}
# For a push the settle wait skipped: the pull request to read and the commit after the push, so the step
# can check the pull request is in the state the skip names. Empty for other events.
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
PUSHED_COMMIT: ${{ github.event.after }}
# Which event started this run, so the step can check the request was of the kind that event makes.
EVENT_NAME: ${{ github.event_name }}
EVENT_ACTION: ${{ github.event.action }}
Expand Down
6 changes: 5 additions & 1 deletion CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ The review request made by requesting a review from the review agent in a pull r
_Avoid_: assigned reviewer

**Push**:
The review request made when commits are pushed to a pull request that is ready (not a draft). It asks for a review of the commits pushed, and of an earlier push's commits that got no review of their own, with the whole pull request as context. A caller turns it on by listing the pull request `synchronize` event.
The review request made when commits are pushed to a pull request that is ready (not a draft). It asks for a review of the commits pushed, and of an earlier push's commits that got no review of their own, with the whole pull request as context. It is sent only after the settle wait. A caller turns it on by listing the pull request `synchronize` event.
_Avoid_: sync, update, review on push

**Settle wait**:
The minutes a Push request waits before it is sent, so a burst of pushes gets one review (5 by default, set by the `settle-minutes` input). After the wait, the request is sent only if the pull request is still open and ready and no newer commit was pushed; otherwise it is skipped as superseded, draft or closed. The one review covers the earlier pushes' commits too, because a Push request asks for every change not yet reviewed. A newer push supersedes even when its own request is skipped, such as a bot's push; then no review is sent, and the commits are reviewed with the next push that is.
_Avoid_: debounce, delay, cooldown

**Team member**:
A member of the GitHub team allowed to make review requests (by default `@cipherstash/developers`); nobody else can cause a review.
_Avoid_: member, collaborator, maintainer
Expand Down
Loading
Loading