Fold openapi.json auto-sync into main CI test job

The separate openapi-sync workflow was duplicating the workspace build
(~15 min cold-cache compile), paying the cost twice per PR. Fold the
regen + auto-commit into the existing test job: one compile, shared
rust-cache, same drift-check semantics.

- Same-repo PRs: OMNIGRAPH_UPDATE_OPENAPI=1 during the test run, then
  commit the regenerated spec back to the PR branch
- Fork PRs / pushes: env var empty, test stays in strict drift-check mode
- openapi_spec_is_up_to_date treats empty env value as unset, so the
  conditional workflow env expression works

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ragnor Comerford 2026-04-18 21:00:46 +02:00
parent 9de2079263
commit a157f6a17c
No known key found for this signature in database
3 changed files with 42 additions and 64 deletions

View file

@ -105,7 +105,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
permissions:
contents: read
contents: write
env:
CARGO_TERM_COLOR: always
steps:
@ -113,8 +113,22 @@ jobs:
if: needs.classify_changes.outputs.run_full_ci != 'true'
run: echo "Text-only change detected; skipping workspace test run."
- name: Checkout source
if: needs.classify_changes.outputs.run_full_ci == 'true'
# For same-repo PRs, check out the PR branch head directly so we can push
# a regenerated openapi.json back to it. Fork PRs and push events use the
# default checkout (which is read-only for our purposes).
- name: Checkout (same-repo PR head)
if: |
needs.classify_changes.outputs.run_full_ci == 'true' &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
uses: actions/checkout@v5.0.1
with:
ref: ${{ github.head_ref }}
- name: Checkout (default)
if: |
needs.classify_changes.outputs.run_full_ci == 'true' &&
!(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
uses: actions/checkout@v5.0.1
- name: Install system dependencies
@ -138,8 +152,29 @@ jobs:
- name: Run workspace tests
if: needs.classify_changes.outputs.run_full_ci == 'true'
# On same-repo PRs, regenerate openapi.json as part of the drift test
# so the following step can commit the update. Elsewhere the env var
# is empty, leaving the drift test in strict-check mode.
env:
OMNIGRAPH_UPDATE_OPENAPI: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) && '1' || '' }}
run: cargo test --workspace --locked
- name: Commit regenerated openapi.json
if: |
needs.classify_changes.outputs.run_full_ci == 'true' &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
run: |
if git diff --quiet -- openapi.json; then
echo "openapi.json is already in sync."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add openapi.json
git commit -m "chore: regenerate openapi.json"
git push
test_aws_feature:
name: Test omnigraph-server --features aws
needs: classify_changes

View file

@ -1,60 +0,0 @@
name: Sync OpenAPI
on:
pull_request:
paths:
- "crates/omnigraph-server/src/**"
- "crates/omnigraph-server/Cargo.toml"
- "crates/omnigraph-server/tests/openapi.rs"
concurrency:
group: openapi-sync-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
jobs:
sync:
name: Regenerate openapi.json
# Auto-commit only on same-repo PRs; forks cannot be pushed to.
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout PR branch
uses: actions/checkout@v5.0.1
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler libprotobuf-dev
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust build data
uses: Swatinem/rust-cache@v2
with:
workspaces: |
. -> target
- name: Regenerate openapi.json
run: |
OMNIGRAPH_UPDATE_OPENAPI=1 \
cargo test --locked -p omnigraph-server --test openapi openapi_spec_is_up_to_date
- name: Commit if changed
run: |
if git diff --quiet -- openapi.json; then
echo "openapi.json is already in sync."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add openapi.json
git commit -m "chore: regenerate openapi.json"
git push

View file

@ -971,7 +971,10 @@ fn openapi_spec_is_up_to_date() {
let generated = serde_json::to_string_pretty(&openapi_doc()).unwrap() + "\n";
if env::var("OMNIGRAPH_UPDATE_OPENAPI").is_ok() {
if !env::var("OMNIGRAPH_UPDATE_OPENAPI")
.unwrap_or_default()
.is_empty()
{
fs::write(&spec_path, &generated).unwrap();
return;
}