-
Notifications
You must be signed in to change notification settings - Fork 1
306 lines (288 loc) · 10.4 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
name: OpenMAQS Java Pipeline
on:
schedule:
- cron: "13 23 * * *"
push:
branches:
- main
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
override:
description: 'Version Number'
required: true
default: '0.0.0'
jobs:
waitOld:
name: Wait For Older Runs To Complete
runs-on: ubuntu-latest
steps:
- name: Wait
id: wait
shell: pwsh
run: |
$runID = ${{ github.run_id }}
$endPoint = "https://api.github.com/repos/${{github.repository}}/actions/runs"
$timeout = New-TimeSpan -Minutes 60
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
do {
$result = Invoke-RestMethod -Uri $endPoint
$builds = $result.workflow_runs | Where-Object {$_.name -eq "Build" -and ($_.status -eq "in_progress" -or $_.status -eq "queued") -and $_.id -lt $runID}
# Check if there were any older build runs still going, if not we waited long enough
if (!$builds)
{
Write-Host "Are now top of the run queue"
return
}
Start-Sleep -s 60
Write-Host "Waited so far $($stopwatch.elapsed)"
} while ($stopwatch.elapsed -lt $timeout)
Write-Host "Waited more than an hour for earlier runs to complete, continuing action pipeline"
draftRelease:
name: Draft release
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v6.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
dependency-tree:
name: Maven Dependency Tree
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4.2.1
with:
distribution: zulu
java-version: 17
cache: maven
- name: Restore Local Maven Cache
uses: actions/cache@v3.3.2
with:
path: ~/.m2
key: ${{runner.os}}-m2
- name: Submit Dependency Snapshot
uses: advanced-security/maven-dependency-submission-action@v3
getVersion:
name: Get package version
runs-on: ubuntu-latest
if: ${{ always() }}
outputs:
buildNumber: ${{ steps.ver.outputs.BUILD_NUMBER }}
tagName: ${{ steps.ver.outputs.TAG_NAME }}
steps:
- name: GetVersion
id: ver
shell: pwsh
run: |
if ("${{github.event.inputs.override}}")
{
Write-Host "Using manually entered override version"
$version = "${{ github.event.inputs.override}}"
}
else
{
$header = @{Authorization = 'Bearer ${{ secrets.GITHUB_TOKEN }}' }
$endPoint = "https://api.github.com/repos/${{github.repository}}/releases"
$info = Invoke-RestMethod -Uri $endPoint -Headers $header
$version = $info.name[0].Trim("v")
}
Write-Host "::set-output name=BUILD_NUMBER::$($version)"
# Write-Host "BUILD_NUMBER=$($version)" >> GITHUB_OUTPUT
install-modules:
name: Pre-compile packages
runs-on: ubuntu-latest
outputs:
buildNumber: ${{ steps.ver.outputs.BUILD_NUMBER }}
steps:
- uses: actions/checkout@v4
- name: Preload packages into cache
id: builder
uses: ./.github/actions/preinstall
with:
bt-param: '-fae -B -e -T 1C -Psonar'
version: ${{ github.sha }}
test-modules:
name: Test Modules
needs: [ waitOld, install-modules ]
runs-on: ubuntu-latest
env:
SAUCE_HUB_URL: ${{secrets.SAUCE_HUB_URL}}
SAUCE: ${{secrets.SAUCE}}
strategy:
fail-fast: false
matrix:
module-name: [ openmaqs-utilities, openmaqs-base, openmaqs-appium, openmaqs-selenium, openmaqs-webservices, openmaqs-cucumber, openmaqs-accessibility, openmaqs-database, openmaqs-playwright ]
steps:
- name: Check if tests can be run
if: matrix.module-name == 'openmaqs-appium' && github.actor == 'dependabot[bot]'
run: |
echo Cannot run Appium tests when build was triggered by dependabot
exit 1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
if: matrix.module-name == 'openmaqs-playwright'
with:
node-version: '14.x'
- name: Install Playwright
if: matrix.module-name == 'openmaqs-playwright'
run: npx playwright install --with-deps
- name: Build and Start Unit Tests
id: builder
uses: ./.github/actions/buildtest
with:
module-name: ${{matrix.module-name}}
bt-param: '-fae -B -e -Dtesting=solo -T 1C'
version: ${{ github.sha }}
- name: Test Reporting
if: always()
id: test-report
uses: phoenix-actions/test-reporting@v12
with:
name: ${{matrix.module-name}} Test Results
path: '**/junitreports/TEST-**.xml'
reporter: 'java-junit'
list-tests: 'failed'
list-suites: 'failed'
fail-on-error: 'false'
- uses: actions/upload-artifact@v3
if: always()
name: "Upload test artifact"
with:
name: ${{matrix.module-name}}-results
path: |
${{matrix.module-name}}/target/**/*.xml
${{matrix.module-name}}/target/logs
${{matrix.module-name}}/target/**/*.exec
${{matrix.module-name}}/target/**/*.jar
sonarcloud:
name: SonarCloud Analysis
runs-on: ubuntu-latest
needs: [test-modules, getVersion]
env:
SONAR_ORG: "openmaqs"
SONAR_PROJECT: "OpenMAQS_openmaqs-java"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
VERSION: ${{ needs.getVersion.outputs.buildNumber }}
steps:
- name: Checkout Source
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
path: ${{github.workspace}}/artifacts/
- name: Set up JDK 17
uses: actions/setup-java@v4.2.1
with:
distribution: zulu
java-version: 17
cache: maven
- name: Create settings file
uses: InstaCode/maven-settings-xml-action@v9
with:
profiles: '[{ "id": "sonar", "properties": { "sonar.organization":"${{env.SONAR_ORG}}", "sonar.host.url":"https://sonarcloud.io", "sonar.login": "${{env.SONAR_TOKEN}}" }}]'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Restore Local Maven Cache
uses: actions/cache@v3.3.2
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{github.sha}}.${{github.run_number}}
restore-keys: |
${{ runner.os }}-maven-${{github.sha}}
- name: Run SonarCloud Analysis
shell: bash
run: mvn -B -e -fae -Drevision=${{env.VERSION}} -Psonar package sonar:sonar -Dsonar.projectKey=${{env.SONAR_PROJECT}} -Dsonar.coverage.jacoco.xmlReportPaths=$(find "$(pwd)" -path '*jacoco.xml' | sed 's/.*/&/' | tr '\n' ',')
working-directory: ${{github.workspace}}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
checkstyle:
name: Checkstyle Run
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4.2.1
with:
distribution: zulu
java-version: 17
cache: maven
- name: Restore Local Maven Cache
uses: actions/cache@v3.3.2
with:
path: ~/.m2
key: ${{runner.os}}-m2
- name: Run Checkstyle
run: mvn -B validate --file pom.xml -e -fae
labels:
name: Pull Request Labels
runs-on: ubuntu-latest
steps:
- name: Label Pull Request
uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
publish:
name: Publish Packages
runs-on: ubuntu-latest
needs: [sonarcloud, checkstyle, getVersion]
environment: OSSRH
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.event_name != 'schedule'
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4.2.1
with:
distribution: zulu
java-version: 11
cache: maven
- name: Restore Local Maven Cache
uses: actions/cache@v3.3.2
with:
path: ~/.m2
key: ${{runner.os}}-m2
- name: Create settings file
uses: whelk-io/maven-settings-xml-action@v21
with:
profiles: '[{"id": "gpg", "properties": { "gpg.keyname": "${{secrets.GPG_KEYNAME_ID}}", "gpg.passphrase": "${{secrets.GPG_PASSPHRASE}}" }}]'
servers: '[{"id": "ossrh", "username": "${{secrets.DEPLOY_PACKAGE_USERNAME}}", "password": "${{secrets.DEPLOY_PACKAGE_PASSWORD}}"}]'
active_profiles: >
[ "ossrh", "release", "gpg" ]
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6.0.0
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: Deploy Release v${{ needs.getVersion.outputs.buildNumber }} to OSSRH
run: mvn -B -e -Drevision=${{ needs.getVersion.outputs.buildNumber }} deploy
- name: Publish GitHub release v${{ needs.getVersion.outputs.buildNumber }}
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const result = await github.action.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
})
var id = "NA"
var data = result.data
for(var key in data){
if(data[key].tag_name == "v${{ needs.getVersion.outputs.buildNumber }}" && data[key].draft == true)
{
github.action.repos.updateRelease({
release_id: data[key].id,
"draft": false,
owner: context.repo.owner,
repo: context.repo.repo });
return;
}
}
console.error("Failed to find related draft release");