Skip to content

Commit f8dd03f

Browse files
authored
Merge pull request #59 from automationiberia/fix/release-merge-pr-token
Fix release merge PR using GITHUB_TOKEN
2 parents b7ef7b2 + 56787e0 commit f8dd03f

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

.github/workflows/release_auto.yml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
bugfixes:
3+
- release automation - create and merge the changelog PR with GITHUB_TOKEN
4+
so merge_release no longer fails when GH_WORKFLOW_KEY lacks createPullRequest.
5+
...

0 commit comments

Comments
 (0)