From 28fb3239007f9f031e813e10b44b58908417fae4 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Tue, 31 Mar 2026 12:29:54 +0200 Subject: [PATCH 1/4] ci: trigger Python client model regeneration on OpenAPI spec changes Co-Authored-By: Claude Opus 4.6 --- .github/workflows/openapi-ci.yaml | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/.github/workflows/openapi-ci.yaml b/.github/workflows/openapi-ci.yaml index a88d3112cd..09230e87dd 100644 --- a/.github/workflows/openapi-ci.yaml +++ b/.github/workflows/openapi-ci.yaml @@ -2,13 +2,20 @@ name: OpenAPI checks on: pull_request: + # The 'closed' type is needed to trigger cleanup of the corresponding apify-client-python PR. + types: [opened, synchronize, reopened, closed] push: branches: - master +permissions: + contents: read + jobs: lint: name: Lint specification + # Skip lint/build/validate on PR close events - those only need the cleanup job. + if: github.event_name != 'pull_request' || github.event.action != 'closed' runs-on: ubuntu-latest steps: @@ -114,3 +121,68 @@ jobs: exit 1 fi echo "✓ Bundles have valid sizes" + + # When a PR changes OpenAPI specs and passes validation, trigger model regeneration in apify-client-python + # so the Python client stays in sync with the API spec. + trigger-client-model-regeneration: + name: Trigger Python client model regeneration + runs-on: ubuntu-latest + needs: [validate] + if: >- + github.event_name == 'pull_request' + && github.event.action != 'closed' + && github.event.pull_request.head.repo.full_name == github.repository + + steps: + - uses: actions/checkout@v6 + + - name: Check if OpenAPI files changed + id: changed-files + uses: tj-actions/changed-files@v47 + with: + files: 'apify-api/openapi/**' + + - name: Trigger apify-client-python model regeneration + if: steps.changed-files.outputs.any_changed == 'true' + env: + GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_SHA: ${{ github.event.pull_request.head.sha }} + run: | + gh workflow run regenerate_models.yaml \ + --repo apify/apify-client-python \ + --field docs_pr_number="$PR_NUMBER" \ + --field docs_pr_sha="$PR_SHA" + + # When a docs PR is closed (merged or abandoned), clean up the corresponding auto-generated PR + # in apify-client-python to avoid stale PRs piling up. + cleanup-client-model-pr: + name: Close Python client model PR on docs PR close + runs-on: ubuntu-latest + if: >- + github.event_name == 'pull_request' + && github.event.action == 'closed' + + steps: + - name: Close corresponding apify-client-python PR + env: + GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + # Branch name convention must match what regenerate_models.yaml creates. + run: | + BRANCH="chore/update-models-docs-pr-${PR_NUMBER}" + EXISTING_PR=$(gh pr list \ + --repo apify/apify-client-python \ + --head "$BRANCH" \ + --json number \ + --jq '.[0].number' 2>/dev/null || true) + + if [ -n "$EXISTING_PR" ]; then + gh pr close "$EXISTING_PR" \ + --repo apify/apify-client-python \ + --delete-branch \ + --comment "Closing this PR because the source apify-docs PR #${PR_NUMBER} was closed." + echo "Closed apify-client-python PR #$EXISTING_PR" + else + echo "No corresponding apify-client-python PR found for branch $BRANCH" + fi From a2a5e67df37194863080e1be5f8f3c7d957c24c1 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Wed, 1 Apr 2026 16:38:08 +0200 Subject: [PATCH 2/4] fix: rename auto-generated branch and drop chore prefix Co-Authored-By: Claude Opus 4.6 (1M context) --- .github/workflows/openapi-ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/openapi-ci.yaml b/.github/workflows/openapi-ci.yaml index 09230e87dd..65418bf52b 100644 --- a/.github/workflows/openapi-ci.yaml +++ b/.github/workflows/openapi-ci.yaml @@ -170,7 +170,7 @@ jobs: PR_NUMBER: ${{ github.event.pull_request.number }} # Branch name convention must match what regenerate_models.yaml creates. run: | - BRANCH="chore/update-models-docs-pr-${PR_NUMBER}" + BRANCH="update-models-docs-pr-${PR_NUMBER}" EXISTING_PR=$(gh pr list \ --repo apify/apify-client-python \ --head "$BRANCH" \ From 4055e3d164ea60213d0d94f70612199bf345c255 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Thu, 2 Apr 2026 13:54:43 +0200 Subject: [PATCH 3/4] Address feedback --- .github/workflows/openapi-ci.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/openapi-ci.yaml b/.github/workflows/openapi-ci.yaml index 65418bf52b..e1d86fbcc3 100644 --- a/.github/workflows/openapi-ci.yaml +++ b/.github/workflows/openapi-ci.yaml @@ -10,6 +10,7 @@ on: permissions: contents: read + pull-requests: read jobs: lint: @@ -116,7 +117,7 @@ jobs: echo "Bundle sizes:" echo " JSON: $JSON_SIZE bytes" echo " YAML: $YAML_SIZE bytes" - if [ "$JSON_SIZE" -lt 1000 ] || [ "$YAML_SIZE" -lt 1000 ]; then + if [[ "$JSON_SIZE" -lt 1000 ]] || [[ "$YAML_SIZE" -lt 1000 ]]; then echo "Error: Bundle files are suspiciously small" exit 1 fi @@ -162,6 +163,7 @@ jobs: if: >- github.event_name == 'pull_request' && github.event.action == 'closed' + && github.event.pull_request.head.repo.full_name == github.repository steps: - name: Close corresponding apify-client-python PR @@ -175,9 +177,9 @@ jobs: --repo apify/apify-client-python \ --head "$BRANCH" \ --json number \ - --jq '.[0].number' 2>/dev/null || true) + --jq '.[0].number // empty' 2>/dev/null || true) - if [ -n "$EXISTING_PR" ]; then + if [[ -n "$EXISTING_PR" ]]; then gh pr close "$EXISTING_PR" \ --repo apify/apify-client-python \ --delete-branch \ From 806d164abab78407f31a575a6d40f94058b1e0d0 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Thu, 2 Apr 2026 14:13:14 +0200 Subject: [PATCH 4/4] use artifacts --- .github/workflows/openapi-ci.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/openapi-ci.yaml b/.github/workflows/openapi-ci.yaml index e1d86fbcc3..9f7a2b5b66 100644 --- a/.github/workflows/openapi-ci.yaml +++ b/.github/workflows/openapi-ci.yaml @@ -148,12 +148,11 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} - PR_SHA: ${{ github.event.pull_request.head.sha }} run: | gh workflow run regenerate_models.yaml \ --repo apify/apify-client-python \ --field docs_pr_number="$PR_NUMBER" \ - --field docs_pr_sha="$PR_SHA" + --field docs_workflow_run_id="${{ github.run_id }}" # When a docs PR is closed (merged or abandoned), clean up the corresponding auto-generated PR # in apify-client-python to avoid stale PRs piling up.