Skip to content

Commit c83a149

Browse files
vdusekclaude
andcommitted
ci: Improve model regeneration workflow
- Add reviewer, assignee, and label to auto-created PRs - Add @docs_group('Models') post-processing step for API docs - Replace force push with incremental commits to preserve reviewer changes - Simplify PR description body Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2021928 commit c83a149

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

.github/workflows/manual_regenerate_models.yaml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ on:
1717
description: Workflow run ID in apify/apify-docs that built the OpenAPI spec artifact (optional for manual runs)
1818
required: false
1919
type: string
20+
docs_pr_author:
21+
description: GitHub login of the apify-docs PR author (optional for manual runs)
22+
required: false
23+
type: string
2024

2125
permissions:
2226
contents: write
@@ -35,6 +39,7 @@ jobs:
3539
DOCS_PR_NUMBER: ${{ inputs.docs_pr_number }}
3640
BRANCH: ${{ inputs.docs_pr_number && format('update-models-docs-pr-{0}', inputs.docs_pr_number) || 'update-models-manual' }}
3741
TITLE: "${{ inputs.docs_pr_number && format('[TODO]: update generated models from apify-docs PR #{0}', inputs.docs_pr_number) || '[TODO]: update generated models from published OpenAPI spec' }}"
42+
ASSIGNEE: ${{ inputs.docs_pr_author || github.actor }}
3843

3944
steps:
4045
- name: Validate inputs
@@ -54,6 +59,17 @@ jobs:
5459
with:
5560
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
5661

62+
# If the branch already exists on the remote (e.g. from a previous run, possibly with
63+
# reviewer commits), check it out to build on top of it instead of starting fresh.
64+
- name: Switch to existing branch or create a new one
65+
run: |
66+
if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then
67+
git fetch origin "$BRANCH"
68+
git checkout "$BRANCH"
69+
else
70+
git checkout -b "$BRANCH"
71+
fi
72+
5773
# Download the pre-built OpenAPI spec artifact from the apify-docs workflow run.
5874
# Skipped for manual runs — datamodel-codegen will fetch from the published spec URL instead.
5975
- name: Download OpenAPI spec artifact
@@ -84,17 +100,16 @@ jobs:
84100
uv run poe generate-models
85101
fi
86102
87-
- name: Commit model changes
103+
- name: Commit and push model changes
88104
id: commit
89105
uses: EndBug/add-and-commit@v10
90106
with:
91107
add: src/apify_client/_models.py
92108
author_name: apify-service-account
93109
author_email: apify-service-account@users.noreply.github.com
94110
message: ${{ env.TITLE }}
95-
new_branch: ${{ env.BRANCH }}
96111
commit: --no-verify
97-
push: -u origin ${{ env.BRANCH }} --force
112+
push: -u origin ${{ env.BRANCH }}
98113

99114
- name: Create or update PR
100115
if: steps.commit.outputs.committed == 'true'
@@ -111,34 +126,19 @@ jobs:
111126
else
112127
if [[ -n "$DOCS_PR_NUMBER" ]]; then
113128
DOCS_PR_URL="https://github.com/apify/apify-docs/pull/${DOCS_PR_NUMBER}"
114-
BODY=$(cat <<EOF
115-
This PR updates the auto-generated Pydantic models based on OpenAPI specification changes in [apify-docs PR #${DOCS_PR_NUMBER}](${DOCS_PR_URL}).
116-
117-
## Changes
118-
119-
- Regenerated \`src/apify_client/_models.py\` using \`datamodel-codegen\`
120-
121-
## Source
122-
123-
- apify-docs PR: ${DOCS_PR_URL}
124-
EOF
125-
)
129+
BODY="This PR updates the auto-generated Pydantic models based on OpenAPI specification changes in [apify-docs PR #${DOCS_PR_NUMBER}](${DOCS_PR_URL})."
126130
else
127-
BODY=$(cat <<EOF
128-
This PR updates the auto-generated Pydantic models from the published OpenAPI specification.
129-
130-
## Changes
131-
132-
- Regenerated \`src/apify_client/_models.py\` using \`datamodel-codegen\`
133-
EOF
134-
)
131+
BODY="This PR updates the auto-generated Pydantic models from the [published OpenAPI specification](https://docs.apify.com/api/openapi.json)."
135132
fi
136133
137134
PR_URL=$(gh pr create \
138135
--title "$TITLE" \
139136
--body "$BODY" \
140137
--head "$BRANCH" \
141-
--base master)
138+
--base master \
139+
--reviewer vdusek \
140+
--assignee "$ASSIGNEE" \
141+
--label t-tooling)
142142
echo "Created PR: $PR_URL"
143143
echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
144144
echo "created=true" >> "$GITHUB_OUTPUT"

scripts/postprocess_generated_models.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
nested-$ref limitation), causing datamodel-codegen to generate a duplicate `Type(StrEnum)`
99
class alongside the canonical `ErrorType(StrEnum)`. This script removes the duplicate and
1010
rewires references to use `ErrorType`.
11+
- Missing @docs_group decorator: Adds `@docs_group('Models')` to all model classes for API
12+
reference documentation grouping, along with the required import.
1113
"""
1214

1315
from __future__ import annotations
@@ -51,10 +53,27 @@ def deduplicate_error_type_enum(content: str) -> str:
5153
return re.sub(r'\n{3,}', '\n\n\n', content)
5254

5355

56+
def add_docs_group_decorators(content: str) -> str:
57+
"""Add `@docs_group('Models')` decorator to all model classes and the required import."""
58+
# Add the import after the existing imports.
59+
content = re.sub(
60+
r'(from pydantic import [^\n]+\n)',
61+
r'\1\nfrom apify_client._docs import docs_group\n',
62+
content,
63+
)
64+
# Add @docs_group('Models') before every class definition.
65+
return re.sub(
66+
r'\nclass ',
67+
"\n@docs_group('Models')\nclass ",
68+
content,
69+
)
70+
71+
5472
def main() -> None:
5573
content = MODELS_PATH.read_text()
5674
fixed = fix_discriminators(content)
5775
fixed = deduplicate_error_type_enum(fixed)
76+
fixed = add_docs_group_decorators(fixed)
5877

5978
if fixed != content:
6079
MODELS_PATH.write_text(fixed)

0 commit comments

Comments
 (0)