-
Notifications
You must be signed in to change notification settings - Fork 1.8k
473 lines (410 loc) · 18.5 KB
/
build.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
name: Build and Test
on:
pull_request_target:
types:
- opened
- reopened
- synchronize
branches-ignore:
- github-action-* #to allow testing of build logic in branches, don't do PR builds for github-action-* branches and instead use branch builds
push:
branches:
- master
- main
- github-action-*
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
proBranchName: ${{ steps.find-branches.outputs.proBranchName }}
proBranchSha: ${{ steps.find-branches.outputs.proBranchSha }}
thisSha: ${{ steps.find-branches.outputs.thisSha }}
thisBranchName: ${{ steps.find-branches.outputs.thisBranchName }}
thisBranchFileName: ${{ steps.find-branches.outputs.thisBranchFileName }}
thisRepositoryName: ${{ steps.find-branches.outputs.thisRepositoryName }}
thisRepositoryOwner: ${{ steps.find-branches.outputs.thisRepositoryName }}
standAlonePR: ${{ steps.find-branches.outputs.standAlonePR }}
stablePro: ${{ steps.find-branches.outputs.stablePro }}
steps:
- name: Failsafe
uses: actions/github-script@v5
with:
script: |
if (${{ github.run_attempt }} % 5 == 0) {
core.setFailed("Fail every 5 run attempts to catch accidental infinite loops");
}
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha || github.event.after}}
- name: Find corresponding branches
id: find-branches
uses: actions/github-script@v5
with:
github-token: ${{ secrets.BOT_TOKEN }}
script: |
const helper = require('./.github/util/workflow-helper.js')({github, context});
core.setOutput("thisSha", helper.getCurrentSha());
core.setOutput("thisBranchName", helper.getCurrentBranch());
core.setOutput("thisBranchFileName", helper.getCurrentBranch().replace(/[^a-zA-Z0-9\-_]/g, "_"));
core.setOutput("thisRepoName", helper.getRepositoryName());
core.setOutput("thisRepoOwner", helper.getRepositoryOwner());
let proStatusMessage = "success";
let proFailed = false;
let branch = await helper.findMatchingBranch("liquibase", "liquibase-pro");
//count as not a stand-alone PR for branch builds on master/main, even though there are no PRs
if (helper.getCurrentBranch() == 'master' || helper.getCurrentBranch() == 'main' && branch.pullRequestId) {
core.setOutput("standAlonePR", helper.getCurrentBranch() !== branch.name);
} else {
core.setOutput("standAlonePR", true);
}
if (!branch.lastSuccessfulRunNumber) {
proFailed = true;
proStatusMessage = "Matching pro branch has never passed. Falling back to master"
branch = await helper.findMatchingBranch("liquibase", "liquibase-pro", ["main", "master"])
}
core.setOutput("proBranchName", branch.name);
core.setOutput("proBranchSha", branch.sha);
if (!proFailed) {
if (!branch.workflowId) {
proStatusMessage = "does not have a ran workflow";
proFailed = true
} else if ( branch.runStatus != "completed") {
proStatusMessage = "build is "+ branch.runStatus;
proFailed = true
} else if ( branch.runConclusion != "success") {
proStatusMessage = "build conclusion was "+branch.runConclusion;
proFailed = true
}
}
statusMessage = "liquibase/liquibase-pro:"+branch.name+"@" + branch.sha.substring(0, 7) + " " + proStatusMessage;
console.log("Pro failed?" + proFailed + ": "+statusMessage);
github.rest.repos.createCommitStatus({
"owner": "liquibase",
"repo": "liquibase",
"sha": helper.getCurrentSha(),
"state": (proFailed ? "failure" : "success"),
"target_url": branch.runHtmlUrl,
"context": "Stable Liquibase Pro",
"description": statusMessage
});
core.setOutput("stablePro", !proFailed);
build:
name: Build & Test (Java ${{ matrix.java }})
needs: setup
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java: [ 8, 11, 16 ]
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha || github.event.after}}
- name: Built Code Cache
if: ${{ matrix.java == 8}}
uses: actions/cache@v2
with:
key: built-code-${{ github.run_number }}-${{ github.run_attempt }}
path: ./**/target
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
cache: 'maven'
- name: Build & Test
run: |
mvn -B -Dbuild.repository.owner=${{ needs.setup.outputs.thisRepositoryOwner }} -Dbuild.repository.name=${{ needs.setup.outputs.thisRepositoryName }} -Dbuild.branch=${{ needs.setup.outputs.thisBranchName }} -Dbuild.number=${{ github.run_number }} -Dbuild.commit=${{ needs.setup.outputs.thisSha }} -DtrimStackTrace=false -pl '!liquibase-dist' clean test package surefire-report:report
find . -name original-*.jar -exec rm {} \;
- name: Archive Test Results
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: liquibase-test-results-jdk${{ matrix.java }}
path: |
./**/target/surefire-reports
./**/target/site
- name: Archive Modules
if: ${{ matrix.java == 8}}
uses: actions/upload-artifact@v2
with:
name: liquibase-modules
path: |
*/target/*-0-SNAPSHOT.jar
sonar:
name: Sonar Scan
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'
cache: 'maven'
- name: Cache SonarCloud packages
uses: actions/cache@v2
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn clean verify sonar:sonar -P sonar -Dsonar.login=$SONAR_TOKEN
integration-test:
name: Integration Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
testSystem:
- h2
# - h2:1.4
- hsql
- mariadb
- mssql
- mysql
- oracle
- postgresql
- sqlite
needs: build
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha || github.event.after}}
- name: Prepare
id: prepare
uses: actions/github-script@v5
with:
script: |
core.setOutput("testResultsArtifact", "liquibase-test-results-integration-${{ matrix.testSystem }}".replace(/[^a-zA-Z0-9\-_]/g, "_"));
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
cache: 'maven'
- name: Restore Built Code Cache
uses: actions/cache@v2
with:
key: built-code-${{ github.run_number }}-${{ github.run_attempt }}
path: ./**/target
- name: Login to Artifactory
uses: docker/login-action@v1
with:
registry: docker-dev.artifactory.datical.net
username: ${{ secrets.ARTIFACTORY_USER }}
password: ${{ secrets.ARTIFACTORY_TOKEN }}
- name: Run Tests
run: mvn -B jar:jar jar:test-jar surefire:test -DtrimStackTrace=false -Dliquibase.sdk.testSystem.test=hub,${{ matrix.testSystem }} -Dliquibase.sdk.testSystem.acceptLicenses=${{ matrix.testSystem }} -Dtest=*IntegrationTest -DfailIfNoTests=false
- name: Archive Test Results
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: ${{ steps.prepare.outputs.testResultsArtifact }}
path: |
./**/target/surefire-reports
package:
name: Package Artifacts
runs-on: ubuntu-latest
needs: [ setup, build ]
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha || github.event.after}}
- name: Built Code Cache
uses: actions/cache@v2
with:
key: built-code-${{ github.run_number }}-${{ github.run_attempt }}
path: ./**/target
##Cache based on install4j file, since changes to JVM is seen in there. If install4j version changes without changing the file, change the prefix letter before hashFiles to force a new cache
- name: Install4j Cache
uses: actions/cache@v2
with:
key: install4j-A${{ hashFiles('liquibase-dist/src/main/install4j/liquibase.install4j') }}
path: ~/.install4j8/**
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
gpg-private-key: ${{ secrets.GPG_SECRET }}
gpg-passphrase: GPG_PASSPHRASE
cache: 'maven'
env:
GPG_PASSWORD: ${{ secrets.GPG_PASSPHRASE }}
- name: Download liquibase-pro
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{ secrets.BOT_TOKEN }}
workflow: build.yml
workflow_conclusion: success
branch: "${{ needs.setup.outputs.proBranchName }}"
name: liquibase-pro-modules
path: download/liquibase-pro
repo: liquibase/liquibase-pro
- name: Install Built Modules
run: |
(find . -name *-SNAPSHOT.jar -exec mvn -B org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile={} \;)
(find . -name *-SNAPSHOT-sources.jar -exec mvn -B org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dclassifier=sources -Dfile={} \;)
mvn -B org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=download/liquibase-pro/liquibase-pro-0-SNAPSHOT.jar
- name: Build & Sign Artifacts
env:
INSTALL4J_LICENSE: ${{ secrets.INSTALL4J_LICENSE }}
GPG_PASSWORD: ${{ secrets.GPG_PASSPHRASE }}
run: |
mvn -B -pl liquibase-dist -P liquibase-pro source:jar package
## extract tar content for other artifacts
mkdir -p liquibase-dist/target/liquibase-0-SNAPSHOT
(cd liquibase-dist/target/liquibase-0-SNAPSHOT && tar xfz ../liquibase-0-SNAPSHOT.tar.gz)
##create zip file from tar content
(cd liquibase-dist/target/liquibase-0-SNAPSHOT && zip -r ../liquibase-0-SNAPSHOT.zip *)
##create installers
(cd liquibase-dist && ${{ github.workspace }}/.github/util/package-install4j.sh 0-SNAPSHOT)
find . -name original-*.jar -exec rm {} \;
mkdir -p artifacts
cp liquibase-dist/target/liquibase-0-SNAPSHOT.tar.gz artifacts
cp liquibase-dist/target/liquibase-0-SNAPSHOT.zip artifacts
cp liquibase-dist/target/liquibase-0-SNAPSHOT.jar artifacts
cp liquibase-dist/target/liquibase-0-SNAPSHOT-sources.jar artifacts
cp liquibase-dist/target/liquibase-*-installer-* artifacts
cp liquibase-maven-plugin/target/liquibase-maven-plugin-0-SNAPSHOT.jar artifacts
cp liquibase-maven-plugin/target/liquibase-maven-plugin-0-SNAPSHOT-sources.jar artifacts
cp liquibase-maven-plugin/target/liquibase-maven-plugin-0-SNAPSHOT-javadoc.jar artifacts
cp liquibase-cdi/target/liquibase-cdi-0-SNAPSHOT.jar artifacts
cp liquibase-cdi/target/liquibase-cdi-0-SNAPSHOT-sources.jar artifacts
cp liquibase-cdi/target/liquibase-cdi-0-SNAPSHOT-javadoc.jar artifacts
cp target/liquibase-0-SNAPSHOT-javadoc.jar artifacts
.github/util/sign-artifacts.sh artifacts
##prepare branch-named convenience artifacts directories
mkdir artifacts-named
cp liquibase-dist/target/liquibase-0-SNAPSHOT.tar.gz artifacts-named/liquibase-${{ needs.setup.outputs.thisBranchFileName }}.tar.gz
cp liquibase-dist/target/liquibase-0-SNAPSHOT.jar artifacts-named/liquibase-${{ needs.setup.outputs.thisBranchFileName }}.jar
cp liquibase-maven-plugin/target/liquibase-maven-plugin-0-SNAPSHOT.jar artifacts-named/liquibase-maven-plugin-${{ needs.setup.outputs.thisBranchFileName }}.jar
cp liquibase-extension-testing/target/liquibase-extension-testing-0-SNAPSHOT.jar artifacts-named/liquibase-extension-testing-${{ needs.setup.outputs.thisBranchFileName }}.jar
cp liquibase-extension-testing/target/liquibase-extension-testing-0-SNAPSHOT-deps.jar artifacts-named/liquibase-extension-testing-${{ needs.setup.outputs.thisBranchFileName }}.jar
- name: Archive Packages
uses: actions/upload-artifact@v2
with:
name: liquibase-artifacts
path: artifacts/*
- name: Archive Convenience Zip
uses: actions/upload-artifact@v2
with:
name: liquibase-zip-${{ needs.setup.outputs.thisBranchFileName }}
path: liquibase-dist/target/liquibase-0-SNAPSHOT/*
- name: Archive Convenience Artifacts
uses: actions/upload-artifact@v2
with:
name: liquibase-artifacts-${{ needs.setup.outputs.thisBranchFileName }}
path: artifacts-named/*
finish:
name: Finish Build
runs-on: ubuntu-latest
needs: [ setup, build, integration-test, package, sonar ]
if: ${{ always() }}
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha || github.event.after}}
- name: Coordinate Liquibase-Pro
uses: actions/github-script@v5
with:
github-token: ${{ secrets.BOT_TOKEN }}
script: |
const helper = require('./.github/util/workflow-helper.js')({github, context});
let currentBranchInfo = await helper.findMatchingBranch("liquibase", "liquibase-pro");
let thisStatus = "${{ needs.package.result }}" == "success" ? "success" : "failure";
let stablePro = ("${{ needs.setup.outputs.stablePro }}" == "true");
let standalonePR = "${{ needs.setup.outputs.standAlonePR }}" == "true";
console.log("Stand alone PR: "+standalonePR);
let runFunctionalTests = false;
let markFunctionalTestsStatus = "failure";
let markFunctionalTestsDescription = "Unexpected setup";
if (stablePro) {
console.log("Pro is stable");
runFunctionalTests = true;
markFunctionalTestsStatus = "pending";
markFunctionalTestsDescription = "Trigger internal functional tests";
} else {
console.log("Last pro was unstable");
runFunctionalTests = false;
markFunctionalTestsStatus = "failure";
markFunctionalTestsDescription = "Liquibase Pro is unstable";
let checks = await github.rest.repos.listCommitStatusesForRef({
"owner": "liquibase",
"repo": "liquibase-pro",
"ref": currentBranchInfo.sha
});
let failedCheckingUs = false;
if (standalonePR) {
for (let status of checks.data) {
if (status.context == "Stable Liquibase Core") {
console.log("Stable Liquibase Core is "+ status.state);
failedCheckingUs = (status.state == "failure");
}
}
}
if (failedCheckingUs) {
console.log("Rerun liquibase-pro that was waiting on us");
//octokit removed the retryWorkflow function
github.request("POST "+currentBranchInfo.runRerunUrl);
//await github.rest.actions.retryWorkflow({
// "owner": "liquibase",
// "repo": "liquibase-pro",
// "run_id": currentBranchInfo.workflowId
//});
}
}
if (standalonePR) {
console.log("Do not mark base pro branch as included in this");
} else {
console.log("Mark 'Included in Liquibase Core' status as "+thisStatus);
github.rest.repos.createCommitStatus({
"owner": "liquibase",
"repo": "liquibase-pro",
"sha": currentBranchInfo.sha,
"state": thisStatus,
"context": "Stable Liquibase Core",
"target_url": currentBranchInfo.runHtmlUrl,
"description": "Latest Liquibase Core build"
});
}
if (runFunctionalTests) {
let testsBranch = await helper.findMatchingBranch("liquibase", "liquibase-pro-tests");
let notices = [];
if (context.payload.pull_request) {
console.log("Sending pull request information");
notices = ["Triggered by PR " + context.payload.pull_request.html_url];
}
console.log("Trigger functional tests");
let workflowDispatch = await github.rest.actions.createWorkflowDispatch({
"owner": "liquibase",
"repo": "liquibase-pro-tests",
"workflow_id": "test.yml",
"ref": testsBranch.name,
"inputs": {
"liquibaseCommit": helper.getCurrentSha(),
"runDescription": "Triggered by https://github.com/liquibase/liquibase/actions/runs/"+context.runId,
"runDetails": JSON.stringify({
"liquibaseBranch": helper.getCurrentBranch(),
"notices": notices
})
}
});
}
await github.rest.repos.createCommitStatus({
"owner": "liquibase",
"repo": "liquibase",
"sha": helper.getCurrentSha(),
"state": markFunctionalTestsStatus,
"context": "Run Functional Tests",
"description": markFunctionalTestsDescription
});