-
-
Notifications
You must be signed in to change notification settings - Fork 145
235 lines (231 loc) · 12.3 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: "Create PR to bump version"
on:
workflow_dispatch:
inputs:
targetBranch:
description: 'Target Branch'
required: true
type: choice
options:
- bugfix
- master
versionType:
description: 'What Version to Bump'
required: true
type: choice
options:
- build
- minor
- major
jobs:
build:
if: ${{ github.event.inputs.versionType == 'build' }}
runs-on: ubuntu-latest
steps:
# Setup
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Install required packages
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq
- name: Save targetBranch to env
if: github.event.inputs.targetBranch != 'bugfix'
run: echo "targetBranch=${{ github.event.inputs.targetBranch }}" >> $GITHUB_ENV
# Save old version
- name: Find and save old major_version from manifest
run: awk 'BEGIN { FS="=" } /^major_version/ { print "oldMajor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old minor_version from manifest
run: awk 'BEGIN { FS="=" } /^minor_version/ { print "oldMinor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old build_version from manifest
run: awk 'BEGIN { FS="=" } /^build_version/ { print "oldBuild="$2; }' manifest >> $GITHUB_ENV
# Bugfix branch
- name: Save bugfix branch name
if: github.event.inputs.targetBranch == 'bugfix'
run: echo "bugfixBranch=${{ env.oldMajor }}.${{ env.oldMinor }}.z" >> $GITHUB_ENV
- name: Update targetBranch with actual bugfix branch name
if: github.event.inputs.targetBranch == 'bugfix'
run: echo "targetBranch=${{ env.bugfixBranch }}" >> $GITHUB_ENV
- name: Checkout bugfix branch
if: github.event.inputs.targetBranch == 'bugfix'
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
ref: ${{ env.targetBranch }}
# Save old version again if needed
- name: Find and save old major_version from manifest
if: github.event.inputs.targetBranch == 'bugfix'
run: awk 'BEGIN { FS="=" } /^major_version/ { print "oldMajor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old minor_version from manifest
if: github.event.inputs.targetBranch == 'bugfix'
run: awk 'BEGIN { FS="=" } /^minor_version/ { print "oldMinor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old build_version from manifest
if: github.event.inputs.targetBranch == 'bugfix'
run: awk 'BEGIN { FS="=" } /^build_version/ { print "oldBuild="$2; }' manifest >> $GITHUB_ENV
# Calculate new version
- name: Calculate new build_version
run: echo "newBuild=$((${{ env.oldBuild }} + 1))" >> $GITHUB_ENV
- name: Save new version to env var
run: echo "newVersion=${{ env.oldMajor }}.${{ env.oldMinor }}.${{ env.newBuild }}" >> $GITHUB_ENV
- name: Save a copy of newVersion without periods to env var
run: echo "newVersionSlug=${{ env.newVersion }}" | sed -e 's/\.//g' >> $GITHUB_ENV
# Update files with new versions
- name: Update manifest build_version
run: sed -i "s/build_version=.*/build_version=${{ env.newBuild }}/g" manifest
- name: Update package-lock.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package-lock.json version 2
run: echo "$( jq '.packages."".version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package.json )" > package.json
- name: Update Makefile version
run: sed -i "s/VERSION := .*/VERSION := ${{ env.newVersion }}/g" Makefile
# Create PR
- name: Save new branch name to env
run: echo "newBranch=bump-${{ github.event.inputs.targetBranch }}-to-${{ env.newVersionSlug }}" >> $GITHUB_ENV
- name: Create PR with new version
env:
GH_TOKEN: ${{ secrets.JF_BOT_TOKEN }}
run: |-
git config user.name "jellyfin-bot"
git config user.email "[email protected]"
git checkout -b "${{ env.newBranch }}"
git add .
git commit -m "Bump ${{ github.event.inputs.versionType }} version"
git push --set-upstream origin "${{ env.newBranch }}"
gh pr create --title "Bump ${{ github.event.inputs.targetBranch }} branch to ${{ env.newVersion }}" --body "Bump version to prep for next release. Generated by `.github/workflows/bump-version.yml`" --label ignore-changelog --base ${{ env.targetBranch }}
minor:
if: ${{ github.event.inputs.versionType == 'minor' }}
runs-on: ubuntu-latest
steps:
# Setup
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Install jq to update json
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq
- name: Save targetBranch to env
if: github.event.inputs.targetBranch != 'bugfix'
run: echo "targetBranch=${{ github.event.inputs.targetBranch }}" >> $GITHUB_ENV
# Save old version
- name: Find and save old major_version from manifest
run: awk 'BEGIN { FS="=" } /^major_version/ { print "oldMajor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old minor_version from manifest
run: awk 'BEGIN { FS="=" } /^minor_version/ { print "oldMinor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old build_version from manifest
run: awk 'BEGIN { FS="=" } /^build_version/ { print "oldBuild="$2; }' manifest >> $GITHUB_ENV
# Bugfix branch
- name: Save bugfix branch name
if: github.event.inputs.targetBranch == 'bugfix'
run: echo "bugfixBranch=${{ env.oldMajor }}.${{ env.oldMinor }}.z" >> $GITHUB_ENV
- name: Update targetBranch with actual bugfix branch name
if: github.event.inputs.targetBranch == 'bugfix'
run: echo "targetBranch=${{ env.bugfixBranch }}" >> $GITHUB_ENV
- name: Checkout bugfix branch
if: github.event.inputs.targetBranch == 'bugfix'
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
ref: ${{ env.targetBranch }}
# Calculate new version
- name: Calculate new build_version
run: echo "newMinor=$((${{ env.oldMinor }} + 1))" >> $GITHUB_ENV
- name: Save new version to env var
run: echo "newVersion=${{ env.oldMajor }}.${{ env.newMinor }}.0" >> $GITHUB_ENV
- name: Save a copy of newVersion without periods to env var
run: echo "newVersionSlug=${{ env.newVersion }}" | sed -e 's/\.//g' >> $GITHUB_ENV
# Update files with new versions
- name: Update manifest minor_version
run: sed -i "s/minor_version=.*/minor_version=${{ env.newMinor }}/g" manifest
- name: Update manifest build_version
run: sed -i "s/build_version=.*/build_version=0/g" manifest
- name: Update package-lock.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package-lock.json version 2
run: echo "$( jq '.packages."".version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package.json )" > package.json
- name: Update Makefile version
run: sed -i "s/VERSION := .*/VERSION := ${{ env.newVersion }}/g" Makefile
# Create PR
- name: Save new branch name to env
run: echo "newBranch=bump-${{ github.event.inputs.targetBranch }}-to-${{ env.newVersionSlug }}" >> $GITHUB_ENV
- name: Create PR with new version
env:
GH_TOKEN: ${{ secrets.JF_BOT_TOKEN }}
run: |-
git config user.name "jellyfin-bot"
git config user.email "[email protected]"
git checkout -b "${{ env.newBranch }}"
git add .
git commit -m "Bump ${{ github.event.inputs.versionType }} version"
git push --set-upstream origin "${{ env.newBranch }}"
gh pr create --title "Bump ${{ github.event.inputs.targetBranch }} branch to ${{ env.newVersion }}" --body "Bump version to prep for next release. Generated by `.github/workflows/bump-version.yml`" --label ignore-changelog --base ${{ env.targetBranch }}
major:
if: ${{ github.event.inputs.versionType == 'major' }}
runs-on: ubuntu-latest
steps:
# Setup
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Install jq to update json
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq
- name: Save targetBranch to env
if: github.event.inputs.targetBranch != 'bugfix'
run: echo "targetBranch=${{ github.event.inputs.targetBranch }}" >> $GITHUB_ENV
# Save old version
- name: Find and save old major_version from manifest
run: awk 'BEGIN { FS="=" } /^major_version/ { print "oldMajor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old minor_version from manifest
run: awk 'BEGIN { FS="=" } /^minor_version/ { print "oldMinor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old build_version from manifest
run: awk 'BEGIN { FS="=" } /^build_version/ { print "oldBuild="$2; }' manifest >> $GITHUB_ENV
# Bugfix branch
- name: Save bugfix branch name
if: github.event.inputs.targetBranch == 'bugfix'
run: echo "bugfixBranch=${{ env.oldMajor }}.${{ env.oldMinor }}.z" >> $GITHUB_ENV
- name: Update targetBranch with actual bugfix branch name
if: github.event.inputs.targetBranch == 'bugfix'
run: echo "targetBranch=${{ env.bugfixBranch }}" >> $GITHUB_ENV
- name: Checkout bugfix branch
if: github.event.inputs.targetBranch == 'bugfix'
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
ref: ${{ env.targetBranch }}
# Calculate new version
- name: Calculate new build_version
run: echo "newMajor=$((${{ env.oldMajor }} + 1))" >> $GITHUB_ENV
- name: Save new version to env var
run: echo "newVersion=${{ env.newMajor }}.0.0" >> $GITHUB_ENV
- name: Save a copy of newVersion without periods to env var
run: echo "newVersionSlug=${{ env.newVersion }}" | sed -e 's/\.//g' >> $GITHUB_ENV
# Update files with new versions
- name: Update manifest major_version
run: sed -i "s/major_version=.*/major_version=${{ env.newMajor }}/g" manifest
- name: Update manifest minor_version
run: sed -i "s/minor_version=.*/minor_version=0/g" manifest
- name: Update manifest build_version
run: sed -i "s/build_version=.*/build_version=0/g" manifest
- name: Update package-lock.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package-lock.json version 2
run: echo "$( jq '.packages."".version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package.json )" > package.json
- name: Update Makefile version
run: sed -i "s/VERSION := .*/VERSION := ${{ env.newVersion }}/g" Makefile
# Create PR
- name: Save new branch name to env
run: echo "newBranch=bump-${{ github.event.inputs.targetBranch }}-to-${{ env.newVersionSlug }}" >> $GITHUB_ENV
- name: Create PR with new version
env:
GH_TOKEN: ${{ secrets.JF_BOT_TOKEN }}
run: |-
git config user.name "jellyfin-bot"
git config user.email "[email protected]"
git checkout -b "${{ env.newBranch }}"
git add .
git commit -m "Bump ${{ github.event.inputs.versionType }} version"
git push --set-upstream origin "${{ env.newBranch }}"
gh pr create --title "Bump ${{ github.event.inputs.targetBranch }} branch to ${{ env.newVersion }}" --body "Bump version to prep for next release. Generated by `.github/workflows/bump-version.yml`" --label ignore-changelog --base ${{ env.targetBranch }}