chore: Use custom action to commit changes in CI instead of git commit
#1467
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| pull-requests: 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: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| - uses: apify/workflows/pnpm-install@main | |
| - name: Lint with Redocly | |
| run: pnpm openapi:lint:redocly --format=github-actions | |
| - name: Lint with Spectral | |
| run: pnpm openapi:lint:spectral --format=github-actions | |
| build: | |
| name: Build bundled specification | |
| runs-on: ubuntu-latest | |
| needs: lint | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| - uses: apify/workflows/pnpm-install@main | |
| - name: Build bundles | |
| run: pnpm openapi:build | |
| - name: Upload bundles | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: openapi-bundles | |
| path: | | |
| static/api/openapi.json | |
| static/api/openapi.yaml | |
| retention-days: 1 | |
| validate: | |
| name: Validate bundled specification | |
| runs-on: ubuntu-latest | |
| needs: [lint, build] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| - uses: apify/workflows/pnpm-install@main | |
| - name: Download bundles | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: openapi-bundles | |
| path: static/api/ | |
| - name: Validate YAML bundle | |
| run: pnpm exec redocly lint static/api/openapi.yaml | |
| - name: Validate JSON bundle | |
| run: pnpm exec redocly lint static/api/openapi.json | |
| - name: Check bundle sizes | |
| run: | | |
| JSON_SIZE=$(stat -f%z static/api/openapi.json 2>/dev/null || stat -c%s static/api/openapi.json) | |
| YAML_SIZE=$(stat -f%z static/api/openapi.yaml 2>/dev/null || stat -c%s static/api/openapi.yaml) | |
| echo "Bundle sizes:" | |
| echo " JSON: $JSON_SIZE bytes" | |
| echo " YAML: $YAML_SIZE bytes" | |
| if [[ "$JSON_SIZE" -lt 1000 ]] || [[ "$YAML_SIZE" -lt 1000 ]]; then | |
| echo "Error: Bundle files are suspiciously small" | |
| 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_AUTHOR: ${{ github.event.pull_request.user.login }} | |
| run: | | |
| gh workflow run manual_regenerate_models.yaml \ | |
| --repo apify/apify-client-python \ | |
| --field docs_pr_number="$PR_NUMBER" \ | |
| --field docs_workflow_run_id="${{ github.run_id }}" \ | |
| --field docs_pr_author="$PR_AUTHOR" | |
| # When a docs PR is closed without being merged, clean up the corresponding auto-generated PR | |
| # in apify-client-python to avoid stale PRs piling up. | |
| # If the docs PR is merged, the client PR is left open for manual review and merge. | |
| 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' | |
| && github.event.pull_request.merged == false | |
| && github.event.pull_request.head.repo.full_name == github.repository | |
| 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 manual_regenerate_models.yaml creates. | |
| run: | | |
| BRANCH="update-models-docs-pr-${PR_NUMBER}" | |
| EXISTING_PR=$(gh pr list \ | |
| --repo apify/apify-client-python \ | |
| --head "$BRANCH" \ | |
| --json number \ | |
| --jq '.[0].number // empty' 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 without merging." | |
| echo "Closed apify-client-python PR #$EXISTING_PR" | |
| else | |
| echo "No corresponding apify-client-python PR found for branch $BRANCH" | |
| fi |