From 7b8b57975692c498719f330fc4fe0eaee07ea58d Mon Sep 17 00:00:00 2001 From: Ilan Harel Date: Mon, 30 Nov 2026 17:10:48 +0200 Subject: [PATCH] ci(openshell-next): install the Rust version the branch needs The tracking job hard-coded Rust 1.94, but OpenShell v0.1.11-pre.2 needs 1.95. After the merge and the bump it now installs the highest rust-version of openshell-annotate and the locked ai-openshell/openshell crates (new `scripts/openshell-next.sh toolchain`). `sync` keeps the branch's higher rust-version when it resolves a pin conflict from main's Cargo.toml, which it used to reset to main's. Closes #118 Signed-off-by: Ilan Harel --- .github/workflows/openshell-next.yml | 13 +++++++--- CHANGELOG.md | 1 + docs/DEVELOPING.md | 10 +++++--- scripts/openshell-next.sh | 37 +++++++++++++++++++++++++--- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/.github/workflows/openshell-next.yml b/.github/workflows/openshell-next.yml index 77aa0b4..b93133d 100644 --- a/.github/workflows/openshell-next.yml +++ b/.github/workflows/openshell-next.yml @@ -89,9 +89,6 @@ jobs: echo "before=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" echo "pin=$("$TOOLS/openshell-tags.sh" pinned)" >> "$GITHUB_OUTPUT" - - name: Install Rust - run: rustup toolchain install 1.94 --profile minimal --component rustfmt,clippy && rustup default 1.94 - - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: | @@ -118,6 +115,16 @@ jobs: -m "Automated by .github/workflows/openshell-next.yml. Upstream changes: $UPSTREAM/compare/$prev...$tag" fi + # After the merge and the bump: the toolchain is the highest rust-version of openshell-annotate and the pinned + # OpenShell crates, so a prerelease that raises its rust-version (v0.1.11-pre.2 needs 1.95) does not fail on a + # hard-coded toolchain. The merge and bump steps run `cargo update`/`cargo metadata` with the runner's + # preinstalled stable cargo. + - name: Install Rust (the version the branch needs) + run: | + tc=$("$TOOLS/openshell-next.sh" toolchain) + echo "Rust $tc (highest rust-version of openshell-annotate and the pinned OpenShell crates)" | tee -a "$GITHUB_STEP_SUMMARY" + rustup toolchain install "$tc" --profile minimal --component rustfmt,clippy && rustup default "$tc" + - name: Test (fmt, clippy, test, docs) id: test continue-on-error: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 18c3e11..cf39565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ version section and adds the squash-merged PR titles since the previous tag. Ver ## [Unreleased] +- ci(openshell-next): the tracking job installs the Rust version the branch needs, the highest `rust-version` of openshell-annotate and the pinned OpenShell crates (new `scripts/openshell-next.sh toolchain`), instead of a hard-coded 1.94, so OpenShell v0.1.11-pre.2 (Rust 1.95) builds; `sync` keeps the branch's higher `rust-version` when it resolves a pin conflict from main's `Cargo.toml` (#118) - chore(deps): build against OpenShell v0.1.10 (`openshell-policy-schema`, `openshell-policy`, commit 152c59d); docs, generated policy headers and the `diff-logs`/`--image` notes now name v0.1.10. v0.1.10 still declares `rust-version = "1.94"`, so main stays on Rust 1.94 (#113) - feat(validate): `lint --policy`, `drift` and `generate` run the offline checks of `openshell policy lint` (OpenShell v0.1.10, ai-openshell/openshell#5358): `find_endpoint_ambiguities` and `validate_and_canonicalize_authored_policy` (reserved `_provider_` keys, credential bindings, size limit) next to the gateway validator. Endpoints that match the same requests with different protocols are now an error, since a request is authorized only by endpoints using the selected route's protocol (ai-openshell/openshell#5274) (#113) - feat(validate): a YAML policy file with `endpoint_settings` (a Cedar-only section, ai-openshell/openshell#5006) is rejected by `lint --policy` and `drift` with OpenShell's message (#113) diff --git a/docs/DEVELOPING.md b/docs/DEVELOPING.md index 87f22b9..133e13f 100644 --- a/docs/DEVELOPING.md +++ b/docs/DEVELOPING.md @@ -134,11 +134,15 @@ false`), so a delayed early run is not cancelled when the later one starts; the comment) if the pin is unchanged and everything already passed. Dispatch it by hand when you need a bump now. It: 1. checks out `openshell-next` (recreating it from `main` if it was deleted) and merges `origin/main` into it with a - signed-off merge commit. If both sides changed the pin it keeps the newer tag; any other conflict stops the run - without pushing and is reported on the issue for a human to resolve; + signed-off merge commit. If both sides changed the pin it keeps the newer tag (and the branch's `rust-version` when + it is higher than main's); any other conflict stops the run without pushing and is reported on the issue for a + human to resolve; 2. moves the pin when upstream has a newer tag (`scripts/openshell-next.sh update`) and commits it as `github-actions[bot]` with a `Signed-off-by` line; -3. runs `cargo fmt --check`, clippy, `cargo test --locked` and `scripts/gen-docs.sh --check` in the same job; +3. installs the Rust version the branch needs, the highest `rust-version` of openshell-annotate and the pinned + OpenShell crates (`scripts/openshell-next.sh toolchain`; v0.1.11-pre.2 needs 1.95), and runs `cargo fmt --check`, + clippy, `cargo test --locked` and `scripts/gen-docs.sh --check` in the same job. The dispatched `ci.yml` uses the + toolchain the branch's own `ci.yml` pins; 4. pushes the branch, even when the tests fail (the branch mirrors upstream; the fix is made on top), then dispatches `ci.yml` on it, because a push with `GITHUB_TOKEN` starts no `push` workflow. The dispatched run publishes its result as the commit statuses `CI (dispatched) / check` and `CI (dispatched) / audit`, which is what the tracking PR shows. diff --git a/scripts/openshell-next.sh b/scripts/openshell-next.sh index 4f20f39..a750133 100755 --- a/scripts/openshell-next.sh +++ b/scripts/openshell-next.sh @@ -5,10 +5,13 @@ # scripts/openshell-next.sh bump # pin both OpenShell crates to in Cargo.toml and re-resolve Cargo.lock # scripts/openshell-next.sh update [] # bump to (default: newest upstream tag) only if it is newer than the pin # scripts/openshell-next.sh sync [] # merge (default origin/main) into the current branch +# scripts/openshell-next.sh toolchain # print the Rust version the checkout needs (highest rust-version of +# # openshell-annotate and the locked ai-openshell/openshell crates) # # `bump` and `update` edit files only; they never commit. `sync` creates a signed-off merge commit. When main and the # branch both changed the pin, `sync` keeps the newer of the two tags and re-resolves Cargo.lock; any other conflict -# aborts the merge (exit 3) so a human can resolve it. +# aborts the merge (exit 3) so a human can resolve it. The pin conflict is resolved from main's Cargo.toml, but a higher +# `rust-version` on the branch is kept (the branch may need a newer toolchain than main). # `update` prints `previous=`, `tag=`, `changed=` and `stable=` lines (also appended to $GITHUB_OUTPUT when set). # Env: OPENSHELL_ANNOTATE_ROOT, the checkout to work on (default: the one this script lives in). The workflow runs # main's copy of these scripts from a temp dir against the openshell-next checkout, so the branch needs no copy. @@ -51,9 +54,30 @@ update() { if "$TAGS" is-stable "$want"; then out "stable=true"; else out "stable=false"; fi } +# rust-version of the root package in Cargo.toml (empty when unset). +own_rust_version() { sed -nE 's/^rust-version[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' Cargo.toml | head -n 1; } + +# Highest of two dotted versions (either may be empty). +max_version() { printf '%s\n%s\n' "$1" "$2" | grep . | sort -V | tail -n 1; } + +# The Rust toolchain this checkout needs: the highest `rust-version` declared by openshell-annotate itself or by any +# package Cargo.lock resolves from ai-openshell/openshell. A prerelease pin can need a newer Rust than the branch +# declares yet; the tests then run on what upstream needs. Falls back to Cargo.toml when `cargo metadata` fails. +toolchain() { + local own upstream + own=$(own_rust_version) + upstream=$(cargo metadata --locked --format-version 1 2>/dev/null | + jq -r '.packages[] | select((.source // "") | startswith("git+https://github.com/ai-openshell/openshell")) | .rust_version // empty' | + sort -V | tail -n 1) || upstream="" + own=$(max_version "$own" "$upstream") + [ -n "$own" ] || { echo "no rust-version in Cargo.toml or the OpenShell crates" >&2; exit 2; } + echo "$own" +} + sync() { - local ref="${1:-origin/main}" before after bad msg + local ref="${1:-origin/main}" before after bad msg rv tmp before=$("$TAGS" pinned) + rv=$(own_rust_version) msg="Merge $ref into $(git rev-parse --abbrev-ref HEAD)" if git merge --no-ff --no-edit --signoff -m "$msg" "$ref"; then echo "merged $ref cleanly" @@ -66,6 +90,12 @@ sync() { # Both sides moved the pin: start from main's files and re-apply the newer tag. git checkout --theirs -- Cargo.toml Cargo.lock 2>/dev/null || git checkout "$ref" -- Cargo.toml Cargo.lock after=$("$TAGS" pinned) + if [ -n "$rv" ] && [ "$rv" != "$(own_rust_version)" ] && [ "$(max_version "$rv" "$(own_rust_version)")" = "$rv" ]; then + tmp=$(mktemp) + sed -E "s/^rust-version[[:space:]]*=[[:space:]]*\"[^\"]+\"/rust-version = \"$rv\"/" Cargo.toml > "$tmp" + cat "$tmp" > Cargo.toml; rm -f "$tmp" + echo "kept the branch's rust-version $rv" + fi if "$TAGS" newer "$before" "$after"; then bump "$before"; fi git add Cargo.toml Cargo.lock git commit --signoff -m "$msg" -m "Both sides changed the OpenShell pin; kept the newer tag." @@ -84,5 +114,6 @@ case "$cmd" in bump) [ $# -eq 1 ] || { echo "usage: $0 bump " >&2; exit 2; }; bump "$1" ;; update) update "${1:-}" ;; sync) sync "${1:-}" ;; - *) sed -n '2,13p' "$0" | sed 's/^# \{0,1\}//' >&2; exit 2 ;; + toolchain) toolchain ;; + *) sed -n '2,17p' "$0" | sed 's/^# \{0,1\}//' >&2; exit 2 ;; esac