From d614f8076cf895e2f15cac981371b0d25107cb16 Mon Sep 17 00:00:00 2001 From: Ben Miner Date: Mon, 27 Apr 2026 14:46:25 -0500 Subject: [PATCH 1/2] fix(ci): update existing schema-regen PRs with changeset When an open schema-regeneration PR already exists, the workflow skipped it entirely. PRs created before the changeset requirement (like #156) are permanently blocked because they lack a changeset and the workflow never updates them. Add an "Update existing PR" path that checks out the existing branch, re-runs schema generation, adds a changeset if missing, and pushes. --- .changeset/update-existing-schema-pr.md | 5 ++ .github/workflows/regenerate-schemas.yml | 61 ++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 .changeset/update-existing-schema-pr.md diff --git a/.changeset/update-existing-schema-pr.md b/.changeset/update-existing-schema-pr.md new file mode 100644 index 0000000..51d2cf6 --- /dev/null +++ b/.changeset/update-existing-schema-pr.md @@ -0,0 +1,5 @@ +--- +'scope3': patch +--- + +Update schema regeneration workflow to push changeset and schema changes to existing open PRs instead of skipping them diff --git a/.github/workflows/regenerate-schemas.yml b/.github/workflows/regenerate-schemas.yml index 2119a02..d383094 100644 --- a/.github/workflows/regenerate-schemas.yml +++ b/.github/workflows/regenerate-schemas.yml @@ -51,8 +51,14 @@ jobs: env: GH_TOKEN: ${{ steps.app-token.outputs.token }} run: | - EXISTING=$(gh pr list --search 'chore: regenerate schemas in:title' --state open --json number --jq 'length') - echo "count=$EXISTING" >> $GITHUB_OUTPUT + PR_JSON=$(gh pr list --search 'chore: regenerate schemas in:title' --state open --json number,headRefName,url --jq '.[0] // empty') + if [ -n "$PR_JSON" ]; then + echo "count=1" >> $GITHUB_OUTPUT + echo "branch=$(echo "$PR_JSON" | jq -r '.headRefName')" >> $GITHUB_OUTPUT + echo "url=$(echo "$PR_JSON" | jq -r '.url')" >> $GITHUB_OUTPUT + else + echo "count=0" >> $GITHUB_OUTPUT + fi - name: Create PR if: steps.changes.outputs.has_changes == 'true' && steps.existing-pr.outputs.count == '0' @@ -97,8 +103,53 @@ jobs: echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT + - name: Update existing PR + if: steps.changes.outputs.has_changes == 'true' && steps.existing-pr.outputs.count == '1' + id: update-pr + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + run: | + BRANCH="${{ steps.existing-pr.outputs.branch }}" + if [ -z "$BRANCH" ]; then + echo "::error::Could not resolve existing PR branch name" + exit 1 + fi + + git config user.name "scope3-wizard[bot]" + git config user.email "${{ vars.SCOPE3_WIZARD_APP_ID }}+scope3-wizard[bot]@users.noreply.github.com" + + git fetch origin "$BRANCH" + git checkout -b "$BRANCH" "origin/$BRANCH" + + npm run generate-schemas + + git add src/schemas/ + + EXISTING_CHANGESET=$(find .changeset -name 'regenerate-schemas-*.md' -maxdepth 1 2>/dev/null | head -1) + if [ -z "$EXISTING_CHANGESET" ]; then + TIMESTAMP=$(date +%Y%m%d-%H%M%S) + CHANGESET_FILE=".changeset/regenerate-schemas-${TIMESTAMP}.md" + cat > "$CHANGESET_FILE" <<'EOF' + --- + 'scope3': minor + --- + + Regenerate Zod schemas from the latest OpenAPI specification + EOF + git add "$CHANGESET_FILE" + fi + + if git diff --cached --quiet; then + echo "No new changes to commit" + else + git commit -m "chore: regenerate schemas from OpenAPI spec" + git push origin "$BRANCH" + fi + + echo "pr_url=${{ steps.existing-pr.outputs.url }}" >> $GITHUB_OUTPUT + - name: Notify Slack - if: steps.create-pr.outputs.pr_url + if: steps.create-pr.outputs.pr_url || steps.update-pr.outputs.pr_url uses: ./.github/actions/slack-post env: SLACK_TOKEN: ${{ secrets.SLACK_NOTIF_BOT_TOKEN }} @@ -107,8 +158,8 @@ jobs: header: 'SDK Schemas Regenerated' content: | [ - {"type": "section", "text": {"type": "mrkdwn", "text": "A PR has been created to update Zod schemas from the latest OpenAPI specification."}}, - {"type": "section", "text": {"type": "mrkdwn", "text": "<${{ steps.create-pr.outputs.pr_url }}|View Pull Request>"}} + {"type": "section", "text": {"type": "mrkdwn", "text": "A PR has been created or updated to regenerate Zod schemas from the latest OpenAPI specification."}}, + {"type": "section", "text": {"type": "mrkdwn", "text": "<${{ steps.create-pr.outputs.pr_url || steps.update-pr.outputs.pr_url }}|View Pull Request>"}} ] - name: Notify on failure From cec35094afdb2fd03c229b845ac5606ff697c409 Mon Sep 17 00:00:00 2001 From: Ben Miner Date: Mon, 27 Apr 2026 14:59:31 -0500 Subject: [PATCH 2/2] fix(ci): address review feedback on update-existing-PR step - Use git checkout -B (force-reset) to tolerate pre-existing local branch - Only set pr_url output when a commit is actually pushed --- .github/workflows/regenerate-schemas.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/regenerate-schemas.yml b/.github/workflows/regenerate-schemas.yml index d383094..7353ba6 100644 --- a/.github/workflows/regenerate-schemas.yml +++ b/.github/workflows/regenerate-schemas.yml @@ -119,7 +119,7 @@ jobs: git config user.email "${{ vars.SCOPE3_WIZARD_APP_ID }}+scope3-wizard[bot]@users.noreply.github.com" git fetch origin "$BRANCH" - git checkout -b "$BRANCH" "origin/$BRANCH" + git checkout -B "$BRANCH" "origin/$BRANCH" npm run generate-schemas @@ -144,10 +144,9 @@ jobs: else git commit -m "chore: regenerate schemas from OpenAPI spec" git push origin "$BRANCH" + echo "pr_url=${{ steps.existing-pr.outputs.url }}" >> $GITHUB_OUTPUT fi - echo "pr_url=${{ steps.existing-pr.outputs.url }}" >> $GITHUB_OUTPUT - - name: Notify Slack if: steps.create-pr.outputs.pr_url || steps.update-pr.outputs.pr_url uses: ./.github/actions/slack-post