@@ -2,13 +2,21 @@ name: OpenAPI checks
22
33on :
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+ pull-requests : read
14+
915jobs :
1016 lint :
1117 name : Lint specification
18+ # Skip lint/build/validate on PR close events - those only need the cleanup job.
19+ if : github.event_name != 'pull_request' || github.event.action != 'closed'
1220 runs-on : ubuntu-latest
1321
1422 steps :
@@ -109,8 +117,73 @@ jobs:
109117 echo "Bundle sizes:"
110118 echo " JSON: $JSON_SIZE bytes"
111119 echo " YAML: $YAML_SIZE bytes"
112- if [ "$JSON_SIZE" -lt 1000 ] || [ "$YAML_SIZE" -lt 1000 ]; then
120+ if [[ "$JSON_SIZE" -lt 1000 ]] || [[ "$YAML_SIZE" -lt 1000 ] ]; then
113121 echo "Error: Bundle files are suspiciously small"
114122 exit 1
115123 fi
116124 echo "✓ Bundles have valid sizes"
125+
126+ # When a PR changes OpenAPI specs and passes validation, trigger model regeneration in apify-client-python
127+ # so the Python client stays in sync with the API spec.
128+ trigger-client-model-regeneration :
129+ name : Trigger Python client model regeneration
130+ runs-on : ubuntu-latest
131+ needs : [validate]
132+ if : >-
133+ github.event_name == 'pull_request'
134+ && github.event.action != 'closed'
135+ && github.event.pull_request.head.repo.full_name == github.repository
136+
137+ steps :
138+ - uses : actions/checkout@v6
139+
140+ - name : Check if OpenAPI files changed
141+ id : changed-files
142+ uses : tj-actions/changed-files@v47
143+ with :
144+ files : ' apify-api/openapi/**'
145+
146+ - name : Trigger apify-client-python model regeneration
147+ if : steps.changed-files.outputs.any_changed == 'true'
148+ env :
149+ GITHUB_TOKEN : ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
150+ PR_NUMBER : ${{ github.event.pull_request.number }}
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_workflow_run_id="${{ github.run_id }}"
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+ && github.event.pull_request.head.repo.full_name == github.repository
166+
167+ steps :
168+ - name : Close corresponding apify-client-python PR
169+ env :
170+ GITHUB_TOKEN : ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
171+ PR_NUMBER : ${{ github.event.pull_request.number }}
172+ # Branch name convention must match what regenerate_models.yaml creates.
173+ run : |
174+ BRANCH="update-models-docs-pr-${PR_NUMBER}"
175+ EXISTING_PR=$(gh pr list \
176+ --repo apify/apify-client-python \
177+ --head "$BRANCH" \
178+ --json number \
179+ --jq '.[0].number // empty' 2>/dev/null || true)
180+
181+ if [[ -n "$EXISTING_PR" ]]; then
182+ gh pr close "$EXISTING_PR" \
183+ --repo apify/apify-client-python \
184+ --delete-branch \
185+ --comment "Closing this PR because the source apify-docs PR #${PR_NUMBER} was closed."
186+ echo "Closed apify-client-python PR #$EXISTING_PR"
187+ else
188+ echo "No corresponding apify-client-python PR found for branch $BRANCH"
189+ fi
0 commit comments