-
Notifications
You must be signed in to change notification settings - Fork 1
252 lines (227 loc) · 8.49 KB
/
maven.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
name: Java CI with Maven
on:
push:
branches:
- Release*
- main
- testrelease
- testmain
pull_request:
branches:
- Release*
- main
- testrelease
- testmain
# Ensure only one build changes dev environment at the same time
concurrency: v2tofhir
# GITHUB_REF=refs/heads/testmain
#
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the software
uses: actions/checkout@v4
# Necessary to enable push to protected branch
with:
ssh-key: ${{secrets.ACTIONS_KEY}}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
cache: maven
- name: Set up Maven
uses: stCarolas/setup-maven@v5
with:
maven-version: 3.9.0
- name: Set up Toolchain
shell: bash
run: |
echo BASE_TAG=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout` >> $GITHUB_ENV
echo COMPUTERNAME=`hostname` >> $GITHUB_ENV
mkdir -p ~/.m2 \
&& cat << EOF > ~/.m2/toolchains.xml
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>11</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>$JAVA_HOME_11_X64</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>17</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>$JAVA_HOME_17_X64</jdkHome>
</configuration>
</toolchain>
</toolchains>
EOF
cat << EOF > ~/.m2/settings.xml
<?xml version="1.0" encoding="UTF8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>~/.m2/repository</localRepository>
<interactiveMode />
<usePluginRegistry />
<offline />
<servers>
<server>
<id>github</id>
<username>${{ env.GITHUB_ACTOR }}</username>
<password>${{ secrets.GITHUB_TOKEN }}</password>
</server>
</servers>
<mirrors />
<proxies />
<profiles />
<activeProfiles />
</settings>
EOF
- name: Sets env vars for push or pull request to release branch (default behavior)
run: |
echo IMAGE_TAG=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed "s/-SNAPSHOT$/-SNAPSHOT-${{github.run_number}}/"` >> $GITHUB_ENV
echo IMAGE_BRANCH_TAG=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout` >> $GITHUB_ENV
# default to force a revision check unless releasing
echo DO_REVISION_CHECK=true >> $GITHUB_ENV
# Skip dependency check
echo SKIP_DEPENDENCY_CHECK=false >> $GITHUB_ENV
# If pulling to main branch (cutting a release), set branch tag appropriately
- name: Sets env vars for pull to main
if: ${{ github.base_ref == 'main' }}
run: |
IMAGE_TAG=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed "s/-.*$/-IZGW-SNAPSHOT-${{github.run_number}}/"`
echo IMAGE_TAG=$IMAGE_TAG >> $GITHUB_ENV
IMAGE_BRANCH_TAG=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed "s/-.*$/-IZGW-SNAPSHOT/"`
echo IMAGE_BRANCH_TAG=$IMAGE_BRANCH_TAG >> $GITHUB_ENV
mvn versions:set -DnewVersion=$IMAGE_BRANCH_TAG -f pom.xml
# Skip revision check on merge
echo DO_REVISION_CHECK=false >> $GITHUB_ENV
# Skip dependency check
echo SKIP_DEPENDENCY_CHECK=false >> $GITHUB_ENV
# If pushing to main branch (cutting a release), set branch tag appropriately
- name: Sets env vars for pull to main
if: ${{ github.ref_name == 'main' }}
run: |
IMAGE_TAG=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed "s/-.*$/-IZGW-RELEASE-${{github.run_number}}/"`
echo IMAGE_TAG=$IMAGE_TAG >> $GITHUB_ENV
IMAGE_BRANCH_TAG=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed "s/-.*$/-IZGW-RELEASE/"`
echo IMAGE_BRANCH_TAG=$IMAGE_BRANCH_TAG >> $GITHUB_ENV
mvn versions:set -DnewVersion=$IMAGE_BRANCH_TAG -f pom.xml
if [ ${{ github.event_name }} == 'push' ]
then
git config user.name github-actions
git config user.email [email protected]
git add -A
# Only push if something was committed
if git commit -m "Update version to $IMAGE_BRANCH_TAG"
then
git pull
git push
fi
fi
# Disable revision check on push to main.
echo DO_REVISION_CHECK=false >> $GITHUB_ENV
# But enable dependency check
echo SKIP_DEPENDENCY_CHECK=false >> $GITHUB_ENV
- name: List m2
shell: bash
run: |
# Display data for DX
echo BASE_REF: ${{ github.base_ref }}
echo HEAD_REF: ${{ github.head_ref }}
echo REF_NAME: ${{ github.ref_name }}
echo REF: ${{ github.ref }}
echo EVENT_NAME ${{ github.event_name }}
echo TAG: $BASE_TAG
echo DO_REVISION_CHECK: $DO_REVISION_CHECK
echo SKIP_DEPENDENCY_CHECK: $SKIP_DEPENDENCY_CHECK
echo IMAGE_TAG: $IMAGE_TAG
echo IMAGE_BRANCH_TAG: $IMAGE_BRANCH_TAG
cd ~/.m2
ls -l
- name: Check that push to main is from release branch
# Don't filter on testmain to test push to main route
if: ${{ ! startsWith(github.base_ref, 'Release_v') && github.head_ref == 'main' }}
run: |
echo ${{ github.head_ref }} is NOT a Release branch and cannot be pushed to main
# Force failure
false
- name: Maven Install
env:
COMMON_PASS: ${{ secrets.COMMON_PASS }}
ELASTIC_API_KEY: ${{ secrets.ELASTIC_API_KEY }}
run: |
env && mvn -B clean package install deploy site -Dbuildno=${{github.run_number}} \
-DdoRevisionCheck=${{env.DO_REVISION_CHECK}} \
-DskipDependencyCheck=${{env.SKIP_DEPENDENCY_CHECK}} \
-Dimage.tag=$IMAGE_BRANCH_TAG
- name: Publish Site
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/site
destination_dir: current
- name: Upload build environment as artifact for failed build
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: build-failure
path: .
- name: Upload dependency check log
uses: actions/upload-artifact@v4
if: ${{ ! env.SKIP_DEPENDENCY_CHECK }}
with:
name: DependencyCheck
path: ./target/dependency-check-report.*
release:
needs: build
runs-on: ubuntu-latest
# This step should only be done on PUSH to main
if: github.ref == 'refs/heads/testmain' || github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
# Necessary to enable push to protected branch
with:
ssh-key: ${{secrets.ACTIONS_KEY}}
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{env.TAG}}
name: IZ Gateway ${{env.TAG}} Release
body_path: ./docs/release/RELEASE_NOTES.md
draft: true
generate_release_notes: true
files: |
./docs/release/*.md
- name: Upload release documentation as artifact for failed release
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: release-failure
path: ./docs/release/*.md
- name: Checkin Release Documentation to Build
run: |
git config user.name github-actions
git config user.email [email protected]
git config pull.rebase false
git add ./docs/release
if git commit -m "generated"
then
git pull
git push
fi