|
| 1 | +name: Bencher thresholds reset |
| 2 | + |
| 3 | +# Move `bencher-thresholds-reset-<workload>` tag(s) so bencher-track re-windows those |
| 4 | +# measures from a chosen commit — after a toolchain bump or any permanent shift. |
| 5 | +# Other workloads are unaffected; historical data stays in Bencher, only the |
| 6 | +# alert baseline is re-anchored. Two ways to trigger: |
| 7 | +# |
| 8 | +# - Maintainer comment `!bencher-thresholds-reset <workload|all>` on a PR: |
| 9 | +# the `ack` job (issue_comment) is the single place that parses/validates the |
| 10 | +# command. It records each valid workload as a `bencher-thresholds-reset:<workload>` |
| 11 | +# PR label and replies to confirm (or warns on an unknown/missing workload, |
| 12 | +# catching a typo immediately). On merge, the `reset` job simply reads those |
| 13 | +# labels from the event payload — no re-parsing — and anchors the tags at the |
| 14 | +# merge commit. The label is the shared flag between the two events, and is |
| 15 | +# human-visible/cancelable (remove the label to cancel a queued reset). |
| 16 | +# - Manual label (no comment needed): the merge step honors any |
| 17 | +# `bencher-thresholds-reset:<token>` label on the PR, whatever added it — so a |
| 18 | +# Triage+ collaborator can queue a reset by applying the label directly, and |
| 19 | +# cancel by removing it before merge. Naming convention: one label per token, |
| 20 | +# `bencher-thresholds-reset:<token>` where <token> is `ix-compile`, `aiur`, or |
| 21 | +# `all` (the merge step expands an `all` label into every workload). Labeling |
| 22 | +# requires Triage+, so PR authors from forks cannot self-queue a reset. The |
| 23 | +# label shares the command/workflow name; the git tag it moves is the same |
| 24 | +# stem with a dash: `bencher-thresholds-reset-<workload>`. |
| 25 | +# - workflow_dispatch: reset the chosen workload at a given commit (default |
| 26 | +# HEAD); does not read PR contents. For ad-hoc or bootstrap resets. |
| 27 | +# |
| 28 | +# pull_request_target / issue_comment both run in the base-repo context with a |
| 29 | +# write token (works for fork PRs too). Safe here because the jobs run no |
| 30 | +# PR-provided code — only `gh` calls against the trusted event payload, with the |
| 31 | +# comment body used purely as data (never evaluated). |
| 32 | +on: |
| 33 | + workflow_dispatch: |
| 34 | + inputs: |
| 35 | + workload: |
| 36 | + description: Workload baseline to reset |
| 37 | + required: true |
| 38 | + type: choice |
| 39 | + options: [ix-compile, aiur, all] |
| 40 | + sha: |
| 41 | + description: "Commit to anchor to (default: HEAD)" |
| 42 | + required: false |
| 43 | + pull_request_target: |
| 44 | + types: [closed] |
| 45 | + issue_comment: |
| 46 | + types: [created] |
| 47 | + |
| 48 | +permissions: |
| 49 | + contents: write |
| 50 | + pull-requests: write |
| 51 | + issues: write # ack creates/applies the bencher-thresholds-reset:<workload> label |
| 52 | + |
| 53 | +jobs: |
| 54 | + reset: |
| 55 | + if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true |
| 56 | + runs-on: ubuntu-latest |
| 57 | + env: |
| 58 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + REPO: ${{ github.repository }} |
| 60 | + EVENT: ${{ github.event_name }} |
| 61 | + INPUT_WORKLOAD: ${{ inputs.workload }} |
| 62 | + INPUT_SHA: ${{ inputs.sha }} |
| 63 | + HEAD_SHA: ${{ github.sha }} |
| 64 | + PR: ${{ github.event.pull_request.number }} |
| 65 | + MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }} |
| 66 | + steps: |
| 67 | + - run: | |
| 68 | + valid="ix-compile aiur" |
| 69 | + if [ "$EVENT" = workflow_dispatch ]; then |
| 70 | + # Reset the chosen workload(s) at the given commit; no PR scan. |
| 71 | + sha="${INPUT_SHA:-$HEAD_SHA}" |
| 72 | + [ "$INPUT_WORKLOAD" = all ] && workloads="$valid" || workloads="$INPUT_WORKLOAD" |
| 73 | + else |
| 74 | + # Reset the workloads the `ack` job recorded as `bencher-thresholds-reset:*` |
| 75 | + # labels (already parsed/validated at comment time), anchored at the |
| 76 | + # merge commit. Read straight from the event payload — no re-parsing. |
| 77 | + # A `bencher-thresholds-reset:all` label expands to every workload. |
| 78 | + sha="$MERGE_SHA" |
| 79 | + workloads=$(jq -r '.pull_request.labels[].name |
| 80 | + | select(startswith("bencher-thresholds-reset:")) | ltrimstr("bencher-thresholds-reset:")' \ |
| 81 | + "$GITHUB_EVENT_PATH") |
| 82 | + echo "$workloads" | grep -qx all && workloads="$valid" |
| 83 | + fi |
| 84 | +
|
| 85 | + done_list="" |
| 86 | + for w in $workloads; do |
| 87 | + case " $valid " in *" $w "*) ;; *) echo "skip unknown workload: $w"; continue ;; esac |
| 88 | + tag="bencher-thresholds-reset-$w" |
| 89 | + echo "Anchoring $tag -> $sha" |
| 90 | + # Update the tag if it exists, else create it. (Checking first avoids |
| 91 | + # the spurious 422 a PATCH-then-POST logs on first creation.) |
| 92 | + if gh api --silent "repos/$REPO/git/refs/tags/$tag" 2>/dev/null; then |
| 93 | + gh api --silent -X PATCH "repos/$REPO/git/refs/tags/$tag" -f sha="$sha" -F force=true |
| 94 | + else |
| 95 | + gh api --silent -X POST "repos/$REPO/git/refs" -f ref="refs/tags/$tag" -f sha="$sha" |
| 96 | + fi |
| 97 | + done_list="$done_list $w" |
| 98 | + done |
| 99 | + [ -z "$done_list" ] && { echo "Nothing to reset."; exit 0; } |
| 100 | +
|
| 101 | + # Confirm on the PR for the merge-triggered path. |
| 102 | + [ "$EVENT" = pull_request_target ] && gh pr comment "$PR" --repo "$REPO" \ |
| 103 | + --body "♻️ Baseline reset to \`${sha:0:7}\` for:$done_list" |
| 104 | + true |
| 105 | +
|
| 106 | + # Immediate acknowledgment: when a maintainer comments the reset command on a |
| 107 | + # still-open PR, reply that the named baseline(s) will be reset on merge — or |
| 108 | + # warn if the workload is unknown/missing. The `user.type != 'Bot'` guard keeps |
| 109 | + # this reply (which may echo the command) from re-triggering the job. |
| 110 | + ack: |
| 111 | + if: github.event_name == 'issue_comment' && github.event.issue.pull_request && github.event.issue.state == 'open' && github.event.comment.user.type != 'Bot' && contains(github.event.comment.body, '!bencher-thresholds-reset') && (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR') |
| 112 | + runs-on: ubuntu-latest |
| 113 | + env: |
| 114 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + REPO: ${{ github.repository }} |
| 116 | + PR: ${{ github.event.issue.number }} |
| 117 | + BODY: ${{ github.event.comment.body }} |
| 118 | + steps: |
| 119 | + - run: | |
| 120 | + # Accepted command tokens — applied verbatim as labels (incl. `all`, |
| 121 | + # which the merge job expands into every workload). |
| 122 | + accepted="ix-compile aiur all" |
| 123 | + # Parse the workload token(s) after the command, lowercased. |
| 124 | + workloads=$(printf '%s' "$BODY" \ |
| 125 | + | grep -oiE '!bencher-thresholds-reset[[:space:]]+[a-z0-9 -]+' \ |
| 126 | + | sed -E 's/^!bencher-thresholds-reset[[:space:]]+//I' \ |
| 127 | + | tr '[:upper:] ' '[:lower:]\n' | sort -u) |
| 128 | + ok="" |
| 129 | + for w in $workloads; do |
| 130 | + case " $accepted " in *" $w "*) ok="$ok $w" ;; *) ;; esac |
| 131 | + done |
| 132 | + if [ -n "$ok" ]; then |
| 133 | + # Record each workload as a label — the flag the merge-time `reset` |
| 134 | + # job reads. Create the label on first use (idempotent), then apply. |
| 135 | + for w in $ok; do |
| 136 | + label="bencher-thresholds-reset:$w" |
| 137 | + gh label create "$label" --repo "$REPO" --color BFD4F2 \ |
| 138 | + --description "bencher baseline reset queued on merge" 2>/dev/null || true |
| 139 | + gh pr edit "$PR" --repo "$REPO" --add-label "$label" |
| 140 | + done |
| 141 | + gh pr comment "$PR" --repo "$REPO" \ |
| 142 | + --body "♻️ Baseline reset queued for:$ok — will anchor to the merge commit when this PR merges." |
| 143 | + else |
| 144 | + gh pr comment "$PR" --repo "$REPO" \ |
| 145 | + --body "⚠️ Reset command matched no known workload (expected \`ix-compile\`, \`aiur\`, or \`all\`). Nothing will reset on merge." |
| 146 | + fi |
0 commit comments