-
Notifications
You must be signed in to change notification settings - Fork 10
165 lines (145 loc) · 5.98 KB
/
prepare-release-branch.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Prepare release branch
on:
workflow_dispatch:
inputs:
prerelease_version:
description: "Pre-release version number? (e.g. 1.9.0rc2)"
required: False
jobs:
prereqs:
environment: GITHUB
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install toml
run: pip install toml
- name: Verify prerequisites
env:
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
run: |
if [[ $GITHUB_REF_NAME != main ]]; then
echo this workflow should only be run against main
exit 1
fi
if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
echo the change log is missing an \"Unreleased\" section
exit 1
fi
chmod +x ./.github/scripts/get-version.sh
if [[ ! -z $PRERELEASE_VERSION ]]; then
stable_version=$(./.github/scripts/get-version.sh)
if [[ $PRERELEASE_VERSION != ${stable_version}* ]]; then
echo "$PRERELEASE_VERSION is not a prerelease for the version on main ($stable_version)"
exit 1
fi
fi
create-pull-request-against-release-branch:
environment: GITHUB
runs-on: ubuntu-latest
needs: prereqs
steps:
- uses: actions/checkout@v4
- name: Install toml
run: pip install toml
- name: Create release branch
env:
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
run: |
if [[ -z $PRERELEASE_VERSION ]]; then
stable_version=$(./.github/scripts/get-version.sh)
else
stable_version=$PRERELEASE_VERSION
fi
if [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
stable_version_branch_part=$(echo $stable_version | sed -E 's/([0-9]+)\.([0-9]+)\.0/\1.\2.0/')
release_branch_name="release/v${stable_version_branch_part}"
elif [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0 ]]; then
# pre-release version, e.g. 1.9.0rc2
release_branch_name="release/v$stable_version"
else
echo "unexpected version: $stable_version"
exit 1
fi
git push origin HEAD:$release_branch_name
echo "STABLE_VERSION=$stable_version" >> $GITHUB_ENV
echo "RELEASE_BRANCH_NAME=$release_branch_name" >> $GITHUB_ENV
- name: Update the change log with the approximate release date
run: |
date=$(date "+%Y-%m-%d")
sed -Ei "s/^## Unreleased$/## Version ${STABLE_VERSION} ($date)/" CHANGELOG.md
- name: Create pull request against the release branch
env:
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
USER_NAME: ${{ secrets.GIT_USER_NAME }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
message="Prepare release ${STABLE_VERSION}"
branch="monocle/prepare-release-${STABLE_VERSION}"
git config --global user.email "$USER_EMAIL"
git config --global user.name "$USER_NAME"
git commit -a -m "$message"
git push origin HEAD:$branch
gh pr create --title "[$RELEASE_BRANCH_NAME] $message" \
--body "$message." \
--head $branch \
--base $RELEASE_BRANCH_NAME
create-pull-request-against-main:
environment: GITHUB
runs-on: ubuntu-latest
needs: [prereqs, create-pull-request-against-release-branch]
steps:
- uses: actions/checkout@v4
- name: Install toml
run: pip install toml
- name: Set environment variables
env:
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
run: |
if [[ -z $PRERELEASE_VERSION ]]; then
stable_version=$(./.github/scripts/get-version.sh)
else
stable_version=$PRERELEASE_VERSION
fi
if [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
stable_major="${BASH_REMATCH[1]}"
stable_minor="${BASH_REMATCH[2]}"
stable_next_version="$stable_major.$((stable_minor + 1)).0"
elif [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0 ]]; then
# pre-release version, e.g. 1.9.0rc2
stable_major="${BASH_REMATCH[1]}"
stable_minor="${BASH_REMATCH[2]}"
stable_next_version="$stable_major.$stable_minor.0"
else
echo "unexpected stable_version: $stable_version"
exit 1
fi
echo "STABLE_VERSION=${stable_version}" >> $GITHUB_ENV
echo "STABLE_NEXT_VERSION=${stable_next_version}" >> $GITHUB_ENV
- name: Update version
run: |
chmod +x ./.github/scripts/update-version.sh
.github/scripts/update-version.sh $STABLE_NEXT_VERSION
- name: Update the change log on main
run: |
# the actual release date on main will be updated at the end of the release workflow
date=$(date "+%Y-%m-%d")
sed -Ei "s/^## Unreleased$/## Version ${STABLE_VERSION} ($date)/" CHANGELOG.md
- name: Create pull request against main
env:
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
USER_NAME: ${{ secrets.GIT_USER_NAME }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
message="Update version to ${STABLE_NEXT_VERSION}"
body="Update version to ${STABLE_NEXT_VERSION}."
branch="monocle/update-version-to-${STABLE_NEXT_VERSION}"
git config --global user.email "$USER_EMAIL"
git config --global user.name "$USER_NAME"
git commit -a -m "$message"
git push origin HEAD:$branch
gh pr create --title "$message" \
--body "$body" \
--head $branch \
--base main