Skip to content

Commit 41dab09

Browse files
committed
Refactor mergeback branch prep into an action
1 parent 541b8e4 commit 41dab09

File tree

2 files changed

+72
-41
lines changed

2 files changed

+72
-41
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: "Prepare mergeback branch"
2+
description: Prepares a mergeback branch and opens a PR for it
3+
inputs:
4+
base:
5+
description: "The name of the base branch"
6+
required: true
7+
head:
8+
description: "The name of the head branch"
9+
required: true
10+
branch:
11+
description: "The name of the branch to create."
12+
required: true
13+
version:
14+
description: "The new version"
15+
required: true
16+
token:
17+
description: "The token to use"
18+
required: true
19+
runs:
20+
using: composite
21+
steps:
22+
- name: Create mergeback branch
23+
env:
24+
VERSION: "${{ inputs.version }}"
25+
BASE_BRANCH: "${{ inputs.base }}"
26+
HEAD_BRANCH: "${{ inputs.head }}"
27+
NEW_BRANCH: "${{ inputs.branch }}"
28+
GITHUB_TOKEN: "${{ inputs.token }}"
29+
run: |
30+
set -exu
31+
pr_title="Mergeback ${VERSION} ${HEAD_BRANCH} into ${BASE_BRANCH}"
32+
pr_body=$(cat << EOF
33+
This PR bumps the version number and updates the changelog after the ${VERSION} release.
34+
35+
Please do the following:
36+
37+
- [ ] Remove and re-add the "Update dependencies" label to the PR to trigger just this workflow.
38+
- [ ] Wait for the "Update dependencies" workflow to push a commit updating the dependencies.
39+
- [ ] Mark the PR as ready for review to trigger the full set of PR checks.
40+
- [ ] Approve and merge the PR. When merging the PR, make sure "Create a merge commit" is
41+
selected rather than "Squash and merge" or "Rebase and merge".
42+
EOF
43+
)
44+
45+
# Update the version number ready for the next release
46+
npm version patch --no-git-tag-version
47+
48+
# Update the changelog, adding a new version heading directly above the most recent existing one
49+
awk '!f && /##/{print "'"## [UNRELEASED]\n\nNo user facing changes.\n"'"; f=1}1' CHANGELOG.md > temp && mv temp CHANGELOG.md
50+
git add .
51+
git commit -m "Update changelog and version after ${VERSION}"
52+
53+
git push origin "${NEW_BRANCH}"
54+
55+
# PR checks won't be triggered on PRs created by Actions. Therefore mark the PR as draft
56+
# so that a maintainer can take the PR out of draft, thereby triggering the PR checks.
57+
gh pr create \
58+
--head "${NEW_BRANCH}" \
59+
--base "${BASE_BRANCH}" \
60+
--title "${pr_title}" \
61+
--label "Update dependencies" \
62+
--body "${pr_body}" \
63+
--assignee "${GITHUB_ACTOR}" \
64+
--draft

.github/workflows/post-release-mergeback.yml

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -124,48 +124,15 @@ jobs:
124124
cat $PARTIAL_CHANGELOG
125125
echo "::endgroup::"
126126
127-
- name: Create mergeback branch
127+
- name: Create mergeback branch and PR
128128
if: ${{ steps.check.outputs.exists != 'true' && endsWith(github.ref_name, steps.getVersion.outputs.latest_release_branch) }}
129-
env:
130-
VERSION: "${{ steps.getVersion.outputs.version }}"
131-
NEW_BRANCH: "${{ steps.getVersion.outputs.newBranch }}"
132-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
133-
run: |
134-
set -exu
135-
pr_title="Mergeback ${VERSION} ${HEAD_BRANCH} into ${BASE_BRANCH}"
136-
pr_body=$(cat << EOF
137-
This PR bumps the version number and updates the changelog after the ${VERSION} release.
138-
139-
Please do the following:
140-
141-
- [ ] Remove and re-add the "Update dependencies" label to the PR to trigger just this workflow.
142-
- [ ] Wait for the "Update dependencies" workflow to push a commit updating the dependencies.
143-
- [ ] Mark the PR as ready for review to trigger the full set of PR checks.
144-
- [ ] Approve and merge the PR. When merging the PR, make sure "Create a merge commit" is
145-
selected rather than "Squash and merge" or "Rebase and merge".
146-
EOF
147-
)
148-
149-
# Update the version number ready for the next release
150-
npm version patch --no-git-tag-version
151-
152-
# Update the changelog, adding a new version heading directly above the most recent existing one
153-
awk '!f && /##/{print "'"## [UNRELEASED]\n\nNo user facing changes.\n"'"; f=1}1' CHANGELOG.md > temp && mv temp CHANGELOG.md
154-
git add .
155-
git commit -m "Update changelog and version after ${VERSION}"
156-
157-
git push origin "${NEW_BRANCH}"
158-
159-
# PR checks won't be triggered on PRs created by Actions. Therefore mark the PR as draft
160-
# so that a maintainer can take the PR out of draft, thereby triggering the PR checks.
161-
gh pr create \
162-
--head "${NEW_BRANCH}" \
163-
--base "${BASE_BRANCH}" \
164-
--title "${pr_title}" \
165-
--label "Update dependencies" \
166-
--body "${pr_body}" \
167-
--assignee "${GITHUB_ACTOR}" \
168-
--draft
129+
uses: ./.github/actions/prepare-mergeback-branch
130+
with:
131+
base: "${{ env.BASE_BRANCH }}"
132+
head: "${{ env.HEAD_BRANCH }}"
133+
branch: "${{ steps.getVersion.outputs.newBranch }}"
134+
version: "${{ steps.getVersion.outputs.version }}"
135+
token: "${{ secrets.GITHUB_TOKEN }}"
169136

170137
- name: Generate token
171138
uses: actions/[email protected]

0 commit comments

Comments
 (0)