-
Notifications
You must be signed in to change notification settings - Fork 0
256 lines (238 loc) · 11.3 KB
/
release_version_poc.yaml
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
name: Increment Release Version Pipeline
run-name: "Incrementing Release Version -- ${{github.event.inputs.action}}"
on:
workflow_dispatch:
inputs:
action:
type: choice
description: Version To Increment (If Custom. Please Input Release or Development Version Below)
options:
- Major
- Minor
- Patch
- Custom
required: true
release_version:
description: Name of release. May follow SemVer (Major.Minor.Patch) format
development_version:
description: Name of next development version. Must follow SemVer + "-" + <TEXT> (Major.Minor.Patch-TEXT) format
env:
INCREMENTING_VERSION: ${{github.event.inputs.action}}
DEVELOPMENT_VERSION_INPUT: ${{github.event.inputs.development_version}}
RELEASE_VERSION_INPUT: ${{github.event.inputs.release_version}}
jobs:
get_custom_inputs:
runs-on: ubuntu-latest
name: Get Custom Inputs
env:
NEXT_DEV_VERSION: ""
NEXT_RELEASE_VERSION: ""
outputs:
REUSE_DEV_VERSION: ${{env.NEXT_DEV_VERSION}}
REUSE_RELEASE_VERSION: ${{env.NEXT_RELEASE_VERSION}}
if: ${{github.event.inputs.action}} == 'Custom'
steps:
- name: Stops If Fields Are Empty
if: ${{env.DEVELOPMENT_VERSION_INPUT}} == '' && ${{env.RELEASE_VERSION_INPUT}} == ''
run: |
echo "Please Enter A Development Or Release Version"
exit 1
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Downloading Java
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: Get Current Version
run: |
echo "POM_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Set Release Version
run: echo "NEXT_RELEASE_VERSION=${{env.POM_VERSION}}" >> $GITHUB_ENV
- name: If Developemt Version Is Entered And Does Not Contains SNAPSHOT
if: ${{env.DEVELOPMENT_VERSION_INPUT}} != '' && !contains(${{env.DEVELOPMENT_VERSION_INPUT}}, '-SNAPSHOT')
run: "Setting Next Dev To ${{env.NEXT_DEV_VERSION}}"
env:
NEXT_DEV_VERSION: ${{env.DEVELOPMENT_VERSION_INPUT}}
- name: If Developemt Version Is Entered And Contains SNAPSHOT
if: ${{env.DEVELOPMENT_VERSION_INPUT}} != '' && contains(${{env.DEVELOPMENT_VERSION_INPUT}}, '-SNAPSHOT')
uses: xom9ikk/split@v1
id: splitVersionDev
with:
string: ${{env.DEVELOPMENT_VERSION_INPUT}}
separator: -SNAPSHOT
limit: -1
- name: If Developemt Version Is Entered And Contains SNAPSHOT - Set Enviroment
if: ${{env.DEVELOPMENT_VERSION_INPUT}} != '' && contains(${{env.DEVELOPMENT_VERSION_INPUT}}, '-SNAPSHOT')
run: echo "NEXT_DEV_VERSION=${{steps.splitVersionDev.outputs._0}}"
- name: If Release Version Is Entered And Does Not Contains SNAPSHOT
if: ${{env.RELEASE_VERSION_INPUT}} != '' && !contains(${{env.RELEASE_VERSION_INPUT}}, '-SNAPSHOT')
run: "Setting Next Release To ${{env.NEXT_RELEASE_VERSION}}"
env:
NEXT_RELEASE_VERSION: ${{env.RELEASE_VERSION_INPUT}}
- name: If Release Version Is Entered And Contains SNAPSHOT
if: ${{env.RELEASE_VERSION_INPUT}} != '' && contains(${{env.RELEASE_VERSION_INPUT}}, '-SNAPSHOT')
uses: xom9ikk/split@v1
id: splitVersionRelease
with:
string: ${{env.RELEASE_VERSION_INPUT}}
separator: -SNAPSHOT
limit: -1
- name: If Release Version Is Entered And Contains SNAPSHOT - Set Enviroment
if: ${{env.DEVELOPMENT_VERSION_INPUT}} != '' && contains(${{env.DEVELOPMENT_VERSION_INPUT}}, '-SNAPSHOT')
run: echo "NEXT_RELEASE_VERSION=${{steps.splitVersionRelease.outputs._0}}"
calling-release-workflow:
needs: get_custom_inputs
permissions: write-all
uses: OmOmofonmwan/GitHub_Actions_POC/.github/workflows/reusable_release_poc.yaml@main
with:
release_version: ${{needs.get_custom_inputs.outputs.REUSE_RELEASE_VERSION}}
snapshot_version: ${{needs.get_custom_inputs.outputs.REUSE_DEV_VERSION}}
get_version:
runs-on: ubuntu-latest
name: Get Version
if: ${{github.event.inputs.action}} != 'Custom'
outputs:
RELEASE_VERSION: ${{steps.splitVersion.outputs._0}}
_MAJOR: ${{steps.splitVersionMinor.outputs._0}}
_MINOR: ${{steps.splitVersionMinor.outputs._1}}
_PATCH: ${{steps.splitVersionMinor.outputs._2}}
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Downloading Java
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: Get Current Version
run: |
echo "POM_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Print Version
run: echo ${{env.POM_VERSION}}
- name: Split version code
uses: xom9ikk/split@v1
id: splitVersion
with:
string: ${{env.POM_VERSION}}
separator: -SNAPSHOT
limit: -1
- name: Split version code - Minor
uses: xom9ikk/split@v1
id: splitVersionMinor
with:
string: ${{steps.splitVersion.outputs._0}}
separator: .
limit: -1
increment_version:
runs-on: ubuntu-latest
needs: get_version
outputs:
NEXT_SNAPSHOT_VERSION: ${{steps.nextSnapshotVersion.outputs.NEXT_SNAPSHOT_VERSION}}
RELEASE_VERSION: ${{needs.get_version.outputs.RELEASE_VERSION}}
name: "Increment ${{github.event.inputs.action}} Version"
steps:
- name: Set Env - Major
shell: bash
run: |
VERSION_PICKED=${{env.INCREMENTING_VERSION}}
if [[ "$VERSION_PICKED" == "Major" ]]; then
echo "VERSION_NUMBER=${{needs.get_version.outputs._MAJOR}}" >> $GITHUB_ENV
elif [[ "$VERSION_PICKED" == "Minor" ]]; then
echo "VERSION_NUMBER=${{needs.get_version.outputs._MINOR}}" >> $GITHUB_ENV
else
echo "VERSION_NUMBER=${{needs.get_version.outputs._PATCH}}" >> $GITHUB_ENV
fi
- name: Print Version
run: echo ${{env.INCREMENTING_VERSION}} -- ${{env.VERSION_NUMBER}}
- name: Increment Version
run: echo "NEW_VERSION_NUMBER=$((${{env.VERSION_NUMBER}} + 1))" >> $GITHUB_ENV
- name: Generate New Snapshot Version Output
id: nextSnapshotVersion
shell: bash
run: |
VERSION_PICKED=${{env.INCREMENTING_VERSION}}
if [[ "$VERSION_PICKED" == "Major" ]]; then
echo "NEXT_SNAPSHOT_VERSION=${{env.NEW_VERSION_NUMBER}}.0.0" >> $GITHUB_OUTPUT
elif [[ "$VERSION_PICKED" == "Minor" ]]; then
echo "NEXT_SNAPSHOT_VERSION=${{needs.get_version.outputs._MAJOR}}.${{env.NEW_VERSION_NUMBER}}.0" >> $GITHUB_OUTPUT
else
echo "NEXT_SNAPSHOT_VERSION=${{needs.get_version.outputs._MAJOR}}.${{needs.get_version.outputs._MINOR}}.${{env.NEW_VERSION_NUMBER}}" >> $GITHUB_OUTPUT
fi
set_build_and_tag_release:
runs-on: ubuntu-latest
needs: increment_version
name: "Set, Build & Tag Release Version"
permissions:
contents: write
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Downloading Java
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Set Release Version
run: mvn -B versions:set -DnewVersion=${{needs.increment_version.outputs.RELEASE_VERSION}} -DgenerateBackupPoms=false
- name: Build Release Version
run: mvn -version mvn clean install
- name: Create tag
uses: actions/github-script@v5
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{needs.increment_version.outputs.RELEASE_VERSION}}',
sha: context.sha
})
set_next_dev:
runs-on: ubuntu-latest
name: Set Next Snapshot Version
needs:
- increment_version
- set_build_and_tag_release
permissions:
contents: write
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Downloading Java
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Set Dev Version
run: mvn -B versions:set -DnewVersion=${{needs.increment_version.outputs.NEXT_SNAPSHOT_VERSION}}-SNAPSHOT -DgenerateBackupPoms=false
- name: Commit & Push
run: |
git add .
git config user.name fda_shield_omoruyi
git config user.email [email protected]
git commit -m 'Set next dev version to ${{needs.increment_version.outputs.NEXT_SNAPSHOT_VERSION}}'
git push origin HEAD:main
git push --tags origin
create_release:
name: Create Release
permissions: write-all
needs:
- increment_version
- set_build_and_tag_release
- set_next_dev
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{needs.increment_version.outputs.RELEASE_VERSION}}
release_name: Release ${{needs.increment_version.outputs.RELEASE_VERSION}}
body: |
New Release Version ${{needs.increment_version.outputs.RELEASE_VERSION}}
draft: false
prerelease: false