From a9a63656ab5016402211de8a4001c9c82af85765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Thu, 19 Nov 2026 09:11:20 +0100 Subject: [PATCH 1/5] feat(automation): merge stable core bumps that change no proto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A stable core release whose regenerated bindings are identical needs no SDK work, so core-watch can merge its proposal and release-tag.yml tags the SDK release right away. merge-bump-pr.sh merges such a proposal only when it is still one bot commit touching nothing but buf.gen.yaml and README.md, its required checks are green, and no one added the hold label. A release that changes anything under proto/ always waits for review, so the SDK release may lag until the new features are wrapped. Off by default: the CORE_AUTO_MERGE repository variable switches it on, and the bot needs a pull-request bypass on the main-integrity ruleset. Signed-off-by: Roland Huß --- .github/workflows/core-watch.yml | 14 +++- hack/automation/README.md | 13 +++- hack/automation/bump-pr-body.md | 1 + hack/automation/merge-bump-pr.sh | 119 +++++++++++++++++++++++++++++++ mise.toml | 4 ++ 5 files changed, 148 insertions(+), 3 deletions(-) create mode 100755 hack/automation/merge-bump-pr.sh diff --git a/.github/workflows/core-watch.yml b/.github/workflows/core-watch.yml index 15658b9..24b5bd2 100644 --- a/.github/workflows/core-watch.yml +++ b/.github/workflows/core-watch.yml @@ -1,8 +1,9 @@ # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -# Opens one update proposal per new core release tag, then reconciles the RPC -# coverage issues against the newest core tag (hack/automation/). +# Opens one update proposal per new core release tag, reconciles the RPC +# coverage issues against the newest core tag, and merges stable proposals +# that change no proto when auto-merge is on (hack/automation/). name: core-watch on: @@ -97,6 +98,15 @@ jobs: MAX_NEW: ${{ inputs.max_new_issues }} run: BOT_LOGIN="${APP_SLUG}[bot]" hack/automation/rpc-issues.sh ${MAX_NEW:+--max-new "$MAX_NEW"} + # Merges stable proposals that change no proto and whose checks went + # green since the last run. Off unless the CORE_AUTO_MERGE repository + # variable is on; see hack/automation/merge-bump-pr.sh. + - name: Merge proposals that change no proto + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + CORE_AUTO_MERGE: ${{ vars.CORE_AUTO_MERGE }} + run: hack/automation/merge-bump-pr.sh + - name: Report failure if: failure() env: diff --git a/hack/automation/README.md b/hack/automation/README.md index 80abd68..389f32c 100644 --- a/hack/automation/README.md +++ b/hack/automation/README.md @@ -10,6 +10,7 @@ Workflows run them with a token of the `ai-openshell-sdk-go` GitHub App (`ai-ope | `open-bump-pr.sh [--dry-run]` | `core:bump` | Open the update proposal for one core tag: branch `core/`, pin change, regenerated bindings, proto diff in the body, labels `core-bump` plus `stable` or `prerelease`. Closes older pre-release proposals. | | `bump-pr-body.md` | | PR body template for `open-bump-pr.sh`. | | `core-registry.sh` | | Sourced by `start-gateway.sh` and `open-bump-pr.sh`: `core_registry ` prints the registry that holds a core release's images, `quay.io/ai-openshell` for releases since the move and `ghcr.io/nvidia/openshell` for older ones. | +| `merge-bump-pr.sh [--dry-run] [--auto-merge on\|off]` | `core:merge` | Merge stable proposals that change no proto: one bot commit touching only the pin and the README (nothing under `proto/`), green checks, no `hold` label. Off unless `CORE_AUTO_MERGE` is `on`. | | `tag-release.sh [--dry-run]` | `release:tag` | After a stable pin lands on `main`: create the lockstep tag `vX.Y.Z` and the GitHub release, then ask the Go module proxy for the version. | | `drift-check.sh --out ` | `core:drift` | Compare core `main` against the pin: `buf breaking`, regenerate and build, uncovered RPCs. Writes the markdown report. | | `update-drift-issue.sh ` | | Create, update, or close the single `Core main drift` issue from a report; uncovered RPCs link to their open RPC coverage issues. | @@ -28,7 +29,7 @@ Workflows run them with a token of the `ai-openshell-sdk-go` GitHub App (`ai-ope | Workflow | Script | |----------|--------| -| `core-watch.yml` (hourly) | `core-tags.sh`, then `open-bump-pr.sh` per tag, then `rpc-issues.sh` | +| `core-watch.yml` (hourly) | `core-tags.sh`, then `open-bump-pr.sh` per tag, then `rpc-issues.sh` and `merge-bump-pr.sh` | | `release-tag.yml` (push to `main`) | `tag-release.sh` | | `core-drift.yml` (nightly) | `drift-check.sh`, then `update-drift-issue.sh` | | `e2e.yml` (reusable) | `start-gateway.sh`, `mise run e2e`, `stop-gateway.sh` | @@ -52,3 +53,13 @@ Workflows run them with a token of the `ai-openshell-sdk-go` GitHub App (`ai-ope If they are expected, run core-watch by hand with the input `max_new_issues`, or locally `mise run core:rpc-issues -- --max-new `. - **Preview**: `mise run core:rpc-issues -- --dry-run` prints every planned action with its body and changes nothing (it reads GitHub, so `gh` must be logged in). Without `--dry-run`, the script applies the plan only with an explicit `BOT_LOGIN` and the bot's token (core-watch passes both); under a person's `gh` login it stops before any write, because later runs would not manage the issues it opened. + +## Auto-merge for stable pins + +`merge-bump-pr.sh` is off until the repository variable `CORE_AUTO_MERGE` is `on`. +It merges a stable proposal only when the release changes no proto: the regenerated bindings under `proto/` are identical, so the SDK needs no work and can be tagged right away. +A release that changes the protos always waits for review; the SDK release may lag until the new features are wrapped and usable (see the RPC coverage issues). + +It merges with the bot token through a ruleset bypass, so an admin has to add the `ai-openshell-sdk-go` App to the `main-integrity` ruleset as a bypass actor with mode "pull requests only". +A proposal goes back to normal review as soon as anything else is pushed to it, a conformance fixture changes, a check fails, or someone adds the `hold` label. +Merges happen on the hourly run after the checks turn green, so a stable SDK release follows the core release within about two hours. diff --git a/hack/automation/bump-pr-body.md b/hack/automation/bump-pr-body.md index 2120bb9..efed06f 100644 --- a/hack/automation/bump-pr-body.md +++ b/hack/automation/bump-pr-body.md @@ -14,3 +14,4 @@ Move the core pin from `{{OLD}}` to `{{NEW}}` ({{KIND}}). - CI and E2E must pass. If the SDK needs changes for this core version, push them to this branch. - Merging a stable pin tags the SDK release `{{NEW}}`. Pre-release pins are not tagged; a newer pre-release proposal replaces this one. +- When auto-merge is on (repository variable `CORE_AUTO_MERGE`), core-watch merges a stable proposal without review if it changes nothing under `proto/`, is still one bot commit, and its checks are green. Add the `hold` label to keep it for review. diff --git a/hack/automation/merge-bump-pr.sh b/hack/automation/merge-bump-pr.sh new file mode 100755 index 0000000..7528a5e --- /dev/null +++ b/hack/automation/merge-bump-pr.sh @@ -0,0 +1,119 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# merge-bump-pr.sh: merge stable core-bump proposals that change no proto. +# +# Usage: merge-bump-pr.sh [--dry-run] [--auto-merge on|off] +# +# A stable core release whose bindings are unchanged needs no SDK work, so +# its proposal can merge, and release-tag.yml tags the SDK release, without +# waiting for a review. A release that changes the protos waits for review: +# the SDK release may lag until the new features are wrapped and usable. +# On or off comes from --auto-merge or CORE_AUTO_MERGE (default off). +# +# Every condition is checked again on each run; labels and the PR body are +# not trusted. A proposal is merged only when all of these hold: +# - open, not a draft, from branch core/vX.Y.Z of this repository into main +# - no "hold" label (a maintainer's way to keep it for review) +# - exactly one commit since main, authored and committed by the bot +# identity in git config (the one core-watch sets), so any human push +# sends it back to review +# - the pin in buf.gen.yaml is the branch's tag, and the commit touches +# only buf.gen.yaml and README.md: no file under proto/ changed (the +# generated bindings are identical), and no conformance fixture changed +# - the checks in required_checks passed and none failed or is pending +# The bot must be a bypass actor (pull requests only) on the main-integrity +# ruleset, since the merge skips the code owner review. +# Run from the root of an sdk-go clone. GH_TOKEN comes from the environment. +set -euo pipefail + +sdk_repo=${SDK_REPO:-ai-openshell/sdk-go} +required_checks=("ci" "e2e / e2e" "DCO") +allowed_paths='^(buf\.gen\.yaml|README\.md)$' + +dry=0 +mode=${CORE_AUTO_MERGE:-off} +while [ $# -gt 0 ]; do + case $1 in + --dry-run) dry=1; shift ;; + --auto-merge) mode=${2:?--auto-merge needs on or off}; shift 2 ;; + *) echo "usage: $0 [--dry-run] [--auto-merge on|off]" >&2; exit 2 ;; + esac +done +case $mode in +off | "") echo "Auto-merge is off (CORE_AUTO_MERGE=${mode:-unset})."; exit 0 ;; +on) ;; +*) echo "ERROR: CORE_AUTO_MERGE must be on or off, not '$mode'" >&2; exit 2 ;; +esac + +die() { echo "ERROR: $*" >&2; exit 1; } +[ "$(git rev-parse --show-toplevel)" = "$(pwd -P)" ] || die "run this from the root of the sdk-go clone" +bot_email=$(git config user.email) || die "git user.email is not set; it names the bot identity" + +git fetch --quiet origin main + +prs=$(gh pr list -R "$sdk_repo" --label core-bump --label stable --state open \ + --json number,headRefName,headRefOid,baseRefName,isDraft,isCrossRepository,labels \ + --jq '.[] | [.number, .headRefName, .headRefOid, .baseRefName, .isDraft, .isCrossRepository, + ([.labels[].name] | index("hold") != null)] | @tsv') +[ -n "$prs" ] || { echo "No open stable core-bump proposals."; exit 0; } + +while IFS=$'\t' read -r n head sha base draft cross held; do + skip() { echo "#$n: $*; leaving it for review."; } + tag=${head#core/} + + [ "$base" = main ] || { skip "base is $base, not main"; continue; } + [ "$draft" = false ] || { skip "draft"; continue; } + [ "$cross" = false ] || { skip "head is in a fork"; continue; } + [ "$held" = false ] || { skip "labeled hold"; continue; } + [[ "$head" =~ ^core/v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { skip "branch $head is not core/vX.Y.Z"; continue; } + + git fetch --quiet origin "+refs/heads/$head:refs/remotes/origin/$head" + [ "$(git rev-parse "origin/$head")" = "$sha" ] || { skip "head moved during the run"; continue; } + mb=$(git merge-base origin/main "$sha") + + count=$(git rev-list --count "$mb..$sha") + [ "$count" = 1 ] || { skip "$count commits, expected 1"; continue; } + idents=$(git log -1 --format='%ae %ce' "$sha") + [ "$idents" = "$bot_email $bot_email" ] || { skip "commit is not the bot's ($idents)"; continue; } + + pin=$(git show "$sha:buf.gen.yaml" | yq -r '.inputs[0].tag') + [ "$pin" = "$tag" ] || { skip "pin is $pin, branch says $tag"; continue; } + extra=$(git diff --name-only "$mb" "$sha" | grep -Ev "$allowed_paths" || true) + if [ -n "$extra" ]; then + if grep -q '^proto/' <<<"$extra"; then + skip "the bindings change ($(grep -c '^proto/' <<<"$extra") files under proto/), so the new core API needs review" + else + skip "touches files outside the pin bump: $(tr '\n' ' ' <<<"$extra")" + fi + continue + fi + + # gh pr checks exits non-zero while checks fail or are pending; read the + # buckets instead. Each required check must be present and pass, and no + # other check may fail or be pending. + checks=$(gh pr checks "$n" -R "$sdk_repo" --json name,bucket 2>/dev/null || true) + [ -n "$checks" ] || { skip "no checks reported yet"; continue; } + missing= + for c in "${required_checks[@]}"; do + jq -e --arg c "$c" 'any(.[]; .name == $c and .bucket == "pass")' <<<"$checks" >/dev/null || missing+="'$c' " + done + [ -z "$missing" ] || { skip "required checks not passed: $missing"; continue; } + bad=$(jq -r '[.[] | select(.bucket != "pass" and .bucket != "skipping") | "\(.name) (\(.bucket))"] | join(", ")' <<<"$checks") + [ -z "$bad" ] || { skip "checks not green: $bad"; continue; } + + comment=$(printf 'Merged without review by core-watch: core `%s` changes no proto, so the generated bindings are identical; one bot commit, pin bump only, required checks green.\n\nMerging tags the SDK release `%s`.' \ + "$tag" "$tag") + + if [ "$dry" -eq 1 ]; then + echo "dry-run: would merge #$n ($tag) at $sha with comment:" + sed 's/^/ | /' <<<"$comment" + continue + fi + gh pr comment "$n" -R "$sdk_repo" --body "$comment" + # --match-head-commit refuses the merge if someone pushed since the checks. + # --admin uses the bot's ruleset bypass for the code owner review. + gh pr merge "$n" -R "$sdk_repo" --squash --admin --match-head-commit "$sha" + echo "#$n: merged ($tag)." +done <<<"$prs" diff --git a/mise.toml b/mise.toml index dfa7a62..0d91f30 100644 --- a/mise.toml +++ b/mise.toml @@ -251,6 +251,10 @@ run = "hack/automation/open-bump-pr.sh" description = "Tag the lockstep SDK release for a stable pin (--dry-run prints what it would do)" run = "hack/automation/tag-release.sh" +[tasks."core:merge"] +description = "Merge stable core proposals that change no proto (--dry-run, --auto-merge on|off)" +run = "hack/automation/merge-bump-pr.sh" + [tasks."core:drift"] description = "Compare core main with the pin: mise run core:drift -- --out " run = "hack/automation/drift-check.sh" From 89d1bd8f0cf22760a44ee0a0790a11633b4699a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Wed, 25 Nov 2026 09:11:10 +0100 Subject: [PATCH 2/5] feat(automation): check the exact pin bump and merge from its own job MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compare the bump commit's tree with the tree pin_bump_tree rebuilds from the merge base (pin in buf.gen.yaml, README line, nothing else), instead of allowing any change to buf.gen.yaml and README.md. Another edit inside buf.gen.yaml, such as a local Buf plugin, now sends the proposal to review. open-bump-pr.sh makes the same edits through the shared pin_bump_edit, so producer and checker cannot drift apart. Move the merge into a separate core-watch job that mints its token from a merge-only App (SDK_MERGE_CLIENT_ID, SDK_MERGE_PRIVATE_KEY). Only that App needs the main-integrity bypass, the bump App that pushes core/* branches does not get it, and the job runs no generator or other code from core. The watch job passes the bump bot's email, which merge-bump-pr.sh now reads from BUMP_BOT_EMAIL. Document the rulesets an admin sets up before turning auto-merge on. Signed-off-by: Roland Huß --- .github/workflows/core-watch.yml | 64 ++++++++++++++++++++++++++++---- hack/automation/README.md | 21 +++++++++-- hack/automation/bump-pr-body.md | 2 +- hack/automation/merge-bump-pr.sh | 45 +++++++++++++--------- hack/automation/open-bump-pr.sh | 14 +++---- hack/automation/pin-bump.sh | 45 ++++++++++++++++++++++ 6 files changed, 152 insertions(+), 39 deletions(-) create mode 100644 hack/automation/pin-bump.sh diff --git a/.github/workflows/core-watch.yml b/.github/workflows/core-watch.yml index 24b5bd2..f17828f 100644 --- a/.github/workflows/core-watch.yml +++ b/.github/workflows/core-watch.yml @@ -1,9 +1,10 @@ # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -# Opens one update proposal per new core release tag, reconciles the RPC -# coverage issues against the newest core tag, and merges stable proposals -# that change no proto when auto-merge is on (hack/automation/). +# Opens one update proposal per new core release tag and reconciles the RPC +# coverage issues against the newest core tag; when auto-merge is on, a +# separate job merges stable proposals that change no proto +# (hack/automation/). name: core-watch on: @@ -35,6 +36,8 @@ jobs: environment: sdk-bot runs-on: ubuntu-latest timeout-minutes: 20 + outputs: + bot_email: ${{ steps.identity.outputs.email }} steps: - id: app-token uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 @@ -59,6 +62,7 @@ jobs: run: mise install --locked - name: Set the bot identity + id: identity env: GH_TOKEN: ${{ steps.app-token.outputs.token }} APP_SLUG: ${{ steps.app-token.outputs.app-slug }} @@ -66,7 +70,9 @@ jobs: set -euo pipefail id=$(gh api "users/${APP_SLUG}[bot]" --jq .id) git config user.name "${APP_SLUG}[bot]" - git config user.email "${id}+${APP_SLUG}[bot]@users.noreply.github.com" + email="${id}+${APP_SLUG}[bot]@users.noreply.github.com" + git config user.email "$email" + echo "email=$email" >>"$GITHUB_OUTPUT" - name: Propose new core tags env: @@ -98,13 +104,55 @@ jobs: MAX_NEW: ${{ inputs.max_new_issues }} run: BOT_LOGIN="${APP_SLUG}[bot]" hack/automation/rpc-issues.sh ${MAX_NEW:+--max-new "$MAX_NEW"} - # Merges stable proposals that change no proto and whose checks went - # green since the last run. Off unless the CORE_AUTO_MERGE repository - # variable is on; see hack/automation/merge-bump-pr.sh. + - name: Report failure + if: failure() + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: hack/automation/report-failure.sh core-watch "$RUN_URL" + + # Merges stable proposals that change no proto and whose checks went green + # (hack/automation/merge-bump-pr.sh). Only when the CORE_AUTO_MERGE + # repository variable is on. A separate job with a separate App: only the + # merge App is a bypass actor on main-integrity, the bump App that pushes + # core/* branches is not, and this job runs no generator or other code + # from core. + merge: + name: merge + needs: watch + if: ${{ !cancelled() && vars.CORE_AUTO_MERGE == 'on' && needs.watch.outputs.bot_email != '' }} + environment: sdk-bot + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - id: app-token + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + client-id: ${{ secrets.SDK_MERGE_CLIENT_ID }} + private-key: ${{ secrets.SDK_MERGE_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write + permission-checks: read + permission-statuses: read + permission-issues: write + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - uses: jdx/mise-action@236a21c3b91f5db6d4e174b348674a0f0caac06d # v5.2.9 + with: + install: false + + - name: Install tools + run: mise install --locked yq + - name: Merge proposals that change no proto env: GH_TOKEN: ${{ steps.app-token.outputs.token }} CORE_AUTO_MERGE: ${{ vars.CORE_AUTO_MERGE }} + BUMP_BOT_EMAIL: ${{ needs.watch.outputs.bot_email }} run: hack/automation/merge-bump-pr.sh - name: Report failure @@ -112,4 +160,4 @@ jobs: env: GH_TOKEN: ${{ steps.app-token.outputs.token }} RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - run: hack/automation/report-failure.sh core-watch "$RUN_URL" + run: hack/automation/report-failure.sh core-watch-merge "$RUN_URL" diff --git a/hack/automation/README.md b/hack/automation/README.md index 389f32c..bda5975 100644 --- a/hack/automation/README.md +++ b/hack/automation/README.md @@ -10,7 +10,8 @@ Workflows run them with a token of the `ai-openshell-sdk-go` GitHub App (`ai-ope | `open-bump-pr.sh [--dry-run]` | `core:bump` | Open the update proposal for one core tag: branch `core/`, pin change, regenerated bindings, proto diff in the body, labels `core-bump` plus `stable` or `prerelease`. Closes older pre-release proposals. | | `bump-pr-body.md` | | PR body template for `open-bump-pr.sh`. | | `core-registry.sh` | | Sourced by `start-gateway.sh` and `open-bump-pr.sh`: `core_registry ` prints the registry that holds a core release's images, `quay.io/ai-openshell` for releases since the move and `ghcr.io/nvidia/openshell` for older ones. | -| `merge-bump-pr.sh [--dry-run] [--auto-merge on\|off]` | `core:merge` | Merge stable proposals that change no proto: one bot commit touching only the pin and the README (nothing under `proto/`), green checks, no `hold` label. Off unless `CORE_AUTO_MERGE` is `on`. | +| `merge-bump-pr.sh [--dry-run] [--auto-merge on\|off]` | `core:merge` | Merge stable proposals that change no proto: one commit by the bump bot (`BUMP_BOT_EMAIL`) whose tree is exactly the pin bump, green checks, no `hold` label. Off unless `CORE_AUTO_MERGE` is `on`. | +| `pin-bump.sh` | | Sourced by `open-bump-pr.sh` and `merge-bump-pr.sh`: `pin_bump_edit ` makes the pin and README edits of a bump, `pin_bump_tree ` prints the tree a bump commit with only those edits has. | | `tag-release.sh [--dry-run]` | `release:tag` | After a stable pin lands on `main`: create the lockstep tag `vX.Y.Z` and the GitHub release, then ask the Go module proxy for the version. | | `drift-check.sh --out ` | `core:drift` | Compare core `main` against the pin: `buf breaking`, regenerate and build, uncovered RPCs. Writes the markdown report. | | `update-drift-issue.sh ` | | Create, update, or close the single `Core main drift` issue from a report; uncovered RPCs link to their open RPC coverage issues. | @@ -29,7 +30,7 @@ Workflows run them with a token of the `ai-openshell-sdk-go` GitHub App (`ai-ope | Workflow | Script | |----------|--------| -| `core-watch.yml` (hourly) | `core-tags.sh`, then `open-bump-pr.sh` per tag, then `rpc-issues.sh` and `merge-bump-pr.sh` | +| `core-watch.yml` (hourly) | job `watch`: `core-tags.sh`, then `open-bump-pr.sh` per tag, then `rpc-issues.sh`; job `merge` (only when `CORE_AUTO_MERGE` is `on`): `merge-bump-pr.sh` | | `release-tag.yml` (push to `main`) | `tag-release.sh` | | `core-drift.yml` (nightly) | `drift-check.sh`, then `update-drift-issue.sh` | | `e2e.yml` (reusable) | `start-gateway.sh`, `mise run e2e`, `stop-gateway.sh` | @@ -60,6 +61,18 @@ Workflows run them with a token of the `ai-openshell-sdk-go` GitHub App (`ai-ope It merges a stable proposal only when the release changes no proto: the regenerated bindings under `proto/` are identical, so the SDK needs no work and can be tagged right away. A release that changes the protos always waits for review; the SDK release may lag until the new features are wrapped and usable (see the RPC coverage issues). -It merges with the bot token through a ruleset bypass, so an admin has to add the `ai-openshell-sdk-go` App to the `main-integrity` ruleset as a bypass actor with mode "pull requests only". -A proposal goes back to normal review as soon as anything else is pushed to it, a conformance fixture changes, a check fails, or someone adds the `hold` label. +The proposal must be exactly a pin bump. +`pin_bump_tree` rebuilds the expected tree from the merge base with the same edits `open-bump-pr.sh` makes (the pin in `buf.gen.yaml` and the README line), and the bump commit's tree has to match it. +Any other change sends the proposal to review, including one inside `buf.gen.yaml` such as a plugin entry, a changed conformance fixture, or a second commit. +The proposal also goes back to review when a check fails or someone adds the `hold` label. Merges happen on the hourly run after the checks turn green, so a stable SDK release follows the core release within about two hours. + +The merge runs in its own core-watch job, `merge`, with the token of a second GitHub App that only merges (secrets `SDK_MERGE_CLIENT_ID` and `SDK_MERGE_PRIVATE_KEY` in `sdk-bot`). +That job runs no generator or other code from core. +The script checks the proposal; who may write a `core/*` branch and who may skip review are set by repository rules. +Before an admin sets `CORE_AUTO_MERGE` to `on`: + +1. A ruleset on `core/*` lets only the `ai-openshell-sdk-go` App and maintainers create, update, or delete those branches. +2. A ruleset on `main` requires `ci`, `e2e / e2e`, and `DCO` with no bypass actors. +3. The merge App is installed on this repository with contents and pull requests write, checks and statuses read, and issues write (for failure reports), and its secrets are in `sdk-bot`. +4. The merge App, and only the merge App, is a bypass actor on the `main-integrity` ruleset with mode "pull requests only", so its merge can skip the code owner review. diff --git a/hack/automation/bump-pr-body.md b/hack/automation/bump-pr-body.md index efed06f..e5af0c8 100644 --- a/hack/automation/bump-pr-body.md +++ b/hack/automation/bump-pr-body.md @@ -14,4 +14,4 @@ Move the core pin from `{{OLD}}` to `{{NEW}}` ({{KIND}}). - CI and E2E must pass. If the SDK needs changes for this core version, push them to this branch. - Merging a stable pin tags the SDK release `{{NEW}}`. Pre-release pins are not tagged; a newer pre-release proposal replaces this one. -- When auto-merge is on (repository variable `CORE_AUTO_MERGE`), core-watch merges a stable proposal without review if it changes nothing under `proto/`, is still one bot commit, and its checks are green. Add the `hold` label to keep it for review. +- When auto-merge is on (repository variable `CORE_AUTO_MERGE`), core-watch merges a stable proposal without review if it is still the single bot commit, changes nothing but the pin and the README line (so nothing under `proto/`), and its checks are green. Add the `hold` label to keep it for review. diff --git a/hack/automation/merge-bump-pr.sh b/hack/automation/merge-bump-pr.sh index 7528a5e..50f5add 100755 --- a/hack/automation/merge-bump-pr.sh +++ b/hack/automation/merge-bump-pr.sh @@ -16,21 +16,28 @@ # not trusted. A proposal is merged only when all of these hold: # - open, not a draft, from branch core/vX.Y.Z of this repository into main # - no "hold" label (a maintainer's way to keep it for review) -# - exactly one commit since main, authored and committed by the bot -# identity in git config (the one core-watch sets), so any human push +# - exactly one commit since main, authored and committed by the bump +# bot (BUMP_BOT_EMAIL, the identity core-watch sets), so any other push # sends it back to review -# - the pin in buf.gen.yaml is the branch's tag, and the commit touches -# only buf.gen.yaml and README.md: no file under proto/ changed (the -# generated bindings are identical), and no conformance fixture changed +# - the commit's tree is exactly the tree pin_bump_tree (pin-bump.sh) +# rebuilds from the merge base: the pin in buf.gen.yaml set to the +# branch's tag and the README line updated, nothing else. No file under +# proto/ changed (the generated bindings are identical), no conformance +# fixture changed, and no other edit to buf.gen.yaml, such as a plugin. # - the checks in required_checks passed and none failed or is pending -# The bot must be a bypass actor (pull requests only) on the main-integrity -# ruleset, since the merge skips the code owner review. -# Run from the root of an sdk-go clone. GH_TOKEN comes from the environment. +# Provenance and merge rights come from repository rules, not from this +# script (see README.md, "Auto-merge for stable pins"): only the bump App and +# maintainers may write core/* branches, the required checks have no bypass, +# and only the merge App, whose token GH_TOKEN carries here, is a bypass actor +# (pull requests only) on main-integrity for the code owner review. +# Run from the root of an sdk-go clone. set -euo pipefail sdk_repo=${SDK_REPO:-ai-openshell/sdk-go} required_checks=("ci" "e2e / e2e" "DCO") -allowed_paths='^(buf\.gen\.yaml|README\.md)$' +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=hack/automation/pin-bump.sh +. "$here/pin-bump.sh" dry=0 mode=${CORE_AUTO_MERGE:-off} @@ -49,7 +56,8 @@ esac die() { echo "ERROR: $*" >&2; exit 1; } [ "$(git rev-parse --show-toplevel)" = "$(pwd -P)" ] || die "run this from the root of the sdk-go clone" -bot_email=$(git config user.email) || die "git user.email is not set; it names the bot identity" +bot_email=${BUMP_BOT_EMAIL:-} +[ -n "$bot_email" ] || die "BUMP_BOT_EMAIL is not set; it names the bot that commits the bumps" git fetch --quiet origin main @@ -78,14 +86,15 @@ while IFS=$'\t' read -r n head sha base draft cross held; do idents=$(git log -1 --format='%ae %ce' "$sha") [ "$idents" = "$bot_email $bot_email" ] || { skip "commit is not the bot's ($idents)"; continue; } - pin=$(git show "$sha:buf.gen.yaml" | yq -r '.inputs[0].tag') - [ "$pin" = "$tag" ] || { skip "pin is $pin, branch says $tag"; continue; } - extra=$(git diff --name-only "$mb" "$sha" | grep -Ev "$allowed_paths" || true) - if [ -n "$extra" ]; then - if grep -q '^proto/' <<<"$extra"; then - skip "the bindings change ($(grep -c '^proto/' <<<"$extra") files under proto/), so the new core API needs review" + # Compare whole trees rather than file names: an edit inside an allowed + # file (a Buf plugin entry in buf.gen.yaml, say) must not pass. + expected=$(pin_bump_tree "$mb" "$tag" stable) + if [ "$expected" != "$(git rev-parse "$sha^{tree}")" ]; then + diff=$(git diff --name-only "$expected" "$sha") + if grep -q '^proto/' <<<"$diff"; then + skip "the bindings change ($(grep -c '^proto/' <<<"$diff") files under proto/), so the new core API needs review" else - skip "touches files outside the pin bump: $(tr '\n' ' ' <<<"$extra")" + skip "differs from the pin bump to $tag in: $(tr '\n' ' ' <<<"$diff")" fi continue fi @@ -113,7 +122,7 @@ while IFS=$'\t' read -r n head sha base draft cross held; do fi gh pr comment "$n" -R "$sdk_repo" --body "$comment" # --match-head-commit refuses the merge if someone pushed since the checks. - # --admin uses the bot's ruleset bypass for the code owner review. + # --admin uses the merge App's ruleset bypass for the code owner review. gh pr merge "$n" -R "$sdk_repo" --squash --admin --match-head-commit "$sha" echo "#$n: merged ($tag)." done <<<"$prs" diff --git a/hack/automation/open-bump-pr.sh b/hack/automation/open-bump-pr.sh index 5096b1e..017c91e 100755 --- a/hack/automation/open-bump-pr.sh +++ b/hack/automation/open-bump-pr.sh @@ -104,9 +104,14 @@ cleanup() { git worktree remove --force "$work/wt" >/dev/null 2>&1 || true; rm - trap cleanup EXIT git worktree add --quiet -b "$branch" "$work/wt" "$base" +# shellcheck source=hack/automation/pin-bump.sh +. "$here/pin-bump.sh" + ( cd "$work/wt" - yq -i ".inputs[0].tag = \"$tag\"" buf.gen.yaml + # The pin and the README line; merge-bump-pr.sh rebuilds the same edits + # with pin_bump_tree to check that a proposal is a pin bump only. + pin_bump_edit "$tag" "$kind" mise run --quiet proto:gen >/dev/null # Refresh vendored fixtures; one not in the tag yet is left as is. @@ -127,13 +132,6 @@ git worktree add --quiet -b "$branch" "$work/wt" "$base" esac done - # Keep the README's "generated from OpenShell core vX.Y.Z" line in step - # with stable pins. Match any version: after a merged pre-release - # proposal, the line still names the last stable tag, not the old pin. - if [ "$kind" = stable ]; then - sed -E -i.bak "s/generated from OpenShell core v[0-9]+\.[0-9]+\.[0-9]+(-pre\.[0-9]+)?/generated from OpenShell core ${tag}/" README.md && rm -f README.md.bak - fi - git add -A git commit --quiet --signoff -m "chore(core): track $tag" -m "Move the core pin from $old to $tag and regenerate the bindings." ) diff --git a/hack/automation/pin-bump.sh b/hack/automation/pin-bump.sh new file mode 100644 index 0000000..33ad2b3 --- /dev/null +++ b/hack/automation/pin-bump.sh @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# shellcheck shell=bash + +# pin-bump.sh: the edits a core bump makes besides the regenerated bindings. +# Sourced, not run. open-bump-pr.sh applies them; merge-bump-pr.sh rebuilds +# them to check that a proposal is exactly a pin bump and nothing else. + +# pin_bump_edit : in the current directory, set the pin in +# buf.gen.yaml to and, for a stable , keep the README's +# "generated from OpenShell core vX.Y.Z" line in step. The README line may +# still name the last stable tag after a merged pre-release proposal, so any +# version matches. +pin_bump_edit() { + local tag=$1 kind=$2 + yq -i ".inputs[0].tag = \"$tag\"" buf.gen.yaml + if [ "$kind" = stable ]; then + sed -E -i.bak "s/generated from OpenShell core v[0-9]+\.[0-9]+\.[0-9]+(-pre\.[0-9]+)?/generated from OpenShell core ${tag}/" README.md + rm -f README.md.bak + fi +} + +# pin_bump_tree : print the tree a bump commit on +# must have when it changes nothing but the pin edits: 's tree with +# pin_bump_edit applied to buf.gen.yaml and README.md. No worktree, no +# checkout, no generated code; the blobs are written to the object store. +pin_bump_tree() ( + set -euo pipefail + base=$1 tag=$2 kind=$3 + tmp=$(mktemp -d) + trap 'rm -rf "$tmp"' EXIT + for f in buf.gen.yaml README.md; do + git show "$base:$f" >"$tmp/$f" + done + (cd "$tmp" && pin_bump_edit "$tag" "$kind") + # A private index, so the caller's index and worktree stay untouched. + export GIT_INDEX_FILE="$tmp/index" + git read-tree "$base" + for f in buf.gen.yaml README.md; do + mode=$(git ls-tree "$base" -- "$f" | cut -d' ' -f1) + blob=$(git hash-object -w "$tmp/$f") + git update-index --cacheinfo "$mode,$blob,$f" + done + git write-tree +) From 4cf71a783830057edabc1eb59197aceecf979de7 Mon Sep 17 00:00:00 2001 From: Simon Scatton Date: Thu, 26 Nov 2026 17:40:27 +0100 Subject: [PATCH 3/5] ci: verify core bump provenance before auto-merge Signed-off-by: Simon Scatton --- .github/workflows/ci.yml | 22 +++++++++++++++++++++- .github/workflows/core-watch.yml | 12 ++++-------- hack/automation/README.md | 10 ++++++---- hack/automation/bump-pr-body.md | 2 +- hack/automation/merge-bump-pr.sh | 28 +++++++++++++++------------- hack/automation/open-bump-pr.sh | 10 ++++++++++ 6 files changed, 57 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5177ebc..a4e46bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,8 @@ jobs: BASE_SHA: ${{ github.event.pull_request.base.sha }} run: | set -euo pipefail - if git diff --name-only "${BASE_SHA}...HEAD" | grep -qE '^(buf\.gen\.yaml$|go\.(mod|sum)$|mise\.toml$|proto/|openshell/|e2e/|hack/automation/(start|stop)-gateway\.sh$|\.github/workflows/e2e\.yml$)'; then + changed_paths=$(git diff --name-only "${BASE_SHA}...HEAD") + if grep -qE '^(buf\.gen\.yaml$|go\.(mod|sum)$|mise\.toml$|proto/|openshell/|e2e/|hack/automation/(start|stop)-gateway\.sh$|\.github/workflows/e2e\.yml$)' <<<"$changed_paths"; then echo "e2e=true" >>"$GITHUB_OUTPUT" else echo "e2e=false" >>"$GITHUB_OUTPUT" @@ -93,3 +94,22 @@ jobs: needs: changes if: needs.changes.outputs.e2e == 'true' uses: ./.github/workflows/e2e.yml + + e2e-gate: + name: e2e-gate + needs: [changes, e2e] + if: ${{ always() && github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check E2E result + env: + CHANGES_RESULT: ${{ needs.changes.result }} + E2E_REQUIRED: ${{ needs.changes.outputs.e2e }} + E2E_RESULT: ${{ needs.e2e.result }} + run: | + case "$CHANGES_RESULT:$E2E_REQUIRED:$E2E_RESULT" in + success:true:success | success:false:skipped) exit 0 ;; + esac + echo "E2E gate failed (changes=$CHANGES_RESULT, required=$E2E_REQUIRED, e2e=$E2E_RESULT)." >&2 + exit 1 diff --git a/.github/workflows/core-watch.yml b/.github/workflows/core-watch.yml index f17828f..ac762a0 100644 --- a/.github/workflows/core-watch.yml +++ b/.github/workflows/core-watch.yml @@ -36,8 +36,6 @@ jobs: environment: sdk-bot runs-on: ubuntu-latest timeout-minutes: 20 - outputs: - bot_email: ${{ steps.identity.outputs.email }} steps: - id: app-token uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 @@ -47,6 +45,7 @@ jobs: permission-contents: write permission-pull-requests: write permission-issues: write + permission-checks: ${{ vars.CORE_AUTO_MERGE == 'on' && 'write' || '' }} - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -62,7 +61,6 @@ jobs: run: mise install --locked - name: Set the bot identity - id: identity env: GH_TOKEN: ${{ steps.app-token.outputs.token }} APP_SLUG: ${{ steps.app-token.outputs.app-slug }} @@ -70,14 +68,13 @@ jobs: set -euo pipefail id=$(gh api "users/${APP_SLUG}[bot]" --jq .id) git config user.name "${APP_SLUG}[bot]" - email="${id}+${APP_SLUG}[bot]@users.noreply.github.com" - git config user.email "$email" - echo "email=$email" >>"$GITHUB_OUTPUT" + git config user.email "${id}+${APP_SLUG}[bot]@users.noreply.github.com" - name: Propose new core tags env: GH_TOKEN: ${{ steps.app-token.outputs.token }} INPUT_TAG: ${{ inputs.tag }} + CORE_AUTO_MERGE: ${{ vars.CORE_AUTO_MERGE }} run: | set -euo pipefail if [ -n "$INPUT_TAG" ]; then @@ -120,7 +117,7 @@ jobs: merge: name: merge needs: watch - if: ${{ !cancelled() && vars.CORE_AUTO_MERGE == 'on' && needs.watch.outputs.bot_email != '' }} + if: ${{ !cancelled() && vars.CORE_AUTO_MERGE == 'on' }} environment: sdk-bot runs-on: ubuntu-latest timeout-minutes: 10 @@ -152,7 +149,6 @@ jobs: env: GH_TOKEN: ${{ steps.app-token.outputs.token }} CORE_AUTO_MERGE: ${{ vars.CORE_AUTO_MERGE }} - BUMP_BOT_EMAIL: ${{ needs.watch.outputs.bot_email }} run: hack/automation/merge-bump-pr.sh - name: Report failure diff --git a/hack/automation/README.md b/hack/automation/README.md index bda5975..4a7daba 100644 --- a/hack/automation/README.md +++ b/hack/automation/README.md @@ -10,7 +10,7 @@ Workflows run them with a token of the `ai-openshell-sdk-go` GitHub App (`ai-ope | `open-bump-pr.sh [--dry-run]` | `core:bump` | Open the update proposal for one core tag: branch `core/`, pin change, regenerated bindings, proto diff in the body, labels `core-bump` plus `stable` or `prerelease`. Closes older pre-release proposals. | | `bump-pr-body.md` | | PR body template for `open-bump-pr.sh`. | | `core-registry.sh` | | Sourced by `start-gateway.sh` and `open-bump-pr.sh`: `core_registry ` prints the registry that holds a core release's images, `quay.io/ai-openshell` for releases since the move and `ghcr.io/nvidia/openshell` for older ones. | -| `merge-bump-pr.sh [--dry-run] [--auto-merge on\|off]` | `core:merge` | Merge stable proposals that change no proto: one commit by the bump bot (`BUMP_BOT_EMAIL`) whose tree is exactly the pin bump, green checks, no `hold` label. Off unless `CORE_AUTO_MERGE` is `on`. | +| `merge-bump-pr.sh [--dry-run] [--auto-merge on\|off]` | `core:merge` | Merge stable proposals that change no proto: one commit with a provenance check from the bump App, exactly the pin bump, green checks, no `hold` label. Off unless `CORE_AUTO_MERGE` is `on`. | | `pin-bump.sh` | | Sourced by `open-bump-pr.sh` and `merge-bump-pr.sh`: `pin_bump_edit ` makes the pin and README edits of a bump, `pin_bump_tree ` prints the tree a bump commit with only those edits has. | | `tag-release.sh [--dry-run]` | `release:tag` | After a stable pin lands on `main`: create the lockstep tag `vX.Y.Z` and the GitHub release, then ask the Go module proxy for the version. | | `drift-check.sh --out ` | `core:drift` | Compare core `main` against the pin: `buf breaking`, regenerate and build, uncovered RPCs. Writes the markdown report. | @@ -64,6 +64,7 @@ A release that changes the protos always waits for review; the SDK release may l The proposal must be exactly a pin bump. `pin_bump_tree` rebuilds the expected tree from the merge base with the same edits `open-bump-pr.sh` makes (the pin in `buf.gen.yaml` and the README line), and the bump commit's tree has to match it. Any other change sends the proposal to review, including one inside `buf.gen.yaml` such as a plugin entry, a changed conformance fixture, or a second commit. +When auto-merge is on, the bump App records a `core-bump/provenance` check on the stable commit it generated. The merge script verifies the App ID and the exact PR head SHA. A new head without that check goes through review, including proposals opened before auto-merge was enabled. The proposal also goes back to review when a check fails or someone adds the `hold` label. Merges happen on the hourly run after the checks turn green, so a stable SDK release follows the core release within about two hours. @@ -73,6 +74,7 @@ The script checks the proposal; who may write a `core/*` branch and who may skip Before an admin sets `CORE_AUTO_MERGE` to `on`: 1. A ruleset on `core/*` lets only the `ai-openshell-sdk-go` App and maintainers create, update, or delete those branches. -2. A ruleset on `main` requires `ci`, `e2e / e2e`, and `DCO` with no bypass actors. -3. The merge App is installed on this repository with contents and pull requests write, checks and statuses read, and issues write (for failure reports), and its secrets are in `sdk-bot`. -4. The merge App, and only the merge App, is a bypass actor on the `main-integrity` ruleset with mode "pull requests only", so its merge can skip the code owner review. +2. A ruleset on `main` requires the GitHub Actions `ci` and `e2e-gate` checks with no bypass actors, and the separate DCO rule stays in force. Auto-merge also requires an actual `e2e / e2e` pass on the proposal. +3. The bump App installation has checks write so `core-watch` can record provenance when auto-merge is enabled. +4. The merge App is installed on this repository with contents and pull requests write, checks and statuses read, and issues write (for failure reports), and its secrets are in `sdk-bot`. +5. The merge App is a PR-only bypass actor for `main-integrity` on this repository, so its merge can skip the code owner review. diff --git a/hack/automation/bump-pr-body.md b/hack/automation/bump-pr-body.md index e5af0c8..7064c61 100644 --- a/hack/automation/bump-pr-body.md +++ b/hack/automation/bump-pr-body.md @@ -14,4 +14,4 @@ Move the core pin from `{{OLD}}` to `{{NEW}}` ({{KIND}}). - CI and E2E must pass. If the SDK needs changes for this core version, push them to this branch. - Merging a stable pin tags the SDK release `{{NEW}}`. Pre-release pins are not tagged; a newer pre-release proposal replaces this one. -- When auto-merge is on (repository variable `CORE_AUTO_MERGE`), core-watch merges a stable proposal without review if it is still the single bot commit, changes nothing but the pin and the README line (so nothing under `proto/`), and its checks are green. Add the `hold` label to keep it for review. +- When auto-merge is on (repository variable `CORE_AUTO_MERGE`), core-watch merges a stable proposal without review if the bump App recorded provenance for its single commit, it changes nothing but the pin and the README line, and its checks are green. Add the `hold` label to keep it for review. diff --git a/hack/automation/merge-bump-pr.sh b/hack/automation/merge-bump-pr.sh index 50f5add..4037656 100755 --- a/hack/automation/merge-bump-pr.sh +++ b/hack/automation/merge-bump-pr.sh @@ -16,24 +16,22 @@ # not trusted. A proposal is merged only when all of these hold: # - open, not a draft, from branch core/vX.Y.Z of this repository into main # - no "hold" label (a maintainer's way to keep it for review) -# - exactly one commit since main, authored and committed by the bump -# bot (BUMP_BOT_EMAIL, the identity core-watch sets), so any other push -# sends it back to review +# - exactly one commit since main, with a successful provenance check from +# the bump App on that exact SHA # - the commit's tree is exactly the tree pin_bump_tree (pin-bump.sh) # rebuilds from the merge base: the pin in buf.gen.yaml set to the # branch's tag and the README line updated, nothing else. No file under # proto/ changed (the generated bindings are identical), no conformance # fixture changed, and no other edit to buf.gen.yaml, such as a plugin. # - the checks in required_checks passed and none failed or is pending -# Provenance and merge rights come from repository rules, not from this -# script (see README.md, "Auto-merge for stable pins"): only the bump App and -# maintainers may write core/* branches, the required checks have no bypass, -# and only the merge App, whose token GH_TOKEN carries here, is a bypass actor -# (pull requests only) on main-integrity for the code owner review. +# Repository rules limit writes to core/*, enforce required checks without +# bypass, and let the merge App bypass code owner review on pull requests. # Run from the root of an sdk-go clone. set -euo pipefail sdk_repo=${SDK_REPO:-ai-openshell/sdk-go} +bump_app_id=5613773 # ai-openshell-sdk-go GitHub App +provenance_check=core-bump/provenance required_checks=("ci" "e2e / e2e" "DCO") here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=hack/automation/pin-bump.sh @@ -56,8 +54,6 @@ esac die() { echo "ERROR: $*" >&2; exit 1; } [ "$(git rev-parse --show-toplevel)" = "$(pwd -P)" ] || die "run this from the root of the sdk-go clone" -bot_email=${BUMP_BOT_EMAIL:-} -[ -n "$bot_email" ] || die "BUMP_BOT_EMAIL is not set; it names the bot that commits the bumps" git fetch --quiet origin main @@ -83,8 +79,14 @@ while IFS=$'\t' read -r n head sha base draft cross held; do count=$(git rev-list --count "$mb..$sha") [ "$count" = 1 ] || { skip "$count commits, expected 1"; continue; } - idents=$(git log -1 --format='%ae %ce' "$sha") - [ "$idents" = "$bot_email $bot_email" ] || { skip "commit is not the bot's ($idents)"; continue; } + + if ! gh api --method GET "repos/$sdk_repo/commits/$sha/check-runs" \ + -f check_name="$provenance_check" -F app_id="$bump_app_id" | + jq -e --arg name "$provenance_check" --arg sha "$sha" --argjson app "$bump_app_id" \ + 'any(.check_runs[]; .name == $name and .app.id == $app and .head_sha == $sha and .conclusion == "success")' >/dev/null; then + skip "no successful bump App provenance for $sha" + continue + fi # Compare whole trees rather than file names: an edit inside an allowed # file (a Buf plugin entry in buf.gen.yaml, say) must not pass. @@ -112,7 +114,7 @@ while IFS=$'\t' read -r n head sha base draft cross held; do bad=$(jq -r '[.[] | select(.bucket != "pass" and .bucket != "skipping") | "\(.name) (\(.bucket))"] | join(", ")' <<<"$checks") [ -z "$bad" ] || { skip "checks not green: $bad"; continue; } - comment=$(printf 'Merged without review by core-watch: core `%s` changes no proto, so the generated bindings are identical; one bot commit, pin bump only, required checks green.\n\nMerging tags the SDK release `%s`.' \ + comment=$(printf 'Merged without review by core-watch: core `%s` changes no proto, the bump App vouched for the head SHA, and required checks passed.\n\nMerging tags the SDK release `%s`.' \ "$tag" "$tag") if [ "$dry" -eq 1 ]; then diff --git a/hack/automation/open-bump-pr.sh b/hack/automation/open-bump-pr.sh index 017c91e..151fc9e 100755 --- a/hack/automation/open-bump-pr.sh +++ b/hack/automation/open-bump-pr.sh @@ -196,6 +196,16 @@ url=$(gh pr create -R "$sdk_repo" --base main --head "$branch" \ echo "Opened $url" new=${url##*/} +if [ "${CORE_AUTO_MERGE:-off}" = on ] && [ "$kind" = stable ]; then + # Use the local branch we generated. The PR head may already have changed. + sha=$(git rev-parse "refs/heads/$branch") + if ! gh api --method POST "repos/$sdk_repo/check-runs" --silent \ + -f name=core-bump/provenance -f head_sha="$sha" \ + -f status=completed -f conclusion=success; then + echo "WARNING: could not record bump provenance for $sha; $url needs review." >&2 + fi +fi + # Close open pre-release proposals for older tags; this one supersedes them. gh pr list -R "$sdk_repo" --label core-bump --label prerelease --state open \ --json number,headRefName --jq '.[] | "\(.number) \(.headRefName)"' | From c4f0c00cde740121519714b429988b527f6abd67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Fri, 27 Nov 2026 14:53:25 +0100 Subject: [PATCH 4/5] fix(automation): merge stable bumps only on the current pin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When two stable proposals were open from the same base, the second one still passed every check after the first merged, failed with a conflict on the pin line, and set -e ended the run. It failed the same way every hour, and the 'Merged without review' comment was already posted before the refused merge. Nothing checked that the tag was newer than the pin either, so a dispatched older tag could land a downgrade unreviewed. merge-bump-pr.sh now fetches main for each proposal and leaves it for review unless main still pins the tag the proposal was cut from and the proposal's tag is newer. It merges first and comments only after the merge succeeded. A refused merge leaves that proposal for review, the run goes on with the others, and the script exits non-zero at the end so the failure is reported. older moves to pin-bump.sh so both scripts share it. Signed-off-by: Roland Huß --- hack/automation/README.md | 2 ++ hack/automation/merge-bump-pr.sh | 30 +++++++++++++++++++++++++----- hack/automation/open-bump-pr.sh | 11 ----------- hack/automation/pin-bump.sh | 12 ++++++++++++ 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/hack/automation/README.md b/hack/automation/README.md index 4a7daba..739e1bf 100644 --- a/hack/automation/README.md +++ b/hack/automation/README.md @@ -66,6 +66,8 @@ The proposal must be exactly a pin bump. Any other change sends the proposal to review, including one inside `buf.gen.yaml` such as a plugin entry, a changed conformance fixture, or a second commit. When auto-merge is on, the bump App records a `core-bump/provenance` check on the stable commit it generated. The merge script verifies the App ID and the exact PR head SHA. A new head without that check goes through review, including proposals opened before auto-merge was enabled. The proposal also goes back to review when a check fails or someone adds the `hold` label. +It waits for review, too, when its tag is not newer than the pin on `main`, or when `main` moved the pin since the proposal was cut (after an earlier proposal merged, a second one from the same base would only conflict). +If GitHub refuses a merge, the script leaves that proposal for review, goes on with the others, and fails the run so the failure is reported; the comment explaining an unreviewed merge is posted only after the merge succeeds. Merges happen on the hourly run after the checks turn green, so a stable SDK release follows the core release within about two hours. The merge runs in its own core-watch job, `merge`, with the token of a second GitHub App that only merges (secrets `SDK_MERGE_CLIENT_ID` and `SDK_MERGE_PRIVATE_KEY` in `sdk-bot`). diff --git a/hack/automation/merge-bump-pr.sh b/hack/automation/merge-bump-pr.sh index 4037656..f606872 100755 --- a/hack/automation/merge-bump-pr.sh +++ b/hack/automation/merge-bump-pr.sh @@ -16,6 +16,9 @@ # not trusted. A proposal is merged only when all of these hold: # - open, not a draft, from branch core/vX.Y.Z of this repository into main # - no "hold" label (a maintainer's way to keep it for review) +# - main still pins the tag the proposal was cut from, and the branch's tag +# is newer: after one proposal merges, an older one sharing its base +# would only conflict, and a downgrade always waits for review # - exactly one commit since main, with a successful provenance check from # the bump App on that exact SHA # - the commit's tree is exactly the tree pin_bump_tree (pin-bump.sh) @@ -24,6 +27,8 @@ # proto/ changed (the generated bindings are identical), no conformance # fixture changed, and no other edit to buf.gen.yaml, such as a plugin. # - the checks in required_checks passed and none failed or is pending +# A refused merge leaves that proposal for review and the run goes on with +# the others; the script exits non-zero at the end so the failure is reported. # Repository rules limit writes to core/*, enforce required checks without # bypass, and let the merge App bypass code owner review on pull requests. # Run from the root of an sdk-go clone. @@ -55,14 +60,13 @@ esac die() { echo "ERROR: $*" >&2; exit 1; } [ "$(git rev-parse --show-toplevel)" = "$(pwd -P)" ] || die "run this from the root of the sdk-go clone" -git fetch --quiet origin main - prs=$(gh pr list -R "$sdk_repo" --label core-bump --label stable --state open \ --json number,headRefName,headRefOid,baseRefName,isDraft,isCrossRepository,labels \ --jq '.[] | [.number, .headRefName, .headRefOid, .baseRefName, .isDraft, .isCrossRepository, ([.labels[].name] | index("hold") != null)] | @tsv') [ -n "$prs" ] || { echo "No open stable core-bump proposals."; exit 0; } +failed=0 while IFS=$'\t' read -r n head sha base draft cross held; do skip() { echo "#$n: $*; leaving it for review."; } tag=${head#core/} @@ -73,10 +77,18 @@ while IFS=$'\t' read -r n head sha base draft cross held; do [ "$held" = false ] || { skip "labeled hold"; continue; } [[ "$head" =~ ^core/v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { skip "branch $head is not core/vX.Y.Z"; continue; } - git fetch --quiet origin "+refs/heads/$head:refs/remotes/origin/$head" + # Fetch main for each proposal: an earlier one in this run may have moved + # the pin. + git fetch --quiet origin "+refs/heads/main:refs/remotes/origin/main" \ + "+refs/heads/$head:refs/remotes/origin/$head" [ "$(git rev-parse "origin/$head")" = "$sha" ] || { skip "head moved during the run"; continue; } mb=$(git merge-base origin/main "$sha") + main_pin=$(git show origin/main:buf.gen.yaml | yq -r '.inputs[0].tag') + mb_pin=$(git show "$mb:buf.gen.yaml" | yq -r '.inputs[0].tag') + [ "$main_pin" = "$mb_pin" ] || { skip "main moved the pin to $main_pin since this proposal was cut"; continue; } + older "$main_pin" "$tag" || { skip "$tag is not newer than the pin $main_pin on main"; continue; } + count=$(git rev-list --count "$mb..$sha") [ "$count" = 1 ] || { skip "$count commits, expected 1"; continue; } @@ -122,9 +134,17 @@ while IFS=$'\t' read -r n head sha base draft cross held; do sed 's/^/ | /' <<<"$comment" continue fi - gh pr comment "$n" -R "$sdk_repo" --body "$comment" # --match-head-commit refuses the merge if someone pushed since the checks. # --admin uses the merge App's ruleset bypass for the code owner review. - gh pr merge "$n" -R "$sdk_repo" --squash --admin --match-head-commit "$sha" + # Comment only after the merge, so a refused merge leaves no false claim. + if ! gh pr merge "$n" -R "$sdk_repo" --squash --admin --match-head-commit "$sha"; then + echo "ERROR: #$n: merging $tag failed; leaving it for review." >&2 + failed=1 + continue + fi echo "#$n: merged ($tag)." + gh pr comment "$n" -R "$sdk_repo" --body "$comment" || + echo "WARNING: #$n merged, but the comment explaining why failed." >&2 done <<<"$prs" + +exit "$failed" diff --git a/hack/automation/open-bump-pr.sh b/hack/automation/open-bump-pr.sh index 151fc9e..990267c 100755 --- a/hack/automation/open-bump-pr.sh +++ b/hack/automation/open-bump-pr.sh @@ -46,17 +46,6 @@ case $tag in *-pre.*) kind=prerelease ;; *) kind=stable ;; esac die() { echo "ERROR: $*" >&2; exit 1; } -# older : true when release tag a sorts below b (vX.Y.Z-pre.N < vX.Y.Z). -older() { - awk -v a="$1" -v b="$2" ' - function key(t, s, pre, rank, v) { - s = t; sub(/^v/, "", s); pre = 0; rank = 1 - if (index(s, "-pre.")) { pre = substr(s, index(s, "-pre.") + 5) + 0; s = substr(s, 1, index(s, "-pre.") - 1); rank = 0 } - split(s, v, ".") - return sprintf("%06d%06d%06d%d%06d", v[1], v[2], v[3], rank, pre) - } - BEGIN { exit !(key(a) < key(b)) }' -} run() { if [ "$dry" -eq 1 ]; then echo "dry-run: $*"; else "$@"; fi; } [ "$(git rev-parse --show-toplevel)" = "$(pwd -P)" ] || die "run this from the root of the sdk-go clone" diff --git a/hack/automation/pin-bump.sh b/hack/automation/pin-bump.sh index 33ad2b3..eb0b4b4 100644 --- a/hack/automation/pin-bump.sh +++ b/hack/automation/pin-bump.sh @@ -6,6 +6,18 @@ # Sourced, not run. open-bump-pr.sh applies them; merge-bump-pr.sh rebuilds # them to check that a proposal is exactly a pin bump and nothing else. +# older : true when release tag a sorts below b (vX.Y.Z-pre.N < vX.Y.Z). +older() { + awk -v a="$1" -v b="$2" ' + function key(t, s, pre, rank, v) { + s = t; sub(/^v/, "", s); pre = 0; rank = 1 + if (index(s, "-pre.")) { pre = substr(s, index(s, "-pre.") + 5) + 0; s = substr(s, 1, index(s, "-pre.") - 1); rank = 0 } + split(s, v, ".") + return sprintf("%06d%06d%06d%d%06d", v[1], v[2], v[3], rank, pre) + } + BEGIN { exit !(key(a) < key(b)) }' +} + # pin_bump_edit : in the current directory, set the pin in # buf.gen.yaml to and, for a stable , keep the README's # "generated from OpenShell core vX.Y.Z" line in step. The README line may From 59159cf2df7b907231952b93d727cb2428da610f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Fri, 27 Nov 2026 14:53:30 +0100 Subject: [PATCH 5/5] test(automation): cover the stable pin auto-merge offline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit merge-bump-pr-test.sh checks pin_bump_tree and older in a scratch Git repository and runs merge-bump-pr.sh against scratch repositories with a gh stub that serves PR lists, check runs and checks from files and squash-merges into a local bare origin. The cases cover two proposals from the same base, a refused merge, a downgrade, provenance from another App, a failed run or another SHA, a plugin or proto change, missing, skipped, pending and failed checks, and the hold, draft, fork and pre-release filters. workflows:check runs it in CI. The rollout list gains a dry run against the real proposals before an admin turns auto-merge on. Signed-off-by: Roland Huß --- hack/automation/README.md | 4 +- hack/automation/merge-bump-pr-test.sh | 219 +++++++++++++++++++++ hack/automation/testdata/merge-bump/bin/gh | 70 +++++++ mise.toml | 4 +- 4 files changed, 295 insertions(+), 2 deletions(-) create mode 100755 hack/automation/merge-bump-pr-test.sh create mode 100755 hack/automation/testdata/merge-bump/bin/gh diff --git a/hack/automation/README.md b/hack/automation/README.md index 739e1bf..969857c 100644 --- a/hack/automation/README.md +++ b/hack/automation/README.md @@ -11,7 +11,8 @@ Workflows run them with a token of the `ai-openshell-sdk-go` GitHub App (`ai-ope | `bump-pr-body.md` | | PR body template for `open-bump-pr.sh`. | | `core-registry.sh` | | Sourced by `start-gateway.sh` and `open-bump-pr.sh`: `core_registry ` prints the registry that holds a core release's images, `quay.io/ai-openshell` for releases since the move and `ghcr.io/nvidia/openshell` for older ones. | | `merge-bump-pr.sh [--dry-run] [--auto-merge on\|off]` | `core:merge` | Merge stable proposals that change no proto: one commit with a provenance check from the bump App, exactly the pin bump, green checks, no `hold` label. Off unless `CORE_AUTO_MERGE` is `on`. | -| `pin-bump.sh` | | Sourced by `open-bump-pr.sh` and `merge-bump-pr.sh`: `pin_bump_edit ` makes the pin and README edits of a bump, `pin_bump_tree ` prints the tree a bump commit with only those edits has. | +| `pin-bump.sh` | | Sourced by `open-bump-pr.sh` and `merge-bump-pr.sh`: `pin_bump_edit ` makes the pin and README edits of a bump, `pin_bump_tree ` prints the tree a bump commit with only those edits has, `older ` compares release tags. | +| `merge-bump-pr-test.sh` | | Offline tests for `pin-bump.sh` and `merge-bump-pr.sh` in scratch Git repositories, with the gh stub in `testdata/merge-bump/bin/`; part of `workflows:check`. | | `tag-release.sh [--dry-run]` | `release:tag` | After a stable pin lands on `main`: create the lockstep tag `vX.Y.Z` and the GitHub release, then ask the Go module proxy for the version. | | `drift-check.sh --out ` | `core:drift` | Compare core `main` against the pin: `buf breaking`, regenerate and build, uncovered RPCs. Writes the markdown report. | | `update-drift-issue.sh ` | | Create, update, or close the single `Core main drift` issue from a report; uncovered RPCs link to their open RPC coverage issues. | @@ -80,3 +81,4 @@ Before an admin sets `CORE_AUTO_MERGE` to `on`: 3. The bump App installation has checks write so `core-watch` can record provenance when auto-merge is enabled. 4. The merge App is installed on this repository with contents and pull requests write, checks and statuses read, and issues write (for failure reports), and its secrets are in `sdk-bot`. 5. The merge App is a PR-only bypass actor for `main-integrity` on this repository, so its merge can skip the code owner review. +6. `mise run core:merge -- --dry-run --auto-merge on` with the merge App's token lists the open stable proposals it would merge, and each skip reason matches what you expect. diff --git a/hack/automation/merge-bump-pr-test.sh b/hack/automation/merge-bump-pr-test.sh new file mode 100755 index 0000000..67cbf6e --- /dev/null +++ b/hack/automation/merge-bump-pr-test.sh @@ -0,0 +1,219 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# merge-bump-pr-test.sh: offline tests for the stable pin auto-merge. +# +# Usage: merge-bump-pr-test.sh +# +# Run from the root of an sdk-go clone. Checks pin_bump_tree and older +# (pin-bump.sh) in a scratch Git repository, then runs merge-bump-pr.sh +# against scratch repositories with a gh stub (testdata/merge-bump/bin/gh) +# that serves PR lists, check runs and checks from files and squash-merges +# into a local bare origin. Exits 1 on any failed case. +set -euo pipefail + +here=$(pwd -P)/hack/automation +stub_bin=$here/testdata/merge-bump/bin +# shellcheck source=hack/automation/pin-bump.sh +. "$here/pin-bump.sh" + +die() { echo "ERROR: $*" >&2; exit 1; } +[ "$(git rev-parse --show-toplevel)" = "$(pwd -P)" ] || die "run this from the root of the sdk-go clone" + +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +failed=0 +fail() { echo "FAIL $1"; failed=1; } +pass() { echo "ok $1"; } + +export GIT_AUTHOR_NAME=test GIT_AUTHOR_EMAIL=test@example.com +export GIT_COMMITTER_NAME=test GIT_COMMITTER_EMAIL=test@example.com +export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 + +# new_case : a bare origin whose main pins core v0.1.10, and a clone +# of it in $repo. Sets $case_dir, $repo and $state (the gh stub's state). +new_case() { + case_dir=$work/$1 + state=$case_dir/state + repo=$case_dir/repo + mkdir -p "$state" "$repo" + git init --quiet --bare -b main "$state/origin.git" + git -C "$repo" init --quiet -b main + git -C "$repo" remote add origin "$state/origin.git" + cat >"$repo/buf.gen.yaml" <<'EOF' +version: v2 +plugins: + - remote: buf.build/protocolbuffers/go + out: proto +inputs: + - git_repo: https://github.com/ai-openshell/core + tag: v0.1.10 +EOF + printf '# SDK\n\nThe bindings are generated from OpenShell core v0.1.10.\n' >"$repo/README.md" + mkdir -p "$repo/proto" + echo "package proto" >"$repo/proto/api.pb.go" + git -C "$repo" add -A + git -C "$repo" commit --quiet -m init + git -C "$repo" push --quiet origin main + echo '[]' >"$state/prs.json" + echo '[{"name":"ci","bucket":"pass"},{"name":"e2e / e2e","bucket":"pass"},{"name":"DCO","bucket":"pass"}]' >"$state/checks.json" + : >"$state/events" +} + +# propose [...]: commit a pin bump to on +# core/ from origin/main, run the optional extra edit in the clone +# before committing, push it, and list it as PR (labels: $labels, +# draft: $draft, fork: $fork). Sets $sha. +propose() { + local n=$1 tag=$2 kind=stable + shift 2 + case $tag in *-pre.*) kind=prerelease ;; esac + git -C "$repo" checkout --quiet -B "core/$tag" origin/main + (cd "$repo" && pin_bump_edit "$tag" "$kind" && if [ $# -gt 0 ]; then "$@"; fi) + git -C "$repo" commit --quiet -am "chore(core): track $tag" + git -C "$repo" push --quiet origin "core/$tag" + sha=$(git -C "$repo" rev-parse HEAD) + git -C "$repo" checkout --quiet --detach origin/main + jq --argjson n "$n" --arg head "core/$tag" --arg sha "$sha" \ + --argjson draft "${draft:-false}" --argjson fork "${fork:-false}" --arg labels "${labels:-core-bump,stable}" \ + '. + [{number: $n, headRefName: $head, headRefOid: $sha, baseRefName: "main", + isDraft: $draft, isCrossRepository: $fork, + labels: ($labels | split(",") | map({name: .}))}]' \ + "$state/prs.json" >"$state/prs.tmp" + mv "$state/prs.tmp" "$state/prs.json" +} + +# run_merge: run merge-bump-pr.sh in the clone; output in $out, status in $rc. +run_merge() { + rc=0 + out=$(cd "$repo" && PATH="$stub_bin:$PATH" GH_STUB_STATE="$state" \ + "$here/merge-bump-pr.sh" --auto-merge on 2>&1) || rc=$? +} + +main_pin() { git -C "$state/origin.git" show main:buf.gen.yaml | yq -r '.inputs[0].tag'; } +events() { paste -sd, "$state/events"; } + +# expect +expect() { + local name=$1 what=$2 + shift 2 + if "$@"; then pass "$name: $what"; else + fail "$name: $what" + printf ' output:\n%s\n events: %s\n' "$(sed 's/^/ /' <<<"$out")" "$(events)" + fi +} +says() { grep -qF -- "$1" <<<"$out"; } + +# --- older --------------------------------------------------------------- +for pair in "v0.1.9 v0.1.10" "v0.1.10-pre.2 v0.1.10" "v0.1.10-pre.2 v0.1.10-pre.10" "v0.9.0 v1.0.0"; do + # shellcheck disable=SC2086 # two words on purpose + if older $pair; then pass "older $pair"; else fail "older $pair"; fi +done +for pair in "v0.1.10 v0.1.10" "v0.1.10 v0.1.9" "v0.1.10 v0.1.10-pre.2"; do + # shellcheck disable=SC2086 + if older $pair; then fail "not older $pair"; else pass "not older $pair"; fi +done + +# --- pin_bump_tree ------------------------------------------------------- +new_case tree +base=$(git -C "$repo" rev-parse HEAD) +propose 1 v0.1.11 +expect tree "stable bump commit matches the rebuilt tree" \ + test "$(cd "$repo" && pin_bump_tree "$base" v0.1.11 stable)" = "$(git -C "$repo" rev-parse "$sha^{tree}")" +expect tree "the caller's index and worktree stay clean" \ + test -z "$(git -C "$repo" status --porcelain)" +propose 2 v0.1.12 yq -i '.plugins += [{"local": "protoc-gen-evil", "out": "proto"}]' buf.gen.yaml +expect tree "an extra Buf plugin does not match" \ + test "$(cd "$repo" && pin_bump_tree "$base" v0.1.12 stable)" != "$(git -C "$repo" rev-parse "$sha^{tree}")" +propose 3 v0.1.13 sh -c 'echo "// changed" >>proto/api.pb.go' +expect tree "a change under proto/ does not match" \ + test "$(cd "$repo" && pin_bump_tree "$base" v0.1.13 stable)" != "$(git -C "$repo" rev-parse "$sha^{tree}")" +pre_tree=$(cd "$repo" && pin_bump_tree "$base" v0.1.11-pre.1 prerelease) +expect tree "a pre-release bump leaves README.md unchanged" \ + test "$(git -C "$repo" rev-parse "$pre_tree:README.md")" = "$(git -C "$repo" rev-parse "$base:README.md")" +expect tree "a pre-release bump sets the pin" \ + test "$(git -C "$repo" show "$pre_tree:buf.gen.yaml" | yq -r '.inputs[0].tag')" = v0.1.11-pre.1 + +# --- merge-bump-pr.sh ---------------------------------------------------- +# gh pr list returns the newest proposal first. +new_case two-proposals +propose 2 v0.1.12 +propose 1 v0.1.11 +run_merge +expect two-proposals "exits 0" test "$rc" = 0 +expect two-proposals "merges the newest, then comments" test "$(events)" = "merge #2,comment #2" +expect two-proposals "main pins v0.1.12" test "$(main_pin)" = v0.1.12 +expect two-proposals "leaves the older proposal for review" says "#1: main moved the pin to v0.1.12 since this proposal was cut" +run_merge +expect two-proposals "a second run leaves main alone" test "$(events)" = "merge #2,comment #2" + +new_case refused +propose 2 v0.1.12 +propose 1 v0.1.11 +touch "$state/refuse-2" +run_merge +expect refused "exits 1" test "$rc" = 1 +expect refused "posts no comment on the refused proposal" test "$(events)" = "merge #1,comment #1" +expect refused "reports the refused merge" says "ERROR: #2: merging v0.1.12 failed; leaving it for review." +expect refused "goes on and merges the next proposal" test "$(main_pin)" = v0.1.11 + +new_case downgrade +propose 1 v0.1.9 +run_merge +expect downgrade "does not merge an older tag" test "$(events)" = "" +expect downgrade "says why" says "#1: v0.1.9 is not newer than the pin v0.1.10 on main" + +new_case provenance +propose 1 v0.1.11 +jq -n --arg sha "$sha" '{check_runs: [{name: "core-bump/provenance", app: {id: 42}, head_sha: $sha, conclusion: "success"}]}' >"$state/runs-$sha.json" +propose 2 v0.1.12 +jq -n --arg sha "$sha" '{check_runs: [{name: "core-bump/provenance", app: {id: 5613773}, head_sha: $sha, conclusion: "failure"}]}' >"$state/runs-$sha.json" +propose 3 v0.1.13 +jq -n '{check_runs: [{name: "core-bump/provenance", app: {id: 5613773}, head_sha: "0000000000000000000000000000000000000000", conclusion: "success"}]}' >"$state/runs-$sha.json" +propose 4 v0.1.14 +echo '{"check_runs": []}' >"$state/runs-$sha.json" +run_merge +expect provenance "merges nothing" test "$(events)" = "" +for n in 1 2 3 4; do + expect provenance "#$n skipped for provenance" says "#$n: no successful bump App provenance" +done + +new_case tree-mismatch +propose 1 v0.1.11 yq -i '.plugins += [{"local": "protoc-gen-evil", "out": "proto"}]' buf.gen.yaml +propose 2 v0.1.12 sh -c 'echo "// changed" >>proto/api.pb.go' +run_merge +expect tree-mismatch "merges nothing" test "$(events)" = "" +expect tree-mismatch "a plugin edit goes to review" says "#1: differs from the pin bump to v0.1.11 in: buf.gen.yaml" +expect tree-mismatch "a proto change goes to review" says "#2: the bindings change (1 files under proto/)" + +new_case checks +propose 1 v0.1.11 +echo '[{"name":"ci","bucket":"pass"},{"name":"e2e / e2e","bucket":"pass"}]' >"$state/checks-1.json" +propose 2 v0.1.12 +echo '[{"name":"ci","bucket":"pass"},{"name":"e2e / e2e","bucket":"skipping"},{"name":"DCO","bucket":"pass"}]' >"$state/checks-2.json" +propose 3 v0.1.13 +echo '[{"name":"ci","bucket":"pass"},{"name":"e2e / e2e","bucket":"pass"},{"name":"DCO","bucket":"pass"},{"name":"lint","bucket":"pending"}]' >"$state/checks-3.json" +propose 4 v0.1.14 +echo '[{"name":"ci","bucket":"pass"},{"name":"ci","bucket":"fail"},{"name":"e2e / e2e","bucket":"pass"},{"name":"DCO","bucket":"pass"}]' >"$state/checks-4.json" +run_merge +expect checks "merges nothing" test "$(events)" = "" +expect checks "a missing required check blocks" says "#1: required checks not passed: 'DCO'" +expect checks "a skipped required check blocks" says "#2: required checks not passed: 'e2e / e2e'" +expect checks "a pending check blocks" says "#3: checks not green: lint (pending)" +expect checks "a failed run of a required check blocks" says "#4: checks not green: ci (fail)" + +new_case filters +labels=core-bump,stable,hold propose 1 v0.1.11 +draft=true propose 2 v0.1.12 +fork=true propose 3 v0.1.13 +propose 4 v0.1.14-pre.1 +run_merge +expect filters "merges nothing" test "$(events)" = "" +expect filters "hold" says "#1: labeled hold" +expect filters "draft" says "#2: draft" +expect filters "fork" says "#3: head is in a fork" +expect filters "pre-release branch" says "#4: branch core/v0.1.14-pre.1 is not core/vX.Y.Z" + +[ "$failed" -eq 0 ] || { echo "merge-bump-pr-test: FAILED" >&2; exit 1; } +echo "merge-bump-pr-test: all cases passed." diff --git a/hack/automation/testdata/merge-bump/bin/gh b/hack/automation/testdata/merge-bump/bin/gh new file mode 100755 index 0000000..de9a7b8 --- /dev/null +++ b/hack/automation/testdata/merge-bump/bin/gh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# gh stub for merge-bump-pr-test.sh. Answers the calls merge-bump-pr.sh +# makes from the files in $GH_STUB_STATE: +# prs.json what `gh pr list --json ...` returns (before --jq) +# runs-.json check runs for ; default: one successful +# core-bump/provenance run from the bump App +# checks-.json `gh pr checks --json name,bucket`; default checks.json +# refuse- `gh pr merge ` fails +# origin.git bare repository a merge squashes the PR branch into +# Merges and comments are appended to $GH_STUB_STATE/events, in order. +set -euo pipefail + +state=${GH_STUB_STATE:?GH_STUB_STATE is not set} +jq_expr= +args=() +while [ $# -gt 0 ]; do + case $1 in + --jq) jq_expr=$2; shift 2 ;; + *) args+=("$1"); shift ;; + esac +done +set -- "${args[@]}" + +case "$1 $2" in +"pr list") + if [ -n "$jq_expr" ]; then jq -r "$jq_expr" "$state/prs.json"; else cat "$state/prs.json"; fi + ;; +"api --method") + path=$4 sha=${4#*/commits/} + sha=${sha%/check-runs} + [ "$path" != "$sha" ] || { echo "gh stub: unexpected api path $path" >&2; exit 2; } + if [ -f "$state/runs-$sha.json" ]; then + cat "$state/runs-$sha.json" + else + jq -n --arg sha "$sha" \ + '{check_runs: [{name: "core-bump/provenance", app: {id: 5613773}, head_sha: $sha, conclusion: "success"}]}' + fi + ;; +"pr checks") + f="$state/checks-$3.json" + [ -f "$f" ] || f="$state/checks.json" + cat "$f" + ;; +"pr comment") + echo "comment #$3" >>"$state/events" + ;; +"pr merge") + n=$3 + [ ! -f "$state/refuse-$n" ] || { echo "gh stub: merge of #$n refused" >&2; exit 1; } + branch=$(jq -r --argjson n "$n" '.[] | select(.number == $n) | .headRefName' "$state/prs.json") + tmp=$(mktemp -d) + trap 'rm -rf "$tmp"' EXIT + git clone --quiet "$state/origin.git" "$tmp/m" + cd "$tmp/m" + if ! git merge --quiet --squash "origin/$branch" >/dev/null 2>&1; then + echo "gh stub: #$n is not mergeable (conflict)" >&2 + exit 1 + fi + git -c user.name=stub -c user.email=stub@example.com commit --quiet -m "Merge #$n" + git push --quiet origin HEAD:main + echo "merge #$n" >>"$state/events" + ;; +*) + echo "gh stub: unexpected call: gh $*" >&2 + exit 2 + ;; +esac diff --git a/mise.toml b/mise.toml index 0d91f30..437ae2e 100644 --- a/mise.toml +++ b/mise.toml @@ -227,12 +227,14 @@ echo "Proto check passed: generated files match core $(yq -r '.inputs[0].tag' bu """ [tasks."workflows:check"] -description = "Lint GitHub workflows (actionlint with shellcheck, zizmor) and the hack/ scripts (shellcheck), run the RPC coverage issue tests" +description = "Lint GitHub workflows (actionlint with shellcheck, zizmor) and the hack/ scripts (shellcheck), run the RPC coverage issue and core auto-merge tests" run = [ "actionlint", "zizmor --offline --min-severity medium .github", "shellcheck -x -S warning hack/automation/*.sh hack/migration/*.sh", + "shellcheck -x -S warning hack/automation/testdata/merge-bump/bin/gh", "hack/automation/rpc-issues-test.sh", + "hack/automation/merge-bump-pr-test.sh", ] [tasks."docs:build"]