@@ -352,15 +352,34 @@ jobs:
352352 ref : release/${{ needs.calculate_version.outputs.collection_version }}
353353
354354 - name : Create and merge release PR
355- run : |
356- gh pr create \
357- --base devel \
358- --head "release/${{ needs.calculate_version.outputs.collection_version }}" \
359- --title "[RELEASE] Update changelog ${{ needs.calculate_version.outputs.collection_version }}" \
360- --body "Updated with changelog for release ${{ needs.calculate_version.outputs.collection_version }}"
361- gh pr merge "release/${{ needs.calculate_version.outputs.collection_version }}" --rebase --admin
362355 env :
363- GH_TOKEN : ${{ secrets.GH_WORKFLOW_KEY }}
356+ # Use the job GITHUB_TOKEN (pull-requests: write). GH_WORKFLOW_KEY is often a
357+ # fine-grained PAT without createPullRequest and fails with:
358+ # "Resource not accessible by personal access token (createPullRequest)".
359+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
360+ TAG : ${{ needs.calculate_version.outputs.collection_version }}
361+ run : |
362+ HEAD="release/${TAG}"
363+ STATE="$(gh pr view "${HEAD}" --json state --jq .state 2>/dev/null || true)"
364+ if [ "${STATE}" = "MERGED" ]; then
365+ echo "::notice::Release PR for ${HEAD} is already merged."
366+ exit 0
367+ fi
368+ if [ -z "${STATE}" ]; then
369+ gh pr create \
370+ --base devel \
371+ --head "${HEAD}" \
372+ --title "[RELEASE] Update changelog ${TAG}" \
373+ --body "Updated with changelog for release ${TAG}"
374+ else
375+ echo "::notice::Release PR for ${HEAD} already exists (state=${STATE})."
376+ fi
377+ # --admin bypasses branch protection when the token is allowed to; fall back
378+ # to a normal merge if admin bypass is not available for GITHUB_TOKEN.
379+ if ! gh pr merge "${HEAD}" --rebase --admin; then
380+ echo "::warning::Admin merge failed; retrying without --admin."
381+ gh pr merge "${HEAD}" --rebase
382+ fi
364383
365384 deploy_ee :
366385 name : Build Execution Environment
0 commit comments