|
63 | 63 | with: |
64 | 64 | token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} |
65 | 65 |
|
| 66 | + # Record master's SHA up front: a later step checks out the auto-update branch, so the change check below |
| 67 | + # can't compare against HEAD. Resolve master from the remote rather than the checked-out ref: the run may be |
| 68 | + # dispatched from a non-master ref, but that check and the PR both target master, so master is the baseline. |
| 69 | + - name: Record master ref |
| 70 | + id: base |
| 71 | + run: | |
| 72 | + git fetch --depth=1 origin master |
| 73 | + echo "sha=$(git rev-parse FETCH_HEAD)" >> "$GITHUB_OUTPUT" |
| 74 | +
|
| 75 | + # Does the auto-update branch already exist on the remote? If so, a previous dispatch opened the PR |
| 76 | + # and we append to it. If not, we start it from master (below) so signed-commit creates it there. |
| 77 | + - name: Determine auto-update branch state |
| 78 | + id: branch |
| 79 | + run: | |
| 80 | + if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then |
| 81 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 82 | + echo "create=false" >> "$GITHUB_OUTPUT" |
| 83 | + else |
| 84 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 85 | + echo "create=true" >> "$GITHUB_OUTPUT" |
| 86 | + fi |
| 87 | +
|
| 88 | + # Check out the existing branch before regenerating so the new models land as a NEW commit on top, |
| 89 | + # mirroring the commit just pushed to the docs PR. We must switch now, while the tree is clean: |
| 90 | + # signed-commit's own checkout is a plain `git checkout` that would refuse to overwrite the |
| 91 | + # regenerated files (which differ between master and the branch) once they're in the working tree. |
| 92 | + - name: Check out existing auto-update branch |
| 93 | + if: steps.branch.outputs.exists == 'true' |
| 94 | + run: | |
| 95 | + git fetch --depth=1 origin "$BRANCH" |
| 96 | + git checkout -B "$BRANCH" FETCH_HEAD |
| 97 | +
|
| 98 | + # The branch doesn't exist yet, so regenerate from the recorded master SHA rather than the dispatched |
| 99 | + # ref (a manual run may be dispatched from a non-master ref). Regenerating on master keeps the codegen |
| 100 | + # tooling current, and signed-commit then creates the branch (the PR head) on top of master, the PR base. |
| 101 | + - name: Start the auto-update branch from master |
| 102 | + if: steps.branch.outputs.exists == 'false' |
| 103 | + run: git checkout "${{ steps.base.outputs.sha }}" |
| 104 | + |
66 | 105 | # Download the pre-built OpenAPI spec artifact from the apify-docs workflow run. |
67 | 106 | # Skipped for manual runs — datamodel-codegen will fetch from the published spec URL instead. |
68 | 107 | - name: Download OpenAPI spec artifact |
@@ -93,46 +132,44 @@ jobs: |
93 | 132 | uv run poe generate-models |
94 | 133 | fi |
95 | 134 |
|
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. |
| 135 | + # Proceed only when the regenerated models differ from master (compared against the recorded SHA, |
| 136 | + # since the tree may now sit on the branch), which skips empty-PR runs: a spec change that doesn't |
| 137 | + # affect the client models, or one already merged into master. Also avoids creating an empty branch. |
101 | 138 | - name: Check for model changes |
102 | 139 | id: changes |
103 | 140 | run: | |
104 | | - if git diff --quiet -- src/apify_client/_models.py src/apify_client/_typeddicts.py src/apify_client/_literals.py; then |
| 141 | + if git diff --quiet "${{ steps.base.outputs.sha }}" -- src/apify_client/_models.py src/apify_client/_typeddicts.py src/apify_client/_literals.py; then |
105 | 142 | echo "No model changes relative to master — nothing to regenerate." |
106 | 143 | echo "has_changes=false" >> "$GITHUB_OUTPUT" |
107 | 144 | else |
108 | 145 | echo "has_changes=true" >> "$GITHUB_OUTPUT" |
109 | 146 | fi |
110 | 147 |
|
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 | | -
|
123 | | - - name: Commit model changes |
| 148 | + # Append the regenerated models to the auto-update branch as a single signed ("Verified") commit |
| 149 | + # via apify/actions/signed-commit (GitHub's createCommitOnBranch GraphQL mutation). It's added on |
| 150 | + # top of the branch tip, never resetting to master: a fresh docs PR creates the branch |
| 151 | + # (create-branch) and its first commit, and each later docs-PR commit triggers a dispatch that |
| 152 | + # appends another, so the client PR mirrors the docs PR and stays open. |
| 153 | + # |
| 154 | + # Appending (rather than force-pushing the branch to master, as before) is what keeps the PR open: |
| 155 | + # a "branch == master" tip makes the PR head equal its base, which GitHub auto-closes, and each |
| 156 | + # dispatch then opens a duplicate PR. signed-commit also sets committed=false when the staged |
| 157 | + # files match the tip, so a repeated dispatch regenerating identical models adds no commit. |
| 158 | + - name: Commit regenerated models |
124 | 159 | id: commit |
125 | 160 | if: steps.changes.outputs.has_changes == 'true' |
126 | 161 | uses: apify/actions/signed-commit@v1.3.0 |
127 | 162 | with: |
128 | 163 | message: ${{ env.TITLE }} |
129 | | - add: 'src/apify_client/_models.py src/apify_client/_typeddicts.py src/apify_client/_literals.py' |
| 164 | + add: "src/apify_client/_models.py src/apify_client/_typeddicts.py src/apify_client/_literals.py" |
130 | 165 | github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} |
131 | 166 | branch: ${{ env.BRANCH }} |
132 | | - create-branch: 'false' |
| 167 | + create-branch: "${{ steps.branch.outputs.create }}" |
133 | 168 |
|
| 169 | + # Ensure exactly one PR exists for this branch. It's no longer auto-closed, so an existing PR is |
| 170 | + # reused. Only the first run (or one whose PR step a concurrent dispatch cancelled) creates it. |
134 | 171 | - name: Create or update PR |
135 | | - if: steps.commit.outputs.committed == 'true' |
| 172 | + if: steps.changes.outputs.has_changes == 'true' |
136 | 173 | id: pr |
137 | 174 | env: |
138 | 175 | GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} |
@@ -164,9 +201,11 @@ jobs: |
164 | 201 | echo "created=true" >> "$GITHUB_OUTPUT" |
165 | 202 | fi |
166 | 203 |
|
167 | | - # Post a cross-repo comment on the original docs PR so reviewers know about the corresponding client-python PR. |
| 204 | + # Post a cross-repo comment on the docs PR pointing reviewers to the companion client-python PR. |
| 205 | + # Only when something happened: the PR was just created, or a commit was appended. A repeated |
| 206 | + # dispatch that changes nothing (committed=false) posts no comment, avoiding noise on the docs PR. |
168 | 207 | - name: Comment on apify-docs PR |
169 | | - if: steps.commit.outputs.committed == 'true' && inputs.docs_pr_number |
| 208 | + if: inputs.docs_pr_number && (steps.pr.outputs.created == 'true' || steps.commit.outputs.committed == 'true') |
170 | 209 | env: |
171 | 210 | GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} |
172 | 211 | PR_CREATED: ${{ steps.pr.outputs.created }} |
|
0 commit comments