@@ -152,6 +152,11 @@ jobs:
152152 create-pull-request :
153153 if : github.repository == 'github/docs-internal'
154154 runs-on : ubuntu-latest
155+ # Serialize publishing so a second run sees the first run's PR before it force-pushes.
156+ # Pull request dry runs get their own group so they never queue behind or cancel a publisher.
157+ concurrency :
158+ group : ${{ github.workflow }}-query-table-publication-${{ github.event_name == 'pull_request' && github.run_id || 'publish' }}
159+ cancel-in-progress : false
155160 permissions :
156161 contents : write
157162 pull-requests : write
@@ -216,27 +221,27 @@ jobs:
216221
217222 branchname=codeql-query-tables-${{ steps.codeql.outputs.OPENAPI_COMMIT_SHA }}
218223
219- # Query the remote because actions/checkout with fetch-depth 1 omits other remote-tracking branches.
220- branchExists=$(git ls-remote --heads origin refs/heads/$branchname | wc -l)
221-
222224 # Pull request runs validate generated files without pushing branches.
223225 if [ "$DRY_RUN" = "true" ]; then
224226 echo "Dry-run mode when run in a pull request"
225227 echo "See the 'Insight into diff' step for the changes it would create PR about."
226228 exit 0
227229 fi
228230
229- if [ $branchExists -ne 0 ]; then
230- echo "Branch $branchname already exists in the remote repository."
231+ # Check for an open PR before pushing so reruns do not overwrite commits added to it.
232+ existing_pr=$(gh pr list --repo github/docs-internal --head "$branchname" --json number --jq '.[0].number')
233+ if [[ -n "$existing_pr" ]]; then
234+ echo "Pull request #$existing_pr already exists for branch $branchname. Skipping PR creation."
231235 exit 0
232- else
233- git checkout -b $branchname
234236 fi
235237
238+ git checkout -b $branchname
236239 git add data/reusables/code-scanning/codeql-query-tables
237240 git add data/reusables/code-quality/codeql-query-tables
238241 git commit -m "Update CodeQL query tables"
239- git push -u origin $branchname
242+
243+ # Force-push over a branch left by a failed attempt; this workflow exclusively owns these branches.
244+ git push --force -u origin $branchname
240245
241246 echo "Creating pull request..."
242247 gh pr create \
0 commit comments