Skip to content

Commit 28fb323

Browse files
vdusekclaude
andcommitted
ci: trigger Python client model regeneration on OpenAPI spec changes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 04d4945 commit 28fb323

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

.github/workflows/openapi-ci.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ name: OpenAPI checks
22

33
on:
44
pull_request:
5+
# The 'closed' type is needed to trigger cleanup of the corresponding apify-client-python PR.
6+
types: [opened, synchronize, reopened, closed]
57
push:
68
branches:
79
- master
810

11+
permissions:
12+
contents: read
13+
914
jobs:
1015
lint:
1116
name: Lint specification
17+
# Skip lint/build/validate on PR close events - those only need the cleanup job.
18+
if: github.event_name != 'pull_request' || github.event.action != 'closed'
1219
runs-on: ubuntu-latest
1320

1421
steps:
@@ -114,3 +121,68 @@ jobs:
114121
exit 1
115122
fi
116123
echo "✓ Bundles have valid sizes"
124+
125+
# When a PR changes OpenAPI specs and passes validation, trigger model regeneration in apify-client-python
126+
# so the Python client stays in sync with the API spec.
127+
trigger-client-model-regeneration:
128+
name: Trigger Python client model regeneration
129+
runs-on: ubuntu-latest
130+
needs: [validate]
131+
if: >-
132+
github.event_name == 'pull_request'
133+
&& github.event.action != 'closed'
134+
&& github.event.pull_request.head.repo.full_name == github.repository
135+
136+
steps:
137+
- uses: actions/checkout@v6
138+
139+
- name: Check if OpenAPI files changed
140+
id: changed-files
141+
uses: tj-actions/changed-files@v47
142+
with:
143+
files: 'apify-api/openapi/**'
144+
145+
- name: Trigger apify-client-python model regeneration
146+
if: steps.changed-files.outputs.any_changed == 'true'
147+
env:
148+
GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
149+
PR_NUMBER: ${{ github.event.pull_request.number }}
150+
PR_SHA: ${{ github.event.pull_request.head.sha }}
151+
run: |
152+
gh workflow run regenerate_models.yaml \
153+
--repo apify/apify-client-python \
154+
--field docs_pr_number="$PR_NUMBER" \
155+
--field docs_pr_sha="$PR_SHA"
156+
157+
# When a docs PR is closed (merged or abandoned), clean up the corresponding auto-generated PR
158+
# in apify-client-python to avoid stale PRs piling up.
159+
cleanup-client-model-pr:
160+
name: Close Python client model PR on docs PR close
161+
runs-on: ubuntu-latest
162+
if: >-
163+
github.event_name == 'pull_request'
164+
&& github.event.action == 'closed'
165+
166+
steps:
167+
- name: Close corresponding apify-client-python PR
168+
env:
169+
GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
170+
PR_NUMBER: ${{ github.event.pull_request.number }}
171+
# Branch name convention must match what regenerate_models.yaml creates.
172+
run: |
173+
BRANCH="chore/update-models-docs-pr-${PR_NUMBER}"
174+
EXISTING_PR=$(gh pr list \
175+
--repo apify/apify-client-python \
176+
--head "$BRANCH" \
177+
--json number \
178+
--jq '.[0].number' 2>/dev/null || true)
179+
180+
if [ -n "$EXISTING_PR" ]; then
181+
gh pr close "$EXISTING_PR" \
182+
--repo apify/apify-client-python \
183+
--delete-branch \
184+
--comment "Closing this PR because the source apify-docs PR #${PR_NUMBER} was closed."
185+
echo "Closed apify-client-python PR #$EXISTING_PR"
186+
else
187+
echo "No corresponding apify-client-python PR found for branch $BRANCH"
188+
fi

0 commit comments

Comments
 (0)