Skip to content

Commit 5ea3281

Browse files
authored
fix(ci): update existing schema-regen PRs with changeset (#163)
* 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. * 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
1 parent fc77e24 commit 5ea3281

2 files changed

Lines changed: 60 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'scope3': patch
3+
---
4+
5+
Update schema regeneration workflow to push changeset and schema changes to existing open PRs instead of skipping them

.github/workflows/regenerate-schemas.yml

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ jobs:
5151
env:
5252
GH_TOKEN: ${{ steps.app-token.outputs.token }}
5353
run: |
54-
EXISTING=$(gh pr list --search 'chore: regenerate schemas in:title' --state open --json number --jq 'length')
55-
echo "count=$EXISTING" >> $GITHUB_OUTPUT
54+
PR_JSON=$(gh pr list --search 'chore: regenerate schemas in:title' --state open --json number,headRefName,url --jq '.[0] // empty')
55+
if [ -n "$PR_JSON" ]; then
56+
echo "count=1" >> $GITHUB_OUTPUT
57+
echo "branch=$(echo "$PR_JSON" | jq -r '.headRefName')" >> $GITHUB_OUTPUT
58+
echo "url=$(echo "$PR_JSON" | jq -r '.url')" >> $GITHUB_OUTPUT
59+
else
60+
echo "count=0" >> $GITHUB_OUTPUT
61+
fi
5662
5763
- name: Create PR
5864
if: steps.changes.outputs.has_changes == 'true' && steps.existing-pr.outputs.count == '0'
@@ -97,8 +103,52 @@ jobs:
97103
98104
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
99105
106+
- name: Update existing PR
107+
if: steps.changes.outputs.has_changes == 'true' && steps.existing-pr.outputs.count == '1'
108+
id: update-pr
109+
env:
110+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
111+
run: |
112+
BRANCH="${{ steps.existing-pr.outputs.branch }}"
113+
if [ -z "$BRANCH" ]; then
114+
echo "::error::Could not resolve existing PR branch name"
115+
exit 1
116+
fi
117+
118+
git config user.name "scope3-wizard[bot]"
119+
git config user.email "${{ vars.SCOPE3_WIZARD_APP_ID }}+scope3-wizard[bot]@users.noreply.github.com"
120+
121+
git fetch origin "$BRANCH"
122+
git checkout -B "$BRANCH" "origin/$BRANCH"
123+
124+
npm run generate-schemas
125+
126+
git add src/schemas/
127+
128+
EXISTING_CHANGESET=$(find .changeset -name 'regenerate-schemas-*.md' -maxdepth 1 2>/dev/null | head -1)
129+
if [ -z "$EXISTING_CHANGESET" ]; then
130+
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
131+
CHANGESET_FILE=".changeset/regenerate-schemas-${TIMESTAMP}.md"
132+
cat > "$CHANGESET_FILE" <<'EOF'
133+
---
134+
'scope3': minor
135+
---
136+
137+
Regenerate Zod schemas from the latest OpenAPI specification
138+
EOF
139+
git add "$CHANGESET_FILE"
140+
fi
141+
142+
if git diff --cached --quiet; then
143+
echo "No new changes to commit"
144+
else
145+
git commit -m "chore: regenerate schemas from OpenAPI spec"
146+
git push origin "$BRANCH"
147+
echo "pr_url=${{ steps.existing-pr.outputs.url }}" >> $GITHUB_OUTPUT
148+
fi
149+
100150
- name: Notify Slack
101-
if: steps.create-pr.outputs.pr_url
151+
if: steps.create-pr.outputs.pr_url || steps.update-pr.outputs.pr_url
102152
uses: ./.github/actions/slack-post
103153
env:
104154
SLACK_TOKEN: ${{ secrets.SLACK_NOTIF_BOT_TOKEN }}
@@ -107,8 +157,8 @@ jobs:
107157
header: 'SDK Schemas Regenerated'
108158
content: |
109159
[
110-
{"type": "section", "text": {"type": "mrkdwn", "text": "A PR has been created to update Zod schemas from the latest OpenAPI specification."}},
111-
{"type": "section", "text": {"type": "mrkdwn", "text": "<${{ steps.create-pr.outputs.pr_url }}|View Pull Request>"}}
160+
{"type": "section", "text": {"type": "mrkdwn", "text": "A PR has been created or updated to regenerate Zod schemas from the latest OpenAPI specification."}},
161+
{"type": "section", "text": {"type": "mrkdwn", "text": "<${{ steps.create-pr.outputs.pr_url || steps.update-pr.outputs.pr_url }}|View Pull Request>"}}
112162
]
113163
114164
- name: Notify on failure

0 commit comments

Comments
 (0)