Skip to content

Commit 9884e6d

Browse files
committed
Create mergeback branch/PR
1 parent 59fcfc8 commit 9884e6d

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

.github/workflows/rollback-release.yml

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,52 @@ jobs:
4242
- name: Checkout repository
4343
uses: actions/checkout@v5
4444
with:
45-
# We usually expect to checkout `inputs.rollback-tag` (required for `workflow_dispatch`),
46-
# but use `needs.prepare.outputs.latest_tag` for testing.
47-
ref: ${{ inputs.rollback-tag || needs.prepare.outputs.latest_tag }}
4845
fetch-depth: 0 # Need full history for calculation of diffs
4946

5047
- name: Configure runner for release
5148
uses: ./.github/actions/release-initialise
5249

50+
# We start by preparing the mergeback branch, mainly so that we have the updated changelog
51+
# readily available for the partial changelog that's needed for the release.
52+
- name: Prepare mergeback branch
53+
id: mergeback-branch
54+
env:
55+
BASE_BRANCH: "main"
56+
VERSION: ${{ needs.prepare.outputs.version }}
57+
run: |
58+
set -x
59+
60+
# Generate a new branch name for the mergeback PR
61+
short_sha="${GITHUB_SHA:0:8}"
62+
NEW_BRANCH="mergeback/${VERSION}-to-${BASE_BRANCH}-${short_sha}"
63+
echo "new-branch=${NEW_BRANCH}" >> $GITHUB_OUTPUT
64+
65+
# Create the mergeback branch
66+
git checkout -b "${NEW_BRANCH}"
67+
68+
- name: Prepare rollback changelog
69+
env:
70+
NEW_CHANGELOG: "${{ runner.temp }}/new_changelog.md"
71+
ROLLBACK_TAG: ${{ inputs.rollback-tag || needs.prepare.outputs.latest_tag }}
72+
LATEST_TAG: ${{ needs.prepare.outputs.latest_tag }}
73+
VERSION: "${{ needs.prepare.outputs.version }}"
74+
run: |
75+
python .github/workflows/script/rollback_changelog.py "${ROLLBACK_TAG:1}" "${LATEST_TAG:1}" "$VERSION" > $NEW_CHANGELOG
76+
77+
echo "::group::New CHANGELOG"
78+
cat $NEW_CHANGELOG
79+
echo "::endgroup::"
80+
5381
- name: Create tags
5482
shell: bash
5583
env:
84+
# We usually expect to checkout `inputs.rollback-tag` (required for `workflow_dispatch`),
85+
# but use `needs.prepare.outputs.latest_tag` for testing.
86+
ROLLBACK_TAG: ${{ inputs.rollback-tag || needs.prepare.outputs.latest_tag }}
5687
RELEASE_TAG: ${{ needs.prepare.outputs.version }}
5788
MAJOR_VERSION_TAG: ${{ needs.prepare.outputs.major_version }}
5889
run: |
90+
git checkout "refs/tags/${ROLLBACK_TAG}"
5991
git tag --annotate "${RELEASE_TAG}" --message "${RELEASE_TAG}"
6092
git tag --annotate "${MAJOR_VERSION_TAG}" --message "${MAJOR_VERSION_TAG}" --force
6193
@@ -70,10 +102,11 @@ jobs:
70102
71103
- name: Prepare partial Changelog
72104
env:
105+
NEW_CHANGELOG: "${{ runner.temp }}/new_changelog.md"
73106
PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md"
74107
VERSION: "${{ needs.prepare.outputs.version }}"
75108
run: |
76-
python .github/workflows/script/prepare_changelog.py CHANGELOG.md "$VERSION" > $PARTIAL_CHANGELOG
109+
python .github/workflows/script/prepare_changelog.py $NEW_CHANGELOG "$VERSION" > $PARTIAL_CHANGELOG
77110
78111
echo "::group::Partial CHANGELOG"
79112
cat $PARTIAL_CHANGELOG
@@ -87,7 +120,7 @@ jobs:
87120
app-id: ${{ vars.AUTOMATION_APP_ID }}
88121
private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }}
89122

90-
- name: Create the GitHub release
123+
- name: Create the rollback release
91124
if: github.event_name == 'workflow_dispatch'
92125
env:
93126
PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md"
@@ -102,3 +135,16 @@ jobs:
102135
--draft \
103136
--title "$VERSION" \
104137
--notes-file "$PARTIAL_CHANGELOG"
138+
139+
- name: Create mergeback branch and PR
140+
uses: ./.github/actions/prepare-mergeback-branch
141+
with:
142+
base: "main"
143+
head: ""
144+
branch: "${{ steps.mergeback-branch.outputs.new-branch }}"
145+
version: "${{ needs.prepare.outputs.version }}"
146+
token: "${{ secrets.GITHUB_TOKEN }}"
147+
# Setting this to `true` for non-workflow_dispatch events will
148+
# still push the `branch`, but won't create a corresponding PR
149+
dry-run: "${{ github.event_name != 'workflow_dispatch' }}"
150+

0 commit comments

Comments
 (0)