Skip to content

Commit 6933070

Browse files
committed
ci: regenerate models against current master to avoid duplicate PRs
The regeneration used to build on top of a possibly stale existing update-models-docs-pr-N branch. When the same spec change had already been merged into master through another route (e.g. a manually merged client PR), re-regenerating on the stale base re-emitted that change as a fresh diff and opened a PR duplicating what master already had. Now the job regenerates on the master checkout, skips entirely when the result is identical to master, and otherwise force-points the branch at master before committing a single regenerated commit on top — so the diff is always relative to current master. The PR still updates on every new commit to the source docs PR.
1 parent 949fd89 commit 6933070

1 file changed

Lines changed: 29 additions & 17 deletions

File tree

.github/workflows/manual_regenerate_models.yaml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,6 @@ jobs:
6363
with:
6464
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
6565

66-
# If the branch already exists on the remote (e.g. from a previous run, possibly with reviewer
67-
# commits), check it out so regeneration builds on top of it. Otherwise stay on the default
68-
# branch and let the signed-commit step below create the remote branch — its create-branch
69-
# flow does `git fetch ... $BRANCH:refs/heads/$BRANCH` which fails if $BRANCH is already
70-
# checked out locally.
71-
- name: Set up branch
72-
id: branch-setup
73-
run: |
74-
if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then
75-
git fetch origin "$BRANCH":"$BRANCH"
76-
git switch "$BRANCH"
77-
echo "create_branch=false" >> "$GITHUB_OUTPUT"
78-
else
79-
echo "create_branch=true" >> "$GITHUB_OUTPUT"
80-
fi
81-
8266
# Download the pre-built OpenAPI spec artifact from the apify-docs workflow run.
8367
# Skipped for manual runs — datamodel-codegen will fetch from the published spec URL instead.
8468
- name: Download OpenAPI spec artifact
@@ -109,15 +93,43 @@ jobs:
10993
uv run poe generate-models
11094
fi
11195
96+
# Proceed only when regeneration actually changes the models relative to the current master.
97+
# The job runs on a fresh master checkout, so anything already merged into master (e.g. a
98+
# manually merged client PR carrying the same spec change, or a docs PR that merged master in
99+
# and re-emits an already-applied change) produces no diff here and we skip — instead of
100+
# opening a PR that just duplicates what master already has.
101+
- name: Check for model changes
102+
id: changes
103+
run: |
104+
if git diff --quiet -- src/apify_client/_models.py src/apify_client/_typeddicts.py src/apify_client/_literals.py; then
105+
echo "No model changes relative to master — nothing to regenerate."
106+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
107+
else
108+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
109+
fi
110+
111+
# Point the auto-update branch at the current master so the signed-commit step below records
112+
# the regenerated models as a single commit on top of it. Resetting to master (instead of
113+
# building on a possibly stale existing branch) is what keeps the committed diff relative to
114+
# the current master: an already-merged change can never reappear. Any previous content on the
115+
# branch is intentionally replaced, so the PR always reflects "current master + freshly
116+
# regenerated models" — and it still updates whenever the source docs PR gets new commits.
117+
- name: Point branch at current master
118+
if: steps.changes.outputs.has_changes == 'true'
119+
run: |
120+
git checkout -B "$BRANCH"
121+
git push --force origin "HEAD:refs/heads/$BRANCH"
122+
112123
- name: Commit model changes
113124
id: commit
125+
if: steps.changes.outputs.has_changes == 'true'
114126
uses: apify/actions/signed-commit@v1.2.0
115127
with:
116128
message: ${{ env.TITLE }}
117129
add: 'src/apify_client/_models.py src/apify_client/_typeddicts.py src/apify_client/_literals.py'
118130
github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
119131
branch: ${{ env.BRANCH }}
120-
create-branch: ${{ steps.branch-setup.outputs.create_branch }}
132+
create-branch: 'false'
121133

122134
- name: Create or update PR
123135
if: steps.commit.outputs.committed == 'true'

0 commit comments

Comments
 (0)