11# This workflow creates a backmerge PR into `develop` whenever a new version tag is pushed (v*).
22#
33# Key points:
4- # - The PR head is a temporary branch that points at the *tag commit* (refs/tags/vX.Y.Z).
5- # After merging, `develop` can `git describe` as vX.Y.Z-... because the tag commit becomes an ancestor.
4+ # - Creates a PR from `master` to `develop` when a new tag is pushed.
65# - The PR is auto-merged using a MERGE COMMIT (not squash) via a GitHub App token.
76# The GitHub App must be added to the develop ruleset bypass list.
87#
1211# - Actions secret: ES_BACKMERGE_PRIVATE_KEY (GitHub App private key PEM)
1312# - Actions variable: ES_BACKMERGE_APP_ID (GitHub App ID)
1413
15- name : Backmerge PR (tag -> develop)
14+ name : Backmerge PR (master -> develop)
1615
1716on :
1817 push :
18+ branches : ['patch']
1919 tags : ['v*']
2020
2121permissions :
@@ -34,64 +34,49 @@ jobs:
3434 app-id : ${{ vars.BACKMERGE_APP_ID }}
3535 private-key : ${{ secrets.BACKMERGE_PRIVATE_KEY }}
3636
37- - name : Checkout tag commit
37+ - name : Checkout repository
3838 uses : actions/checkout@v5
3939 with :
40- ref : ${{ github.ref }} # refs/tags/vX.Y.Z
4140 fetch-depth : 0
4241 token : ${{ steps.app-token.outputs.token }}
4342
44- - name : Create and push backmerge branch at tag
45- id : vars
43+ - name : Create PR from master to develop (or reuse if exists)
44+ id : pr
4645 run : |
4746 set -euo pipefail
4847
4948 TAG='${{ github.ref_name }}'
50- BRANCH="backmerge/${TAG}"
5149
52- echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
53- echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
50+ TITLE="Backmerge: ${TAG} from master into develop"
5451
55- git config user.name "github-actions[bot]"
56- git config user.email "github-actions[bot]@users.noreply.github.com"
52+ BODY="⚠️ This PR is created automatically for backmerge of the release tag \`${TAG}\` from \`master\` into \`develop\`.
5753
58- # Create/move branch to point exactly at the tag commit
59- git checkout -B "$BRANCH"
54+ It is labeled \`[maintainer] auto-pull-request\` and is excluded from release notes and version bump logic."
6055
61- # Push (force makes re-runs idempotent for the same tag)
62- git push --force --set-upstream origin "$BRANCH"
63- env :
64- GITHUB_TOKEN : ${{ steps.app-token.outputs.token }}
65-
66- - name :
67- Create PR from tag backmerge branch to develop (or reuse if exists)
68- run : |
69- set -euo pipefail
70-
71- TITLE="Backmerge: ${{ steps.vars.outputs.tag }} into develop"
72-
73- BODY="⚠️ This PR is created automatically for backmerge of a new release tag commit \`${{ steps.vars.outputs.tag }}\` into \`develop\`.
74-
75- It is labeled `[maintainer] auto-pull-request` and is excluded from release notes and version bump logic."
56+ # Check if a PR from master to develop already exists
57+ EXISTING_PR=$(gh pr list --repo "${{ github.repository }}" --base develop --head master --state open --json number --jq '.[0].number // empty')
7658
77- if gh pr view --repo "${{ github.repository }}" --head "${{ steps.vars.outputs.branch }}" >/dev/null 2>&1; then
78- echo "PR already exists for head=${{ steps.vars.outputs.branch }}"
59+ if [ -n "$EXISTING_PR" ]; then
60+ echo "PR #${EXISTING_PR} already exists for master -> develop"
61+ echo "pr_number=${EXISTING_PR}" >> "$GITHUB_OUTPUT"
7962 else
80- gh pr create \
63+ PR_URL=$( gh pr create \
8164 --repo "${{ github.repository }}" \
8265 --base develop \
83- --head "${{ steps.vars.outputs.branch }}" \
66+ --head master \
8467 --title "$TITLE" \
8568 --label "[maintainer] auto-pull-request" \
86- --body "$BODY"
69+ --body "$BODY")
70+ PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
71+ echo "Created PR #${PR_NUMBER}"
72+ echo "pr_number=${PR_NUMBER}" >> "$GITHUB_OUTPUT"
8773 fi
8874 env :
8975 GH_TOKEN : ${{ steps.app-token.outputs.token }}
9076
9177 - name : Enable auto-merge using MERGE COMMIT
9278 run : |
9379 set -euo pipefail
94- # Merge the PR identified by its head branch.
95- gh pr merge --repo "${{ github.repository }}" --merge --auto "${{ steps.vars.outputs.branch }}"
80+ gh pr merge --repo "${{ github.repository }}" --merge --auto "${{ steps.pr.outputs.pr_number }}"
9681 env :
9782 GH_TOKEN : ${{ steps.app-token.outputs.token }}
0 commit comments