From 11a82b81b70093ebe072ea0a8d44b6c4afa6b34a Mon Sep 17 00:00:00 2001 From: Moulik Aggarwal Date: Sat, 1 Aug 2026 16:06:51 +0530 Subject: [PATCH] refactor: resolve schema commit from BSR instead of a hand-seeded marker Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0173tbY2QAvy8Sw2uVuHV4SP --- .github/workflows/regen.yml | 53 +++++++++++++++---------------------- scripts/regen.sh | 7 +++-- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/.github/workflows/regen.yml b/.github/workflows/regen.yml index b5a614d..a3d11cc 100644 --- a/.github/workflows/regen.yml +++ b/.github/workflows/regen.yml @@ -20,38 +20,29 @@ jobs: with: setup_only: true - - name: Discover latest schema commit - id: latest + - name: Resolve schema commit + id: schema run: | - current=$(grep -E 'readonly BUF_SCHEMA_COMMIT="' scripts/regen.sh \ - | sed -E 's/.*="([^"]+)".*/\1/') - echo "current=$current" >> "$GITHUB_OUTPUT" - # Version string looks like 35.1.0.1.20260727085848+65e5c3248a1e; - # the commit suffix is the only coordinate shared across languages. - version=$(buf registry sdk version \ - --module=buf.build/openstatus/api \ - --plugin=buf.build/protocolbuffers/python) - latest="${version##*+}" - if [[ -z "$latest" || "$latest" == "$version" ]]; then - echo "::error::schema version discovery returned empty" + json=$(buf registry module commit resolve \ + buf.build/openstatus/api:main --format json) + commit=$(jq -r '.commit' <<< "$json") + source_url=$(jq -r '.source_control_url' <<< "$json") + if [[ -z "$commit" || "$commit" == "null" ]]; then + echo "::error::schema commit resolution returned empty" exit 1 fi - echo "latest=$latest" >> "$GITHUB_OUTPUT" + echo "commit=$commit" >> "$GITHUB_OUTPUT" + echo "source_url=$source_url" >> "$GITHUB_OUTPUT" - - name: No-op when already up to date - if: steps.latest.outputs.latest == steps.latest.outputs.current - run: echo "Already on ${{ steps.latest.outputs.current }}; nothing to do." - - - name: Bump pin and regenerate - if: steps.latest.outputs.latest != steps.latest.outputs.current - run: | - sed -i -E "s/(readonly BUF_SCHEMA_COMMIT=)\"[^\"]+\"/\1\"${{ steps.latest.outputs.latest }}\"/" \ - scripts/regen.sh - bash scripts/regen.sh + - name: Regenerate + run: bash scripts/regen.sh "${{ steps.schema.outputs.commit }}" - name: Bump patch version - if: steps.latest.outputs.latest != steps.latest.outputs.current run: | + if git diff --quiet -- src/openstatus/_gen; then + echo "no schema change; skipping version bump" + exit 0 + fi cur=$(grep -oP '^version = "\K[^"]+' pyproject.toml) IFS=. read -r maj min pat <<< "$cur" next="$maj.$min.$((pat + 1))" @@ -59,14 +50,14 @@ jobs: echo "bumped $cur -> $next" - name: Open PR - if: steps.latest.outputs.latest != steps.latest.outputs.current uses: peter-evans/create-pull-request@v6 with: token: ${{ secrets.SDK_BOT_TOKEN || github.token }} - branch: regen/${{ steps.latest.outputs.latest }} - commit-message: "chore: bump buf schema to ${{ steps.latest.outputs.latest }}" - title: "chore: bump buf schema to ${{ steps.latest.outputs.latest }}" + branch: regen/${{ steps.schema.outputs.commit }} + commit-message: "chore: bump buf schema to ${{ steps.schema.outputs.commit }}" + title: "chore: bump buf schema to ${{ steps.schema.outputs.commit }}" body: | Automated regeneration from `buf.build/openstatus/api` schema - commit `${{ steps.latest.outputs.current }}` to - `${{ steps.latest.outputs.latest }}`. + commit `${{ steps.schema.outputs.commit }}`. + + Source: ${{ steps.schema.outputs.source_url }} diff --git a/scripts/regen.sh b/scripts/regen.sh index 715eae9..418a739 100755 --- a/scripts/regen.sh +++ b/scripts/regen.sh @@ -1,11 +1,10 @@ #!/usr/bin/env bash set -euo pipefail -# Schema commit of buf.build/openstatus/api that this tree was generated from. -# Change-detection marker only — the archive itself is fetched by the `main` +# Recorded in $DEST/VERSION only — the archive itself is fetched by the `main` # label, since the archive URL uses a plugin-version coordinate that cannot be # reconstructed from the commit alone. -readonly BUF_SCHEMA_COMMIT="7d7b7047611f" +SCHEMA_COMMIT="${1:?usage: regen.sh }" # Transitive deps. Buf does not expose pinned versions for these from the # openstatus/api module, so we track main. The PHP plan ships empty initOnce() @@ -80,7 +79,7 @@ find "$DEST" -type f \( -name '*.py' -o -name '*.pyi' \) -print0 \ # Generated trees ship no __init__.py — create empty shims so packages import. find "$DEST" -type d -exec sh -c 'touch "$0/__init__.py"' {} \; -echo "${BUF_SCHEMA_COMMIT}" > "$DEST/VERSION" +echo "${SCHEMA_COMMIT}" > "$DEST/VERSION" echo echo "Done. Generated tree at $DEST" -- 2.51.2