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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .config/mise/lib/calver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# shellcheck shell=bash
# decide <digest> <today YYYY.MDD> reads "<tag> <digest>" lines of the
# existing version tags on stdin. It prints "released <tag>" when a
# tag already points at <digest>, otherwise "next <YYYY.MDD.N>", 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 suffix
while read -r tag tagdigest; do
[ -n "$tag" ] || continue
if [ "$tagdigest" = "$digest" ]; then
echo "released $tag"
return 0
fi
case "$tag" in
"$today".*)
suffix="${tag#"$today".}"
if [ "$suffix" -ge "$n" ]; then n=$((suffix + 1)); fi
;;
esac
done
echo "next $today.$n"
}
18 changes: 18 additions & 0 deletions .config/mise/lib/ghcr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# shellcheck shell=bash
# ghcr_manifest_status <image> <tag> <actor> <token> 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"
}
12 changes: 12 additions & 0 deletions .config/mise/lib/git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# shellcheck shell=bash
# git_push_as <token> <git push args...> 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}"
}
5 changes: 5 additions & 0 deletions .config/mise/lib/image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# shellcheck shell=bash
# shellcheck disable=SC2034
# <registry>/images/<namespace>/<name>: the namespace is the source repository
# and the name is the deployable (ADR 6497710059).
IMAGE=ghcr.io/trogonstack/images/agentgateway/agentgateway
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions .config/mise/tasks/github/workflows/trogonstack-image/summary
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/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 }"
# 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
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"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 10 additions & 0 deletions .config/mise/tasks/github/workflows/trogonstack-sync/fetch-merge
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions .config/mise/tasks/github/workflows/trogonstack-sync/push-main
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/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|lock)$|\.tool-versions$)'
reason=""
# 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
# 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"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions .config/mise/tasks/github/workflows/trogonstack-sync/verify
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions .github/actions/setup-mise/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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/<name>/ only when mise can run them).
runs:
using: composite
steps:
- shell: bash
env:
MISE_VERSION: v2026.10.15
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-$arch.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"
Loading
Loading