-
Notifications
You must be signed in to change notification settings - Fork 34
205 lines (178 loc) · 6.73 KB
/
bump-version.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: Bump Version
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
inputs:
branch:
description: 'Branch to bump version on'
required: true
version:
description: 'Version to bump to'
required: true
jobs:
bump-version-manual:
name: Bump Version (Manual)
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
permissions:
contents: write
pull-requests: write
steps:
- name: GitHub App Token
if: github.repository == 'opensearch-project/opensearch-rs'
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: Install latest stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-make
uses: davidB/rust-cargo-make@v1
- name: Bump Version
run: cargo make update-version "$VERSION"
env:
VERSION: ${{ github.event.inputs.version }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
base: ${{ github.event.inputs.branch }}
branch: "feat/${{ github.event.inputs.branch }}/bump-version"
commit-message: Bump version to ${{ github.event.inputs.version }}
signoff: true
delete-branch: true
title: '[AUTO] Bump version on `${{ github.event.inputs.branch }}` to `${{ github.event.inputs.version }}`'
labels: autocut
body: |
Bumping version on `${{ github.event.inputs.branch }}` to `${{ github.event.inputs.version }}`.
bump-version-auto:
name: Bump Version (Auto)
runs-on: ubuntu-latest
if: github.repository == 'opensearch-project/opensearch-rs' && github.event_name == 'push'
steps:
- name: GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout ${{ github.ref }}
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Install latest stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-make
uses: davidB/rust-cargo-make@v1
- name: Fetch Version Information
run: |
echo "GITHUB_REF=${GITHUB_REF}"
VERSION=$(echo "${GITHUB_REF#refs/*/v}")
VERSION_COMPONENTS=(${VERSION//./ })
MAJOR="${VERSION_COMPONENTS[0]}"
MINOR="${VERSION_COMPONENTS[1]}"
PATCH="${VERSION_COMPONENTS[2]}"
BASE="${MAJOR}.${MINOR}"
BASE_X="${MAJOR}.x"
IS_MAJOR_BUMP=false
IS_MINOR_BUMP=false
if [ "${PATCH}" = "0" ]; then
IS_MINOR_BUMP=true
if [ "${MINOR}" = "0" ]; then
IS_MAJOR_BUMP=true
fi
fi
NEXT_MAJOR="$((MAJOR + 1)).0.0"
NEXT_MINOR="${MAJOR}.$((MINOR + 1)).0"
NEXT_PATCH="${MAJOR}.${MINOR}.$((PATCH + 1))"
{
echo "VERSION=${VERSION}"
echo "MAJOR=${MAJOR}"
echo "MINOR=${MINOR}"
echo "PATCH=${PATCH}"
echo "BASE=${BASE}"
echo "BASE_X=${BASE_X}"
echo "IS_MAJOR_BUMP=${IS_MAJOR_BUMP}"
echo "IS_MINOR_BUMP=${IS_MINOR_BUMP}"
echo "NEXT_MAJOR=${NEXT_MAJOR}"
echo "NEXT_MINOR=${NEXT_MINOR}"
echo "NEXT_PATCH=${NEXT_PATCH}"
} | tee -a "${GITHUB_ENV}"
- name: Create ${{ env.BASE_X }} branch
if: env.IS_MAJOR_BUMP == 'true'
run: git branch ${BASE_X} && git push origin ${BASE_X}
- name: Create ${{ env.BASE }} branch
if: env.IS_MINOR_BUMP == 'true'
run: git branch ${BASE} && git push origin ${BASE}
- name: Checkout ${{ env.BASE }} branch
uses: actions/checkout@v4
with:
ref: ${{ env.BASE }}
token: ${{ steps.app-token.outputs.token }}
- name: Bump Patch Version
run: cargo make update-version "$NEXT_PATCH"
- name: Create Patch Version Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.app-token.outputs.token }}
base: ${{ env.BASE }}
branch: 'feat/${{ env.BASE }}/bump-version'
commit-message: Bump version to ${{ env.NEXT_PATCH }}
signoff: true
delete-branch: true
title: '[AUTO] Bump version on `${{ env.BASE }}` to `${{ env.NEXT_PATCH }}`'
labels: autocut
body: |
Bumping version on `${{ env.BASE }}` to `${{ env.NEXT_PATCH }}`.
- name: Checkout ${{ env.BASE_X }} branch
if: env.IS_MINOR_BUMP == 'true'
uses: actions/checkout@v4
with:
ref: ${{ env.BASE_X }}
token: ${{ steps.app-token.outputs.token }}
- name: Bump Minor Version
if: env.IS_MINOR_BUMP == 'true'
run: cargo make update-version "$NEXT_MINOR"
- name: Create Minor Version Pull Request
if: env.IS_MINOR_BUMP == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.app-token.outputs.token }}
base: ${{ env.BASE_X }}
branch: 'feat/${{ env.BASE_X }}/bump-version'
commit-message: Bump version to ${{ env.NEXT_MINOR }}
signoff: true
delete-branch: true
title: '[AUTO] Bump version on `${{ env.BASE_X }}` to `${{ env.NEXT_MINOR }}`'
labels: autocut
body: |
Bumping version on `${{ env.BASE_X }}` to `${{ env.NEXT_MINOR }}`.
- name: Checkout main branch
if: env.IS_MAJOR_BUMP == 'true'
uses: actions/checkout@v4
with:
ref: main
token: ${{ steps.app-token.outputs.token }}
- name: Bump Major Version
if: env.IS_MAJOR_BUMP == 'true'
run: cargo make update-version "$NEXT_MAJOR"
- name: Create Major Version Pull Request
if: env.IS_MAJOR_BUMP == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.app-token.outputs.token }}
base: main
branch: 'feat/main/bump-version'
commit-message: Bump version to ${{ env.NEXT_MAJOR }}
signoff: true
delete-branch: true
title: '[AUTO] Bump version on `main` to `${{ env.NEXT_MAJOR }}`'
labels: autocut
body: |
Bumping version on `main` to `${{ env.NEXT_MAJOR }}`.