Skip to content

Commit d7cf1c8

Browse files
authored
ci: avoid branch clash in regenerate-models workflow (#812)
## Summary Fixes the branch-clash bug in `.github/workflows/manual_regenerate_models.yaml` that was flagged as a follow-up in #809. The recent manual run ([failing CI](https://github.com/apify/apify-client-python/actions/runs/26239209577/job/77220728000)) failed at the `Commit model changes` step with: ``` fatal: refusing to fetch into branch 'refs/heads/update-models-manual' checked out at '...' ``` ### Cause The local `git switch -c "$BRANCH"` step pre-created the branch unconditionally. `apify/actions/signed-commit@v1.0.0` with `create-branch: 'true'` then ran `git fetch --depth=1 origin "$BRANCH:refs/heads/$BRANCH"`, which refuses to fetch into a checked-out branch. ### Fix - When the remote branch already exists: fetch + check it out locally, and tell signed-commit `create-branch: false`. - When it doesn't exist: stay on the default branch and let signed-commit create the remote branch with `create-branch: true`. The `create_branch` decision is exported from the renamed `Set up branch` step and consumed by the signed-commit step.
1 parent f9018b9 commit d7cf1c8

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

.github/workflows/manual_regenerate_models.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,20 @@ 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 commits),
67-
# check it out to build on top of it instead of starting fresh.
68-
- name: Switch to existing branch or create a new one
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
6973
run: |
7074
if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then
71-
git fetch origin "$BRANCH"
75+
git fetch origin "$BRANCH":"$BRANCH"
7276
git switch "$BRANCH"
77+
echo "create_branch=false" >> "$GITHUB_OUTPUT"
7378
else
74-
git switch -c "$BRANCH"
79+
echo "create_branch=true" >> "$GITHUB_OUTPUT"
7580
fi
7681
7782
# Download the pre-built OpenAPI spec artifact from the apify-docs workflow run.
@@ -112,7 +117,7 @@ jobs:
112117
add: 'src/apify_client/_models.py src/apify_client/_typeddicts.py src/apify_client/_literals.py'
113118
github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
114119
branch: ${{ env.BRANCH }}
115-
create-branch: 'true'
120+
create-branch: ${{ steps.branch-setup.outputs.create_branch }}
116121

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

0 commit comments

Comments
 (0)