Skip to content

Commit 3097e61

Browse files
vdusekclaude
andcommitted
ci: add workflow to regenerate models from OpenAPI spec changes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 32ad005 commit 3097e61

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Regenerate models from OpenAPI spec
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
docs_pr_number:
7+
description: "PR number in apify/apify-docs that triggered this workflow"
8+
required: true
9+
type: string
10+
docs_pr_branch:
11+
description: "Branch name in apify/apify-docs PR"
12+
required: true
13+
type: string
14+
15+
concurrency:
16+
group: regenerate-models-${{ inputs.docs_pr_number }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
regenerate-models:
21+
name: Regenerate models
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout apify-client-python
26+
uses: actions/checkout@v6
27+
28+
- name: Checkout apify-docs at PR branch
29+
uses: actions/checkout@v6
30+
with:
31+
repository: apify/apify-docs
32+
ref: ${{ inputs.docs_pr_branch }}
33+
path: apify-docs
34+
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
35+
36+
- name: Set up Node.js
37+
uses: actions/setup-node@v6
38+
with:
39+
node-version: 24
40+
cache: npm
41+
cache-dependency-path: apify-docs/package-lock.json
42+
43+
- name: Build OpenAPI spec bundle
44+
run: |
45+
cd apify-docs
46+
corepack enable
47+
npm ci --force
48+
npm run openapi:build:json
49+
env:
50+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
51+
52+
- name: Set up uv
53+
uses: astral-sh/setup-uv@v6
54+
55+
- name: Generate models from local spec
56+
run: uv run datamodel-codegen --input apify-docs/static/api/openapi.json
57+
58+
- name: Check for changes
59+
id: changes
60+
run: |
61+
if git diff --exit-code src/apify_client/_models.py; then
62+
echo "No changes in generated models"
63+
echo "changed=false" >> "$GITHUB_OUTPUT"
64+
else
65+
echo "Models have changed"
66+
echo "changed=true" >> "$GITHUB_OUTPUT"
67+
fi
68+
69+
- name: Configure git
70+
if: steps.changes.outputs.changed == 'true'
71+
run: |
72+
git config user.name "apify-service-account"
73+
git config user.email "apify-service-account@users.noreply.github.com"
74+
75+
- name: Create or update PR
76+
if: steps.changes.outputs.changed == 'true'
77+
id: pr
78+
run: |
79+
BRANCH="chore/update-models-docs-pr-${{ inputs.docs_pr_number }}"
80+
DOCS_PR_URL="https://github.com/apify/apify-docs/pull/${{ inputs.docs_pr_number }}"
81+
82+
git checkout -b "$BRANCH"
83+
git add src/apify_client/_models.py
84+
git commit -m "chore: update generated models from apify-docs PR #${{ inputs.docs_pr_number }}"
85+
git push --force origin "$BRANCH"
86+
87+
# Check if PR already exists
88+
EXISTING_PR=$(gh pr list --head "$BRANCH" --json url --jq '.[0].url' 2>/dev/null || true)
89+
90+
if [ -n "$EXISTING_PR" ]; then
91+
echo "PR already exists: $EXISTING_PR"
92+
echo "pr_url=$EXISTING_PR" >> "$GITHUB_OUTPUT"
93+
echo "created=false" >> "$GITHUB_OUTPUT"
94+
else
95+
BODY="This PR updates the auto-generated Pydantic models based on OpenAPI specification changes in [apify-docs PR #${{ inputs.docs_pr_number }}]($DOCS_PR_URL).
96+
97+
## Changes
98+
99+
- Regenerated \`src/apify_client/_models.py\` using \`datamodel-codegen\`
100+
101+
## Source
102+
103+
- apify-docs PR: $DOCS_PR_URL"
104+
105+
PR_URL=$(gh pr create \
106+
--title "chore: update generated models from apify-docs PR #${{ inputs.docs_pr_number }}" \
107+
--body "$BODY" \
108+
--head "$BRANCH" \
109+
--base master)
110+
echo "Created PR: $PR_URL"
111+
echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
112+
echo "created=true" >> "$GITHUB_OUTPUT"
113+
fi
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
116+
117+
- name: Comment on apify-docs PR
118+
if: steps.changes.outputs.changed == 'true' && steps.pr.outputs.created == 'true'
119+
run: |
120+
gh pr comment "${{ inputs.docs_pr_number }}" \
121+
--repo apify/apify-docs \
122+
--body "A PR to update the Python client models has been created in apify-client-python: ${{ steps.pr.outputs.pr_url }}
123+
124+
This was automatically triggered by OpenAPI specification changes in this PR."
125+
env:
126+
GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

0 commit comments

Comments
 (0)