From 994ea9055cea172e12a90b458d17ae2c1029d84d Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 24 Nov 2026 02:28:09 -0500 Subject: [PATCH 1/4] ci: tag the patched image with CalVer versions so Renovate can track it Signed-off-by: Yordis Prieto --- .config/mise/lib/calver.sh | 16 ++++ .config/mise/lib/ghcr.sh | 18 ++++ .config/mise/lib/git.sh | 12 +++ .config/mise/lib/image.sh | 5 ++ .../workflows/trogonstack-image/image-name | 5 ++ .../workflows/trogonstack-image/summary | 4 + .../trogonstack-release/add-calver-tag | 42 +++++++++ .../trogonstack-release/registry-login | 4 + .../trogonstack-release/resolve-commit | 5 ++ .github/actions/setup-mise/action.yml | 24 ++++++ .github/workflows/trogonstack-image.yml | 86 +++++++++++++++++-- .github/workflows/trogonstack-release.yml | 60 +++++++++++++ mise.toml | 4 + 13 files changed, 277 insertions(+), 8 deletions(-) create mode 100644 .config/mise/lib/calver.sh create mode 100644 .config/mise/lib/ghcr.sh create mode 100644 .config/mise/lib/git.sh create mode 100644 .config/mise/lib/image.sh create mode 100755 .config/mise/tasks/github/workflows/trogonstack-image/image-name create mode 100755 .config/mise/tasks/github/workflows/trogonstack-image/summary create mode 100755 .config/mise/tasks/github/workflows/trogonstack-release/add-calver-tag create mode 100755 .config/mise/tasks/github/workflows/trogonstack-release/registry-login create mode 100755 .config/mise/tasks/github/workflows/trogonstack-release/resolve-commit create mode 100644 .github/actions/setup-mise/action.yml create mode 100644 .github/workflows/trogonstack-release.yml create mode 100644 mise.toml diff --git a/.config/mise/lib/calver.sh b/.config/mise/lib/calver.sh new file mode 100644 index 0000000000..1d4aeecad9 --- /dev/null +++ b/.config/mise/lib/calver.sh @@ -0,0 +1,16 @@ +# shellcheck shell=bash +# decide reads " " lines of the +# existing version tags on stdin. It prints "released " when a +# tag already points at , otherwise "next ". +decide() { + local digest="$1" today="$2" tag tagdigest n=0 + while read -r tag tagdigest; do + [ -n "$tag" ] || continue + if [ "$tagdigest" = "$digest" ]; then + echo "released $tag" + return 0 + fi + case "$tag" in "$today".*) n=$((n + 1)) ;; esac + done + echo "next $today.$n" +} diff --git a/.config/mise/lib/ghcr.sh b/.config/mise/lib/ghcr.sh new file mode 100644 index 0000000000..f414c3135e --- /dev/null +++ b/.config/mise/lib/ghcr.sh @@ -0,0 +1,18 @@ +# shellcheck shell=bash +# ghcr_manifest_status prints the HTTP status of +# the manifest. The registry's anonymous token endpoint is not enough for a +# private package, so the bearer token is requested with the given credentials. +ghcr_manifest_status() { + local image="$1" tag="$2" actor="$3" token="$4" bearer + # Command substitution does not inherit errexit, so fail the token request + # here instead of sending an empty bearer and reporting a misleading 401. + bearer="$(curl -fsS -u "$actor:$token" \ + "https://ghcr.io/token?service=ghcr.io&scope=repository:${image#ghcr.io/}:pull" | jq -er .token)" || { + echo "ghcr.io token request failed for $image" >&2 + return 1 + } + curl -sS -o /dev/null -w '%{http_code}' \ + -H "Authorization: Bearer $bearer" \ + -H 'Accept: application/vnd.oci.image.index.v1+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json' \ + "https://ghcr.io/v2/${image#ghcr.io/}/manifests/$tag" +} diff --git a/.config/mise/lib/git.sh b/.config/mise/lib/git.sh new file mode 100644 index 0000000000..0656c61806 --- /dev/null +++ b/.config/mise/lib/git.sh @@ -0,0 +1,12 @@ +# shellcheck shell=bash +# git_push_as pushes with the given token instead of +# the job's GITHUB_TOKEN. The token is read from the environment by the +# credential helper, so it never appears on a command line. actions/checkout +# sends GITHUB_TOKEN as an extra header, which would win over the helper, so +# that header is reset for this push. +# shellcheck disable=SC2016 # expanded by the credential helper, not here +git_push_as() { + PUSH_TOKEN="$1" git -c http.https://github.com/.extraheader= -c credential.helper= \ + -c 'credential.helper=!f() { echo username=x-access-token; echo "password=${PUSH_TOKEN}"; }; f' \ + push "${@:2}" +} diff --git a/.config/mise/lib/image.sh b/.config/mise/lib/image.sh new file mode 100644 index 0000000000..a905523fe6 --- /dev/null +++ b/.config/mise/lib/image.sh @@ -0,0 +1,5 @@ +# shellcheck shell=bash +# shellcheck disable=SC2034 +# /images//: the namespace is the source repository +# and the name is the deployable (ADR 6497710059). +IMAGE=ghcr.io/trogonstack/images/agentgateway/agentgateway diff --git a/.config/mise/tasks/github/workflows/trogonstack-image/image-name b/.config/mise/tasks/github/workflows/trogonstack-image/image-name new file mode 100755 index 0000000000..460554fb68 --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-image/image-name @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +#MISE description="Expose the image name as the step output name" +set -euo pipefail +source "$MISE_PROJECT_ROOT/.config/mise/lib/image.sh" +echo "name=$IMAGE" >> "$GITHUB_OUTPUT" diff --git a/.config/mise/tasks/github/workflows/trogonstack-image/summary b/.config/mise/tasks/github/workflows/trogonstack-image/summary new file mode 100755 index 0000000000..591265f83c --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-image/summary @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +#MISE description="Write the pushed image reference to the step summary" +set -euo pipefail +echo "\`${REF}\`" >> "$GITHUB_STEP_SUMMARY" diff --git a/.config/mise/tasks/github/workflows/trogonstack-release/add-calver-tag b/.config/mise/tasks/github/workflows/trogonstack-release/add-calver-tag new file mode 100755 index 0000000000..64ee2b4cc2 --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-release/add-calver-tag @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +#MISE description="Add the next CalVer tag to the image built for the commit" +set -euo pipefail +source "$MISE_PROJECT_ROOT/.config/mise/lib/image.sh" +source "$MISE_PROJECT_ROOT/.config/mise/lib/calver.sh" + +digest="$(crane digest "$IMAGE:$COMMIT" 2>/dev/null)" || { + echo "No image $IMAGE:$COMMIT. Run trogonstack-image for that commit first." >&2 + exit 1 +} + +# A registry error must stop the release: a missing pair would hide an earlier +# release of this commit or reuse a taken N. Only "no version tags" is fine. +all_tags="$(crane ls "$IMAGE")" +pairs="" +for tag in $(printf '%s\n' "$all_tags" | grep -E '^[0-9]{4}\.[0-9]{3,4}\.[0-9]+$' || true); do + tagdigest="$(crane digest "$IMAGE:$tag")" + pairs+="$tag $tagdigest"$'\n' +done + +# Month without padding followed by a two digit day: 5 April is 405. +today="$(date -u +%Y.%-m%d)" +result="$(printf '%s\n' "$pairs" | decide "$digest" "$today")" + +case "$result" in + released\ *) + tag="${result#released }" + echo "$COMMIT already released as $tag ($digest)" + printf 'Already released as %s\n\n%s@%s\n' "$tag" "$IMAGE" "$digest" >> "$GITHUB_STEP_SUMMARY" + exit 0 + ;; +esac + +version="${result#next }" +crane tag "$IMAGE:$COMMIT" "$version" + +tagged="$(crane digest "$IMAGE:$version")" +if [ "$tagged" != "$digest" ]; then + echo "Tag $version resolves to $tagged, expected $digest" >&2 + exit 1 +fi +printf 'Released %s\n\n%s:%s@%s\n' "$version" "$IMAGE" "$version" "$digest" >> "$GITHUB_STEP_SUMMARY" diff --git a/.config/mise/tasks/github/workflows/trogonstack-release/registry-login b/.config/mise/tasks/github/workflows/trogonstack-release/registry-login new file mode 100755 index 0000000000..176e1cfd94 --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-release/registry-login @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +#MISE description="Log crane in to ghcr.io" +set -euo pipefail +printf '%s' "$TOKEN" | crane auth login ghcr.io -u "$ACTOR" --password-stdin diff --git a/.config/mise/tasks/github/workflows/trogonstack-release/resolve-commit b/.config/mise/tasks/github/workflows/trogonstack-release/resolve-commit new file mode 100755 index 0000000000..c578d58f1d --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-release/resolve-commit @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +#MISE description="Resolve the commit to release" +set -euo pipefail +sha="$(gh api "repos/$GITHUB_REPOSITORY/commits/${INPUT_COMMIT:-main}" --jq .sha)" +echo "sha=$sha" >> "$GITHUB_OUTPUT" diff --git a/.github/actions/setup-mise/action.yml b/.github/actions/setup-mise/action.yml new file mode 100644 index 0000000000..67881e7a4d --- /dev/null +++ b/.github/actions/setup-mise/action.yml @@ -0,0 +1,24 @@ +name: Set up mise +description: Install a pinned mise release after verifying its sha256 checksum. + +# jdx/mise-action is not an allowed action, so the release binary is installed +# directly. This runs before mise exists, so it cannot be a mise task +# (ADR 6647967335 puts composite action scripts under +# .config/mise/tasks/github/actions// only when mise can run them). +runs: + using: composite + steps: + - shell: bash + env: + MISE_VERSION: v2026.10.15 + MISE_SHA256: 1c2d85dc42bef51e0bb20780093c746d6e12dfd15ca461f3979bd52cc214bc19 + run: | + set -euo pipefail + archive="$RUNNER_TEMP/mise.tar.gz" + curl -fsSL -o "$archive" "https://github.com/jdx/mise/releases/download/$MISE_VERSION/mise-$MISE_VERSION-linux-x64.tar.gz" + echo "$MISE_SHA256 $archive" | sha256sum --check --strict + mkdir -p "$RUNNER_TEMP/mise-install" + tar -xzf "$archive" -C "$RUNNER_TEMP/mise-install" + echo "$RUNNER_TEMP/mise-install/mise/bin" >> "$GITHUB_PATH" + # The checkout is ours, so its mise.toml needs no trust prompt. + echo "MISE_TRUSTED_CONFIG_PATHS=$GITHUB_WORKSPACE" >> "$GITHUB_ENV" diff --git a/.github/workflows/trogonstack-image.yml b/.github/workflows/trogonstack-image.yml index 83023577bc..afd4d08eb2 100644 --- a/.github/workflows/trogonstack-image.yml +++ b/.github/workflows/trogonstack-image.yml @@ -2,18 +2,27 @@ name: trogonstack-image # main = upstream main + our patch commits. Builds the proxy image so fixes run # before upstream ships them. Each platform builds on a native runner, then the -# digests are joined into one image index. +# digests are joined into one image index. The cluster runs amd64; arm64 is +# kept in case that changes, and costs no emulation. on: push: branches: [main] + pull_request: workflow_dispatch: + inputs: + release: + description: Tag the built image with the next CalVer version (main only) + type: boolean + default: false permissions: contents: read env: - IMAGE: ghcr.io/trogonstack/images/agentgateway/agentgateway + # A pull request pushes only when it comes from this repository, so fork PRs + # build without a registry write. + PUSH: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} jobs: build: @@ -32,31 +41,50 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + - uses: ./.github/actions/setup-mise + - id: image + run: mise run github:workflows:trogonstack-image:image-name - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 - uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 + if: env.PUSH == 'true' with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6 + env: + # Annotations land on each platform manifest. The index gets its own + # in the merge job. + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest + # Label the pull request head commit, not the merge commit. + DOCKER_METADATA_PR_HEAD_SHA: 'true' + with: + images: ${{ steps.image.outputs.name }} - id: build uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 with: context: . platforms: ${{ matrix.platform }} provenance: mode=min + labels: ${{ steps.meta.outputs.labels }} + annotations: ${{ steps.meta.outputs.annotations }} build-args: | - VERSION=trogonstack-${{ github.sha }} - GIT_REVISION=${{ github.sha }} - outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true + VERSION=trogonstack-${{ github.event.pull_request.head.sha || github.sha }} + GIT_REVISION=${{ github.event.pull_request.head.sha || github.sha }} + # Pushed by digest: the tags are put on the joined index below. + outputs: type=image,name=${{ steps.image.outputs.name }},push-by-digest=true,name-canonical=true,push=${{ env.PUSH == 'true' }} cache-from: type=gha,scope=${{ matrix.platform }} cache-to: type=gha,mode=max,scope=${{ matrix.platform }} - name: Export digest + if: env.PUSH == 'true' env: DIGEST: ${{ steps.build.outputs.digest }} run: | mkdir -p "${RUNNER_TEMP}/digests" touch "${RUNNER_TEMP}/digests/${DIGEST#sha256:}" - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + if: env.PUSH == 'true' with: name: digest-${{ strategy.job-index }} path: ${{ runner.temp }}/digests/* @@ -64,11 +92,19 @@ jobs: merge: needs: build + # The job-level if cannot read env, so the PUSH condition is repeated. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository runs-on: ubuntu-24.04 permissions: contents: read packages: write steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: ./.github/actions/setup-mise + - id: image + run: mise run github:workflows:trogonstack-image:image-name - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: pattern: digest-* @@ -80,9 +116,43 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6 + env: + # Annotations land on the image index. + DOCKER_METADATA_ANNOTATIONS_LEVELS: index + # Label the pull request head commit, not the merge commit. + DOCKER_METADATA_PR_HEAD_SHA: 'true' + with: + images: ${{ steps.image.outputs.name }} + tags: | + type=sha,format=long,prefix=,enable=${{ github.event_name != 'pull_request' }} + type=raw,value=pr-${{ github.event.pull_request.head.sha }},enable=${{ github.event_name == 'pull_request' }} - name: Create image index + id: index working-directory: ${{ runner.temp }}/digests + env: + IMAGE: ${{ steps.image.outputs.name }} run: | - docker buildx imagetools create -t "${IMAGE}:${GITHUB_SHA}" \ - $(printf "${IMAGE}@sha256:%s " *) - docker buildx imagetools inspect "${IMAGE}:${GITHUB_SHA}" + mapfile -t tags < <(jq -r '.tags[] | "-t", .' <<<"$DOCKER_METADATA_OUTPUT_JSON") + mapfile -t annotations < <(jq -r '.annotations[] | "--annotation", .' <<<"$DOCKER_METADATA_OUTPUT_JSON") + sources=() + for digest in *; do + sources+=("${IMAGE}@sha256:${digest}") + done + docker buildx imagetools create "${tags[@]}" "${annotations[@]}" "${sources[@]}" + docker buildx imagetools inspect "${tags[1]}" + echo "digest=$(docker buildx imagetools inspect "${tags[1]}" --format '{{json .Manifest}}' | jq -r .digest)" >> "$GITHUB_OUTPUT" + - env: + REF: ${{ steps.image.outputs.name }}@${{ steps.index.outputs.digest }} + run: mise run github:workflows:trogonstack-image:summary + + release: + needs: merge + if: github.event_name == 'workflow_dispatch' && inputs.release && github.ref == 'refs/heads/main' + permissions: + contents: read + packages: write + uses: ./.github/workflows/trogonstack-release.yml + with: + commit: ${{ github.sha }} diff --git a/.github/workflows/trogonstack-release.yml b/.github/workflows/trogonstack-release.yml new file mode 100644 index 0000000000..492ef67148 --- /dev/null +++ b/.github/workflows/trogonstack-release.yml @@ -0,0 +1,60 @@ +name: trogonstack-release + +# Releases an image by adding a CalVer tag (YYYY.MDD.N, ADR 6497710059) to the +# image already built for a commit. It never builds, so the digest of the +# release is the digest of the commit build. Safe to run repeatedly: a commit +# that already carries a version tag is left alone. + +on: + workflow_call: + inputs: + commit: + description: Full commit SHA to release. Defaults to the current HEAD of main. + type: string + required: false + default: '' + workflow_dispatch: + inputs: + commit: + description: Commit to release. Defaults to the current HEAD of main. + type: string + required: false + default: '' + +permissions: + contents: read + +concurrency: + group: trogonstack-release + cancel-in-progress: false + +env: + GH_TOKEN: ${{ github.token }} + +jobs: + release: + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + packages: write + steps: + # The mise tasks and configuration live in the repository. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: ./.github/actions/setup-mise + - name: Log in to ghcr.io + env: + ACTOR: ${{ github.actor }} + TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: mise run github:workflows:trogonstack-release:registry-login + - name: Resolve the commit + id: commit + env: + INPUT_COMMIT: ${{ inputs.commit }} + run: mise run github:workflows:trogonstack-release:resolve-commit + - name: Add the CalVer tag + env: + COMMIT: ${{ steps.commit.outputs.sha }} + run: mise run github:workflows:trogonstack-release:add-calver-tag diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000000..88824a5bd3 --- /dev/null +++ b/mise.toml @@ -0,0 +1,4 @@ +# Tooling for the trogonstack-* workflows only. Upstream's Rust build does not +# read this file. Tasks live in .config/mise/tasks (ADR 6647967335). +[tools] +"aqua:google/go-containerregistry" = "0.22.1" From 58716cccc2ef7d06e04d84ca0a88c01c42af7690 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 24 Nov 2026 02:28:10 -0500 Subject: [PATCH 2/4] ci: merge upstream main weekly so the fork never falls behind it Signed-off-by: Yordis Prieto --- .../workflows/trogonstack-sync/fetch-merge | 10 + .../workflows/trogonstack-sync/merge-upstream | 22 +++ .../trogonstack-sync/publish-pull-request | 44 +++++ .../workflows/trogonstack-sync/push-main | 23 +++ .../trogonstack-sync/release-current | 22 +++ .../trogonstack-sync/resolve-upstream | 15 ++ .../github/workflows/trogonstack-sync/verify | 24 +++ .github/workflows/trogonstack-sync.yml | 183 ++++++++++++++++++ 8 files changed, 343 insertions(+) create mode 100755 .config/mise/tasks/github/workflows/trogonstack-sync/fetch-merge create mode 100755 .config/mise/tasks/github/workflows/trogonstack-sync/merge-upstream create mode 100755 .config/mise/tasks/github/workflows/trogonstack-sync/publish-pull-request create mode 100755 .config/mise/tasks/github/workflows/trogonstack-sync/push-main create mode 100755 .config/mise/tasks/github/workflows/trogonstack-sync/release-current create mode 100755 .config/mise/tasks/github/workflows/trogonstack-sync/resolve-upstream create mode 100755 .config/mise/tasks/github/workflows/trogonstack-sync/verify create mode 100644 .github/workflows/trogonstack-sync.yml diff --git a/.config/mise/tasks/github/workflows/trogonstack-sync/fetch-merge b/.config/mise/tasks/github/workflows/trogonstack-sync/fetch-merge new file mode 100755 index 0000000000..59d46347de --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-sync/fetch-merge @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +#MISE description="Fetch the bundled merge and check it is the commit the merge job recorded" +set -euo pipefail +# The sha was recorded before any upstream code ran, so a test that replaced +# the bundle is caught here. +git fetch --no-tags "$RUNNER_TEMP/sync.bundle" HEAD +if [ "$(git rev-parse FETCH_HEAD)" != "$MERGE_SHA" ]; then + echo "The bundle holds $(git rev-parse FETCH_HEAD), not $MERGE_SHA" >&2 + exit 1 +fi diff --git a/.config/mise/tasks/github/workflows/trogonstack-sync/merge-upstream b/.config/mise/tasks/github/workflows/trogonstack-sync/merge-upstream new file mode 100755 index 0000000000..8f92601959 --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-sync/merge-upstream @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +#MISE description="Merge upstream main, committing any conflicts so they can be published as a pull request" +set -euo pipefail +git config user.name 'github-actions[bot]' +git config user.email '41898282+github-actions[bot]@users.noreply.github.com' +if git merge --no-ff --no-edit -m "chore(sync): merge upstream main $UPSTREAM_SHORT" "$UPSTREAM_SHA"; then + conflict=false +else + # Commit the conflict markers instead of aborting, so the merge can be + # finished on the pull request branch rather than redone by hand. + git diff --name-only --diff-filter=U > "$RUNNER_TEMP/conflicts.txt" + git add -A + git commit --no-edit -m "chore(sync): merge upstream $UPSTREAM_SHORT with conflicts" + conflict=true +fi +# The publish job pushes exactly this commit, so it is bundled here, before +# the build and tests run any upstream code. +git bundle create "$RUNNER_TEMP/sync.bundle" HEAD ^origin/main +{ + echo "conflict=$conflict" + echo "sha=$(git rev-parse HEAD)" +} >> "$GITHUB_OUTPUT" diff --git a/.config/mise/tasks/github/workflows/trogonstack-sync/publish-pull-request b/.config/mise/tasks/github/workflows/trogonstack-sync/publish-pull-request new file mode 100755 index 0000000000..fa7a18c2d4 --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-sync/publish-pull-request @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +#MISE description="Publish a merge that cannot land on main as a draft pull request and fail" +set -euo pipefail +source "$MISE_PROJECT_ROOT/.config/mise/lib/git.sh" + +branch="sync/upstream-main" +# An open pull request may already carry fixes, so leave its branch alone. +existing="$(GH_TOKEN="$BARNACLE_TOKEN" gh pr list --state open --head "$branch" --json url --jq '.[0].url // ""')" +if [ -n "$existing" ]; then + echo "Upstream main is still pending on $existing" >> "$GITHUB_STEP_SUMMARY" + exit 1 +fi + +if [ "$CONFLICT" = "true" ]; then + reason="it conflicts with main." +elif [ "$VERIFIED" = "failure" ]; then + reason="build or tests failed." +else + reason="$PUSH_REASON" +fi + +# Pushed as Barnacle so the pull request runs CI and may change workflows. +# Without an open pull request the branch is stale, so it is replaced. +git_push_as "$BARNACLE_TOKEN" --force origin "$MERGE_SHA:refs/heads/$branch" + +{ + echo "Merging upstream main ($UPSTREAM_SHORT) into main needs a fix before it can land: $reason" + # Only a conflicting merge skips the build and tests, so only then is the + # list known to be written before any upstream code ran. + if [ "$CONFLICT" = "true" ] && [ -s "$RUNNER_TEMP/conflicts.txt" ]; then + echo + echo "Conflicting files, committed with their markers:" + # shellcheck disable=SC2016 # literal backticks for markdown + head -n 200 "$RUNNER_TEMP/conflicts.txt" | sed 's/^/- `/; s/$/`/' + fi + echo + echo "Run: $RUN_URL" + echo + echo "Fix on this branch, mark it ready, then merge it into main." +} > "$RUNNER_TEMP/pr-body.txt" +url="$(GH_TOKEN="$BARNACLE_TOKEN" gh pr create --draft --base main --head "$branch" \ + --title "chore(sync): merge upstream main $UPSTREAM_SHORT" --body-file "$RUNNER_TEMP/pr-body.txt")" +echo "Upstream main $UPSTREAM_SHORT is pending on $url" >> "$GITHUB_STEP_SUMMARY" +exit 1 diff --git a/.config/mise/tasks/github/workflows/trogonstack-sync/push-main b/.config/mise/tasks/github/workflows/trogonstack-sync/push-main new file mode 100755 index 0000000000..0e1c565f63 --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-sync/push-main @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +#MISE description="Push the verified merge to main and dispatch the image build, or record why it needs a pull request" +set -euo pipefail +# The publish job runs these tasks from main with the Barnacle key in reach, so +# a merge that changes them, mise configuration or a local action must land +# through a reviewed pull request, never this push. GITHUB_TOKEN already may +# not push .github/workflows. +trusted='^(\.github/|\.config/|\.?mise/|\.?mise(\.[^/]+)?\.toml$|\.tool-versions$)' +reason="" +# Captured first so a failing diff stops the script instead of reading as no +# match, and so grep -q cannot cut the pipe short under pipefail. +changed="$(git diff --name-only --no-renames HEAD "$MERGE_SHA")" +if grep -Eq "$trusted" <<<"$changed"; then + reason="the merge changes .github, .config or mise configuration, which the publish job runs." +elif git push origin "$MERGE_SHA:refs/heads/main"; then + # Pushes made with GITHUB_TOKEN do not trigger workflows, but + # workflow_dispatch does, so start the image build explicitly. + gh workflow run trogonstack-image.yml --ref main -f release=true + echo "Merged upstream main $UPSTREAM_SHORT into main and dispatched the image build with release" >> "$GITHUB_STEP_SUMMARY" +else + reason="the push to main was rejected." +fi +echo "reason=$reason" >> "$GITHUB_OUTPUT" diff --git a/.config/mise/tasks/github/workflows/trogonstack-sync/release-current b/.config/mise/tasks/github/workflows/trogonstack-sync/release-current new file mode 100755 index 0000000000..f6c6c05c82 --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-sync/release-current @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +#MISE description="Release current main, building it first when it has no image" +set -euo pipefail +source "$MISE_PROJECT_ROOT/.config/mise/lib/image.sh" +source "$MISE_PROJECT_ROOT/.config/mise/lib/ghcr.sh" + +head="$(git rev-parse HEAD)" +# shellcheck disable=SC2153 +status="$(ghcr_manifest_status "$IMAGE" "$head" "$ACTOR" "$REGISTRY_TOKEN")" +# Only a 404 means the image is missing. Any other answer is an outage +# or an auth problem, and building again would move the commit tag. +if [ "$status" = "200" ]; then + # Release the commit whose image was checked, even if main moves meanwhile. + gh workflow run trogonstack-release.yml --ref main -f commit="$head" + echo "main is current with upstream; dispatched the release for $head" >> "$GITHUB_STEP_SUMMARY" +elif [ "$status" = "404" ]; then + gh workflow run trogonstack-image.yml --ref main -f release=true + echo "main is current with upstream; $IMAGE:$head not found, dispatched the image build with release" >> "$GITHUB_STEP_SUMMARY" +else + echo "Registry answered HTTP $status for $IMAGE:$head" >&2 + exit 1 +fi diff --git a/.config/mise/tasks/github/workflows/trogonstack-sync/resolve-upstream b/.config/mise/tasks/github/workflows/trogonstack-sync/resolve-upstream new file mode 100755 index 0000000000..540399d63a --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-sync/resolve-upstream @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +#MISE description="Resolve upstream main and report whether main contains it" +set -euo pipefail +# Upstream main is merged, not its release tags: our fixes are unreleased, and +# main must never fall behind it. Only the commit is fetched, never a tag. +git fetch --no-tags "$UPSTREAM" main +sha="$(git rev-parse FETCH_HEAD)" +echo "sha=$sha" >> "$GITHUB_OUTPUT" +echo "short=${sha:0:12}" >> "$GITHUB_OUTPUT" +if git merge-base --is-ancestor "$sha" HEAD; then + echo "up_to_date=true" >> "$GITHUB_OUTPUT" + echo "main already contains upstream main $sha" >> "$GITHUB_STEP_SUMMARY" +else + echo "up_to_date=false" >> "$GITHUB_OUTPUT" +fi diff --git a/.config/mise/tasks/github/workflows/trogonstack-sync/verify b/.config/mise/tasks/github/workflows/trogonstack-sync/verify new file mode 100755 index 0000000000..5f7fab189e --- /dev/null +++ b/.config/mise/tasks/github/workflows/trogonstack-sync/verify @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +#MISE description="Build and test the merged tree" +set -euo pipefail +# The runner's rustup has no toolchain pinned by the merged tree, so install +# the channel rust-toolchain.toml names. Exporting it keeps cargo from +# resolving the file again and pulling its clippy and rustfmt components. +channel="$(sed -n 's/^channel *= *"\(.*\)"/\1/p' rust-toolchain.toml)" +if [ -z "$channel" ]; then + echo "No channel in rust-toolchain.toml" >&2 + exit 1 +fi +rustup toolchain install "$channel" --profile minimal +export RUSTUP_TOOLCHAIN="$channel" + +# Upstream's proxy-test job runs `make test` (every test, bench and example) +# on a cached 4 vCPU runner with Keycloak and Postgres. A cold build of all of +# that does not fit this job's budget, and the service-backed tests are skipped +# here anyway. These two cover the code our patch commits touch and the code +# they run in: the LLM translation crate and the proxy crate's unit tests. If +# upstream main later breaks something outside them, widen this list. +export CARGO_INCREMENTAL=0 +export CARGO_PROFILE_TEST_DEBUG=0 +cargo test -p agent-llm +cargo test -p agentgateway --lib diff --git a/.github/workflows/trogonstack-sync.yml b/.github/workflows/trogonstack-sync.yml new file mode 100644 index 0000000000..e423e94bf7 --- /dev/null +++ b/.github/workflows/trogonstack-sync.yml @@ -0,0 +1,183 @@ +name: trogonstack-sync + +# Merges upstream main into main every Friday, so the image is ready for the +# homelab Renovate batch on Saturday. Upstream main is merged, not its release +# tags, because our fixes are unreleased and main must not fall behind it. +# The merge keeps history, so main is never force-pushed. +# main = upstream main + our patch commits. This repo must never carry or push +# git tags: upstream's release workflow triggers on v*.*.* tag pushes. Only +# the upstream main commit is fetched into the runner, never a tag. + +on: + schedule: + - cron: '17 6 * * 5' + workflow_dispatch: + +permissions: {} + +concurrency: + group: trogonstack-sync + cancel-in-progress: false + +env: + UPSTREAM: https://github.com/agentgateway/agentgateway.git + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + +jobs: + # Builds and tests upstream code, so it can read the repository and nothing + # else. The merge is bundled before any of that code runs, and publish + # pushes it by sha, so a test cannot swap the commit that lands. + merge: + runs-on: ubuntu-latest + timeout-minutes: 90 + permissions: + contents: read + outputs: + up_to_date: ${{ steps.upstream.outputs.up_to_date }} + upstream_sha: ${{ steps.upstream.outputs.sha }} + upstream_short: ${{ steps.upstream.outputs.short }} + sha: ${{ steps.merge.outputs.sha }} + conflict: ${{ steps.merge.outputs.conflict }} + verified: ${{ steps.verify.outcome }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: main + fetch-depth: 0 + persist-credentials: false + + - uses: ./.github/actions/setup-mise + + - name: Resolve upstream main + id: upstream + run: mise run github:workflows:trogonstack-sync:resolve-upstream + - name: Merge upstream main + id: merge + if: steps.upstream.outputs.up_to_date == 'false' + env: + UPSTREAM_SHA: ${{ steps.upstream.outputs.sha }} + UPSTREAM_SHORT: ${{ steps.upstream.outputs.short }} + run: mise run github:workflows:trogonstack-sync:merge-upstream + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + if: steps.upstream.outputs.up_to_date == 'false' + with: + name: sync + path: | + ${{ runner.temp }}/sync.bundle + ${{ runner.temp }}/conflicts.txt + retention-days: 7 + + # No build cache is restored or saved: one saved after upstream tests run + # would be restored by later builds on main. The verify task installs + # the Rust toolchain from rust-toolchain.toml and runs a justified subset + # of upstream's tests, see its comment. + - name: Build and test + id: verify + if: steps.upstream.outputs.up_to_date == 'false' && steps.merge.outputs.conflict == 'false' + continue-on-error: true + run: mise run github:workflows:trogonstack-sync:verify + + # The only job that can read the Barnacle key: the environment admits it + # from main, and GCP admits only this file. It runs mise tasks and a local + # action from main, so push-main never lands a merge that changes them; + # those, like workflow changes GITHUB_TOKEN may not push, go through a + # reviewed pull request. + # Barnacle opens the sync pull requests, so they run CI and may change + # workflows, which GITHUB_TOKEN can do neither of. + publish: + needs: merge + if: needs.merge.outputs.up_to_date == 'false' + runs-on: ubuntu-latest + timeout-minutes: 15 + environment: github-app-barnacle + permissions: + contents: write + actions: write + id-token: write + env: + UPSTREAM_SHORT: ${{ needs.merge.outputs.upstream_short }} + MERGE_SHA: ${{ needs.merge.outputs.sha }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: main + fetch-depth: 0 + + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: sync + path: ${{ runner.temp }} + + - uses: ./.github/actions/setup-mise + + - name: Fetch the merge + run: mise run github:workflows:trogonstack-sync:fetch-merge + + - name: Push main and build image + id: push + if: needs.merge.outputs.verified == 'success' + run: mise run github:workflows:trogonstack-sync:push-main + + - name: Google Cloud auth + if: needs.merge.outputs.verified != 'success' || steps.push.outputs.reason != '' + uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3 + with: + project_id: ${{ vars.BARNACLE_PROJECT_ID }} + workload_identity_provider: ${{ vars.BARNACLE_WORKLOAD_IDENTITY_PROVIDER }} + + - name: Barnacle key + id: barnacle_key + if: needs.merge.outputs.verified != 'success' || steps.push.outputs.reason != '' + uses: google-github-actions/get-secretmanager-secrets@bc9c54b29fdffb8a47776820a7d26e77b379d262 # v3.0.0 + with: + secrets: |- + private_key:${{ vars.BARNACLE_PRIVATE_KEY_SECRET }} + + - name: Barnacle token + id: barnacle + if: needs.merge.outputs.verified != 'success' || steps.push.outputs.reason != '' + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + client-id: ${{ vars.BARNACLE_APP_CLIENT_ID }} + private-key: ${{ steps.barnacle_key.outputs.private_key }} + repositories: ${{ github.event.repository.name }} + permission-contents: write + permission-pull-requests: write + permission-workflows: write + + - name: Publish the merge as a pull request + if: needs.merge.outputs.verified != 'success' || steps.push.outputs.reason != '' + env: + BARNACLE_TOKEN: ${{ steps.barnacle.outputs.token }} + CONFLICT: ${{ needs.merge.outputs.conflict }} + VERIFIED: ${{ needs.merge.outputs.verified }} + PUSH_REASON: ${{ steps.push.outputs.reason }} + run: mise run github:workflows:trogonstack-sync:publish-pull-request + + # Main may hold fork-only commits that were never released. The release + # workflow is idempotent, so run it for HEAD when it has an image, and build + # and release that commit when it has none. + release: + needs: merge + if: needs.merge.outputs.up_to_date == 'true' + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + actions: write + packages: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: main + persist-credentials: false + + - uses: ./.github/actions/setup-mise + + - name: Release current main + env: + REGISTRY_TOKEN: ${{ github.token }} + ACTOR: ${{ github.actor }} + run: mise run github:workflows:trogonstack-sync:release-current From c2c8909080d9834f15a2d47e2a41b7e2dfb6bab8 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 24 Nov 2026 02:29:47 -0500 Subject: [PATCH 3/4] ci: install the arm64 mise on the native arm64 runner Signed-off-by: Yordis Prieto --- .github/actions/setup-mise/action.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-mise/action.yml b/.github/actions/setup-mise/action.yml index 67881e7a4d..1cd11424f5 100644 --- a/.github/actions/setup-mise/action.yml +++ b/.github/actions/setup-mise/action.yml @@ -11,11 +11,18 @@ runs: - shell: bash env: MISE_VERSION: v2026.10.15 - MISE_SHA256: 1c2d85dc42bef51e0bb20780093c746d6e12dfd15ca461f3979bd52cc214bc19 + MISE_SHA256_X64: 1c2d85dc42bef51e0bb20780093c746d6e12dfd15ca461f3979bd52cc214bc19 + MISE_SHA256_ARM64: ae36e72ea72d337ab7b367edb0f7016fa1502aa0e36ccb705acad7902c60677b run: | set -euo pipefail + # The image workflow builds arm64 on a native runner. + case "$RUNNER_ARCH" in + X64) arch=x64 MISE_SHA256="$MISE_SHA256_X64" ;; + ARM64) arch=arm64 MISE_SHA256="$MISE_SHA256_ARM64" ;; + *) echo "Unsupported runner architecture $RUNNER_ARCH" >&2; exit 1 ;; + esac archive="$RUNNER_TEMP/mise.tar.gz" - curl -fsSL -o "$archive" "https://github.com/jdx/mise/releases/download/$MISE_VERSION/mise-$MISE_VERSION-linux-x64.tar.gz" + curl -fsSL -o "$archive" "https://github.com/jdx/mise/releases/download/$MISE_VERSION/mise-$MISE_VERSION-linux-$arch.tar.gz" echo "$MISE_SHA256 $archive" | sha256sum --check --strict mkdir -p "$RUNNER_TEMP/mise-install" tar -xzf "$archive" -C "$RUNNER_TEMP/mise-install" From 82a282b8b1efdb10a9d3a98ceada66318442a45e Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 24 Nov 2026 02:53:14 -0500 Subject: [PATCH 4/4] ci: harden the release tag and the sync gate against races and hung tests Signed-off-by: Yordis Prieto --- .config/mise/lib/calver.sh | 13 ++++++++++--- .../workflows/trogonstack-release/add-calver-tag | 4 +++- .../github/workflows/trogonstack-sync/push-main | 11 ++++++----- .github/workflows/trogonstack-sync.yml | 4 ++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.config/mise/lib/calver.sh b/.config/mise/lib/calver.sh index 1d4aeecad9..0cd86254f4 100644 --- a/.config/mise/lib/calver.sh +++ b/.config/mise/lib/calver.sh @@ -1,16 +1,23 @@ # shellcheck shell=bash # decide reads " " lines of the # existing version tags on stdin. It prints "released " when a -# tag already points at , otherwise "next ". +# tag already points at , otherwise "next ", where N is one +# more than the largest suffix of today (a count would reuse a taken N when a +# tag is missing from the sequence). decide() { - local digest="$1" today="$2" tag tagdigest n=0 + local digest="$1" today="$2" tag tagdigest n=0 suffix while read -r tag tagdigest; do [ -n "$tag" ] || continue if [ "$tagdigest" = "$digest" ]; then echo "released $tag" return 0 fi - case "$tag" in "$today".*) n=$((n + 1)) ;; esac + case "$tag" in + "$today".*) + suffix="${tag#"$today".}" + if [ "$suffix" -ge "$n" ]; then n=$((suffix + 1)); fi + ;; + esac done echo "next $today.$n" } diff --git a/.config/mise/tasks/github/workflows/trogonstack-release/add-calver-tag b/.config/mise/tasks/github/workflows/trogonstack-release/add-calver-tag index 64ee2b4cc2..2e97413518 100755 --- a/.config/mise/tasks/github/workflows/trogonstack-release/add-calver-tag +++ b/.config/mise/tasks/github/workflows/trogonstack-release/add-calver-tag @@ -32,7 +32,9 @@ case "$result" in esac version="${result#next }" -crane tag "$IMAGE:$COMMIT" "$version" +# Tag the digest recorded above: the commit tag is mutable, and a rebuild of +# the same commit could repoint it before this runs. +crane tag "$IMAGE@$digest" "$version" tagged="$(crane digest "$IMAGE:$version")" if [ "$tagged" != "$digest" ]; then diff --git a/.config/mise/tasks/github/workflows/trogonstack-sync/push-main b/.config/mise/tasks/github/workflows/trogonstack-sync/push-main index 0e1c565f63..374a9dfb33 100755 --- a/.config/mise/tasks/github/workflows/trogonstack-sync/push-main +++ b/.config/mise/tasks/github/workflows/trogonstack-sync/push-main @@ -5,12 +5,13 @@ set -euo pipefail # a merge that changes them, mise configuration or a local action must land # through a reviewed pull request, never this push. GITHUB_TOKEN already may # not push .github/workflows. -trusted='^(\.github/|\.config/|\.?mise/|\.?mise(\.[^/]+)?\.toml$|\.tool-versions$)' +trusted='^(\.github/|\.config/|\.?mise/|\.?mise(\.[^/]+)?\.(toml|lock)$|\.tool-versions$)' reason="" -# Captured first so a failing diff stops the script instead of reading as no -# match, and so grep -q cannot cut the pipe short under pipefail. -changed="$(git diff --name-only --no-renames HEAD "$MERGE_SHA")" -if grep -Eq "$trusted" <<<"$changed"; then +# Written to a file first so a failing diff stops the script instead of reading +# as no match. NUL-delimited so git does not quote unusual path names, which +# would hide a trusted prefix from the match. +git diff -z --name-only --no-renames HEAD "$MERGE_SHA" > "$RUNNER_TEMP/changed.txt" +if grep -Ezq "$trusted" "$RUNNER_TEMP/changed.txt"; then reason="the merge changes .github, .config or mise configuration, which the publish job runs." elif git push origin "$MERGE_SHA:refs/heads/main"; then # Pushes made with GITHUB_TOKEN do not trigger workflows, but diff --git a/.github/workflows/trogonstack-sync.yml b/.github/workflows/trogonstack-sync.yml index e423e94bf7..c2755de822 100644 --- a/.github/workflows/trogonstack-sync.yml +++ b/.github/workflows/trogonstack-sync.yml @@ -77,6 +77,10 @@ jobs: id: verify if: steps.upstream.outputs.up_to_date == 'false' && steps.merge.outputs.conflict == 'false' continue-on-error: true + # Shorter than the job's timeout: a hung test then fails this step, + # which still lets publish open the draft pull request. The job timeout + # would cancel the job and skip publish. + timeout-minutes: 70 run: mise run github:workflows:trogonstack-sync:verify # The only job that can read the Barnacle key: the environment admits it