From b83a55244f4add000f3d83a305723893ce4b0321 Mon Sep 17 00:00:00 2001 From: Moulik Aggarwal Date: Sat, 1 Aug 2026 16:06:55 +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 | 62 +++++++++++++------------------------ scripts/regen.sh | 8 ++--- 2 files changed, 24 insertions(+), 46 deletions(-) diff --git a/.github/workflows/regen.yml b/.github/workflows/regen.yml index 5dfe781..1628aea 100644 --- a/.github/workflows/regen.yml +++ b/.github/workflows/regen.yml @@ -36,74 +36,54 @@ jobs: env: OVERRIDE: ${{ github.event.inputs.commit }} run: | + resolved="$(buf registry module commit resolve \ + buf.build/openstatus/api:main --format json)" + commit="$(printf '%s' "$resolved" | jq -r '.commit')" + source_url="$(printf '%s' "$resolved" | jq -r '.source_control_url')" + if [ -n "$OVERRIDE" ]; then commit="$OVERRIDE" - else - version="$(buf registry sdk version \ - --module=buf.build/openstatus/api \ - --plugin=buf.build/protocolbuffers/python)" - commit="${version##*+}" - [ "$commit" = "$version" ] && commit="" fi - if [ -z "$commit" ]; then + + if [ -z "$commit" ] || [ "$commit" = "null" ]; then echo "::error::schema commit discovery returned empty" exit 1 fi - echo "commit=$commit" >> "$GITHUB_OUTPUT" - - name: Decide whether to regen - id: check - env: - RESOLVED: ${{ steps.schema.outputs.commit }} - OVERRIDE: ${{ github.event.inputs.commit }} - run: | - vendored="$(sed -n 's|^readonly BUF_SCHEMA_COMMIT="\(.*\)"$|\1|p' scripts/regen.sh)" - if [ -n "$OVERRIDE" ] || [ "$vendored" != "$RESOLVED" ]; then - echo "changed=true" >> "$GITHUB_OUTPUT" - else - echo "changed=false" >> "$GITHUB_OUTPUT" - echo "schema commit $vendored unchanged; nothing to do" - fi + echo "commit=$commit" >> "$GITHUB_OUTPUT" + echo "source_control_url=$source_url" >> "$GITHUB_OUTPUT" - - name: Record resolved schema commit - if: steps.check.outputs.changed == 'true' + - name: Run regen env: RESOLVED: ${{ steps.schema.outputs.commit }} - run: | - sed -i "s|^readonly BUF_SCHEMA_COMMIT=.*|readonly BUF_SCHEMA_COMMIT=\"${RESOLVED}\"|" scripts/regen.sh - - - name: Run regen - if: steps.check.outputs.changed == 'true' - run: bash scripts/regen.sh + run: bash scripts/regen.sh "$RESOLVED" - name: Install dependencies - if: steps.check.outputs.changed == 'true' run: composer install --prefer-dist --no-progress --no-interaction - name: Static analysis - if: steps.check.outputs.changed == 'true' run: composer analyse - name: Unit tests - if: steps.check.outputs.changed == 'true' run: composer test -- --testsuite unit - name: Open PR if anything changed - if: steps.check.outputs.changed == 'true' uses: peter-evans/create-pull-request@v6 with: token: ${{ secrets.SDK_BOT_TOKEN || github.token }} - commit-message: 'chore: regen src/Gen from buf archive' - title: 'chore: regen src/Gen from buf archive' + commit-message: 'chore: regen src/Gen from schema commit ${{ steps.schema.outputs.commit }}' + title: 'chore: regen src/Gen from schema commit ${{ steps.schema.outputs.commit }}' body: | Automated regen of the Buf-generated PHP archive. - Schema commit `${{ steps.schema.outputs.commit }}` (resolved from - `buf.build/openstatus/api`) differs from the `BUF_SCHEMA_COMMIT` - marker vendored in `scripts/regen.sh`. + Schema commit `${{ steps.schema.outputs.commit }}` resolved from + `buf.build/openstatus/api:main`. + + Source: ${{ steps.schema.outputs.source_control_url }} - `scripts/regen.sh` fetches the archive from the `main` label, so - `src/Gen` below is generated from that commit. Trigger this workflow - manually with a `commit` input to force a regen. + `scripts/regen.sh` fetches the archive from the `main` label and + writes the resolved commit to `src/Gen/VERSION`. Trigger this + workflow manually with a `commit` input to override the resolved + value. branch: regen/auto-bump delete-branch: true diff --git a/scripts/regen.sh b/scripts/regen.sh index 3edef81..c8bad24 100755 --- a/scripts/regen.sh +++ b/scripts/regen.sh @@ -1,9 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -# BSR commit the vendored code was generated from. The archive is fetched by -# label, so this is the only marker cron can diff to detect schema movement. -readonly BUF_SCHEMA_COMMIT="7d7b7047611f" +SCHEMA_COMMIT="${1:?usage: regen.sh }" URL="https://buf.build/gen/archive/openstatus/api/protocolbuffers/php/main.zip" @@ -19,6 +17,6 @@ mkdir -p "$ROOT/src/Gen" mv "$TMP/api_php/Openstatus" "$ROOT/src/Gen/Openstatus" mv "$TMP/api_php/GPBMetadata" "$ROOT/src/Gen/GPBMetadata" -echo "${BUF_SCHEMA_COMMIT}" > "$ROOT/src/Gen/VERSION" +echo "${SCHEMA_COMMIT}" > "$ROOT/src/Gen/VERSION" -echo "Regenerated src/Gen from ${BUF_SCHEMA_COMMIT}" +echo "Regenerated src/Gen from ${SCHEMA_COMMIT}" -- 2.51.2