Skip to content

Commit fc5b0c1

Browse files
committed
Merge remote-tracking branch 'origin/master' into update-models-docs-pr-2403
2 parents 65a2659 + dd17027 commit fc5b0c1

File tree

6 files changed

+294
-41
lines changed

6 files changed

+294
-41
lines changed

.github/workflows/manual_regenerate_models.yaml

Lines changed: 26 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,9 @@ 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 }}
43+
REVIEWER: vdusek
44+
LABEL: t-tooling
3845

3946
steps:
4047
- name: Validate inputs
@@ -54,6 +61,17 @@ jobs:
5461
with:
5562
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
5663

64+
# If the branch already exists on the remote (e.g. from a previous run, possibly with
65+
# reviewer commits), check it out to build on top of it instead of starting fresh.
66+
- name: Switch to existing branch or create a new one
67+
run: |
68+
if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then
69+
git fetch origin "$BRANCH"
70+
git switch "$BRANCH"
71+
else
72+
git switch -c "$BRANCH"
73+
fi
74+
5775
# Download the pre-built OpenAPI spec artifact from the apify-docs workflow run.
5876
# Skipped for manual runs — datamodel-codegen will fetch from the published spec URL instead.
5977
- name: Download OpenAPI spec artifact
@@ -84,17 +102,16 @@ jobs:
84102
uv run poe generate-models
85103
fi
86104
87-
- name: Commit model changes
105+
- name: Commit and push model changes
88106
id: commit
89107
uses: EndBug/add-and-commit@v10
90108
with:
91109
add: src/apify_client/_models.py
92110
author_name: apify-service-account
93111
author_email: apify-service-account@users.noreply.github.com
94112
message: ${{ env.TITLE }}
95-
new_branch: ${{ env.BRANCH }}
96113
commit: --no-verify
97-
push: -u origin ${{ env.BRANCH }} --force
114+
push: -u origin ${{ env.BRANCH }}
98115

99116
- name: Create or update PR
100117
if: steps.commit.outputs.committed == 'true'
@@ -111,34 +128,19 @@ jobs:
111128
else
112129
if [[ -n "$DOCS_PR_NUMBER" ]]; then
113130
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-
)
131+
BODY="This PR updates the auto-generated Pydantic models based on OpenAPI specification changes in [apify-docs PR #${DOCS_PR_NUMBER}](${DOCS_PR_URL})."
126132
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-
)
133+
BODY="This PR updates the auto-generated Pydantic models from the [published OpenAPI specification](https://docs.apify.com/api/openapi.json)."
135134
fi
136135
137136
PR_URL=$(gh pr create \
138137
--title "$TITLE" \
139138
--body "$BODY" \
140139
--head "$BRANCH" \
141-
--base master)
140+
--base master \
141+
--reviewer "$REVIEWER" \
142+
--assignee "$ASSIGNEE" \
143+
--label "$LABEL")
142144
echo "Created PR: $PR_URL"
143145
echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
144146
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)