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 :
@@ -34,64 +33,49 @@ jobs:
3433 app-id : ${{ vars.BACKMERGE_APP_ID }}
3534 private-key : ${{ secrets.BACKMERGE_PRIVATE_KEY }}
3635
37- - name : Checkout tag commit
36+ - name : Checkout repository
3837 uses : actions/checkout@v5
3938 with :
40- ref : ${{ github.ref }} # refs/tags/vX.Y.Z
4139 fetch-depth : 0
4240 token : ${{ steps.app-token.outputs.token }}
4341
44- - name : Create and push backmerge branch at tag
45- id : vars
42+ - name : Create PR from master to develop (or reuse if exists)
43+ id : pr
4644 run : |
4745 set -euo pipefail
4846
4947 TAG='${{ github.ref_name }}'
50- BRANCH="backmerge/${TAG}"
5148
52- echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
53- echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
49+ TITLE="Backmerge: ${TAG} from master into develop"
5450
55- git config user.name "github-actions[bot]"
56- git config user.email "github-actions[bot]@users.noreply.github.com"
51+ BODY="⚠️ This PR is created automatically for backmerge of the release tag \`${TAG}\` from \`master\` into \`develop\`.
5752
58- # Create/move branch to point exactly at the tag commit
59- git checkout -B "$BRANCH"
53+ It is labeled \`[maintainer] auto-pull-request\` and is excluded from release notes and version bump logic."
6054
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."
55+ # Check if a PR from master to develop already exists
56+ EXISTING_PR=$(gh pr list --repo "${{ github.repository }}" --base develop --head master --state open --json number --jq '.[0].number // empty')
7657
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 }}"
58+ if [ -n "$EXISTING_PR" ]; then
59+ echo "PR #${EXISTING_PR} already exists for master -> develop"
60+ echo "pr_number=${EXISTING_PR}" >> "$GITHUB_OUTPUT"
7961 else
80- gh pr create \
62+ PR_URL=$( gh pr create \
8163 --repo "${{ github.repository }}" \
8264 --base develop \
83- --head "${{ steps.vars.outputs.branch }}" \
65+ --head master \
8466 --title "$TITLE" \
8567 --label "[maintainer] auto-pull-request" \
86- --body "$BODY"
68+ --body "$BODY")
69+ PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
70+ echo "Created PR #${PR_NUMBER}"
71+ echo "pr_number=${PR_NUMBER}" >> "$GITHUB_OUTPUT"
8772 fi
8873 env :
8974 GH_TOKEN : ${{ steps.app-token.outputs.token }}
9075
9176 - name : Enable auto-merge using MERGE COMMIT
9277 run : |
9378 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 }}"
79+ gh pr merge --repo "${{ github.repository }}" --merge --auto "${{ steps.pr.outputs.pr_number }}"
9680 env :
9781 GH_TOKEN : ${{ steps.app-token.outputs.token }}
0 commit comments