346 lines (292 loc) · 17.9 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
name: Build and Publish
#the concurrency check will cancel in-progress runs on non-master branches and pull requests on forked repositories regardless of the target branch.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref == 'master' && 'master' || github.run_id }}
cancel-in-progress: true
on:
workflow_call:
workflow_dispatch:
jobs:
setup:
name: Setup
runs-on: ubuntu-22.04
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
branchExistsInBoth: ${{ steps.check-branch.outputs.branchExistsInBoth }}
thisBranchName: ${{ steps.get-branch-name.outputs.thisBranchName }}
latestMergeSha: ${{ steps.get-sha.outputs.latestMergeSha }}
timeStamp: ${{ steps.get-timestamp.outputs.timestamp }}
proBranchNamePrefix: ${{ steps.check-branch.outputs.proBranchNamePrefix }}
unmodifiedBranchName: ${{ steps.get-branch-name.outputs.unmodifiedBranchName }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.event.after}}
- name: Get Latest Merge Commit SHA
id: get-sha
run: |
latest_merge_sha=`(git rev-parse HEAD)`
echo "latestMergeSha=${latest_merge_sha}" >> $GITHUB_OUTPUT
- name: Get Timestamp
id: get-timestamp
run: |
timeStamp=$(date +'%Y-%m-%d %H:%M:%S %Z')
echo "timestamp=${timeStamp}" >> $GITHUB_OUTPUT
- name: Get Current BranchName
id: get-branch-name
run: |
# this logic checks if the branch is from a forked repository PR or not. Where -n is the inverse of -z (not empty)
if [ -n "${GITHUB_HEAD_REF}" ];
then
branch_name=${GITHUB_HEAD_REF}
else
branch_name=${{ github.ref_name }}
fi
modified_branch_name=`(echo $branch_name | tr '/' '_')`
echo "thisBranchName=$modified_branch_name" >> $GITHUB_OUTPUT
#this is to check if the same branch name exists in PRO, we need it in check-branch step
echo "unmodifiedBranchName=$branch_name" >> $GITHUB_OUTPUT
echo "Modified Branch Name:" $modified_branch_name
echo "Original Branch Name thisBranchName:" $branch_name
- name: Checkout OSS Repo
uses: actions/checkout@v4
with:
repository: liquibase/liquibase
#RUN THIS LOGIC WHEN THERE IS A SAME BRANCH IN OSS AND PRO
#checking if the branch specified by $currentBranch exists in the PRO repository, If the getBranch call throws an error, it means the branch doesn't exist in the PRO repo. Also, remove refs/heads/
# if the value of branchExistsInBoth = false then set liquibaseProVersionPrefix = master else $currentBranch
# if the value of branchExistsInBoth = true then set liquibaseProVersionPrefix = thisBranchName else $currentBranch as PRO also has replacement logic for / with _
- name: Check branch existence
id: check-branch
uses: actions/github-script@v7
with:
github-token: ${{ secrets.LIQUIBOT_PAT_GPM_ACCESS }}
script: |
const currentBranch = "${{ steps.get-branch-name.outputs.unmodifiedBranchName }}"
console.log(currentBranch)
let branchExistsInBoth;
try {
await github.rest.repos.getBranch({
owner: "liquibase",
repo: "liquibase-pro",
branch: currentBranch
});
branchExistsInBoth = true
} catch (error){
branchExistsInBoth = false
}
let liquibaseProVersionPrefix= branchExistsInBoth ? currentBranch : 'master'
liquibaseProVersionPrefix=liquibaseProVersionPrefix.replaceAll("/","_")
core.setOutput("branchExistsInBoth", branchExistsInBoth)
core.setOutput("proBranchNamePrefix", liquibaseProVersionPrefix)
console.log(liquibaseProVersionPrefix)
### MATCHING BRANCH RUN THIS LOGIC
build_publish_branch:
name: Artifacts- Build & Package
runs-on: macos-latest
needs: [ setup ]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.event.after}}
# this includes all the tar files included in the previous runs. So in the next step we deploy what was previously build
- name: Download Artifacts for build.yml
uses: actions/download-artifact@v3
with:
name: temp-artifact
##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@v4.0.2
with:
key: install4j-A${{ hashFiles('liquibase-dist/src/main/install4j/liquibase.install4j') }}
path: ~/.install4j8/**
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
gpg-private-key: ${{ secrets.GPG_SECRET }}
gpg-passphrase: GPG_PASSPHRASE
cache: 'maven'
overwrite-settings: false
env:
GPG_PASSWORD: ${{ secrets.GPG_PASSPHRASE }}
#look for dependencies in maven
- name: maven-settings-xml-action
uses: whelk-io/maven-settings-xml-action@v22
with:
repositories: |
[
{
"id": "liquibase",
"url": "https://maven.pkg.github.com/liquibase/liquibase",
"releases": {
"enabled": "false"
},
"snapshots": {
"enabled": "true",
"updatePolicy": "always"
}
},
{
"id": "liquibase-pro",
"url": "https://maven.pkg.github.com/liquibase/liquibase-pro",
"releases": {
"enabled": "false"
},
"snapshots": {
"enabled": "true",
"updatePolicy": "always"
}
}
]
servers: |
[
{
"id": "liquibase-pro",
"username": "liquibot",
"password": "${{ secrets.LIQUIBOT_PAT }}"
},
{
"id": "liquibase",
"username": "liquibot",
"password": "${{ secrets.LIQUIBOT_PAT }}"
}
]
# Version artifact based off of branch
- name: Version Artifact
run: |
version=${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT
./mvnw versions:set -DnewVersion="$version"
- name: Artifacts- Build & Sign
env:
INSTALL4J_LICENSE: ${{ secrets.INSTALL4J_LICENSE }}
INSTALL4J_APPLE_KEY: ${{ secrets.INSTALL4J_APPLE_KEY }}
INSTALL4J_APPLE_KEY_PASSWORD: ${{ secrets.INSTALL4J_APPLE_KEY_PASSWORD }}
INSTALL4J_APPLE_ID: ${{ secrets.INSTALL4J_APPLE_ID }}
INSTALL4J_APPLE_ID_PASSWORD: ${{ secrets.INSTALL4J_APPLE_ID_PASSWORD }}
INSTALL4J_WINDOWS_KEY: ${{ secrets.INSTALL4J_WINDOWS_KEY }}
INSTALL4J_WINDOWS_KEY_PASSWORD: ${{ secrets.INSTALL4J_WINDOWS_KEY_PASSWORD }}
GPG_PASSWORD: ${{ secrets.GPG_PASSPHRASE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
## save install4j code signing keys
mkdir -p liquibase-dist/target/keys
echo "Saving apple key"
echo "$INSTALL4J_APPLE_KEY" | base64 -d > liquibase-dist/target/keys/datical_apple.p12
echo "Saving windows key"
echo "$INSTALL4J_WINDOWS_KEY" | base64 -d > liquibase-dist/target/keys/datical_windows.pfx
# we are packaging and deploying liquibase tar which includes liquibase-commercial
./mvnw -B -pl liquibase-dist -P liquibase-commercial source:jar package "-Dliquibase-pro.version=${{ needs.setup.outputs.proBranchNamePrefix }}-SNAPSHOT" "-Dbuild.repository.owner=liquibase" "-Dbuild.repository.name=liquibase" "-Dbuild.branch=${{ needs.setup.outputs.thisBranchName }}" "-Dbuild.number=${{ github.run_number }}" "-Dbuild.commit=${{ needs.setup.outputs.latestMergeSha }}-SNAPSHOT" "-Dbuild.timestamp=${{ needs.setup.outputs.timeStamp }}"
## extract tar content for other artifacts
mkdir -p liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT
(cd liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT && tar -xzf ../liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz)
# there is some issue while doing a tar -xzf hence copying this manually
cp -r liquibase-standard/src/main/resources/liquibase/examples liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT
ls -l liquibase-dist/target
#zip the above folder again which contains examples folder
(cd liquibase-dist/target && tar -czf liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT)
## verify that the contents of the tar matches the expectation
echo "Comparing the contents of the tar.gz with the expected contents (using baseline file in liquibase-dist directory) to ensure that no new files were accidentally added. A failure here indicates that a new file was added to the tar.gz, and it should either be rectififed or added to the baseline."
brew install tree --quiet
tree liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT -o actual-distribution-contents.txt --noreport
# remove first line of actual, because it contains the folder name, which the expected will not have
echo "$(tail -n +2 actual-distribution-contents.txt)" > actual-distribution-contents.txt
diff actual-distribution-contents.txt liquibase-dist/expected-distribution-contents.txt
rm -rf actual-distribution-contents.txt
##create zip file from tar content
(cd liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT && zip -r ../liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.zip *)
echo "liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT"
ls liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT
##create installer - disabled here but run as nightly job and as part of release workflow
# (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-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz artifacts
cp liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.zip artifacts
cp liquibase-core/target/liquibase-core-0-SNAPSHOT.jar artifacts/liquibase-core-0-SNAPSHOT.jar
#cp liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT/internal/lib/liquibase-core.jar artifacts/liquibase-core-0-SNAPSHOT.jar
cp liquibase-core/target/liquibase-core-0-SNAPSHOT-sources.jar artifacts/liquibase-core-0-SNAPSHOT-sources.jar
cp target/liquibase-0-SNAPSHOT-javadoc.jar artifacts/liquibase-core-0-SNAPSHOT-javadoc.jar
##create installer - disabled here but run as nightly job and as part of release workflow
#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 liquibase-cdi-jakarta/target/liquibase-cdi-jakarta-0-SNAPSHOT.jar artifacts
cp liquibase-cdi-jakarta/target/liquibase-cdi-jakarta-0-SNAPSHOT-sources.jar artifacts
cp liquibase-cdi-jakarta/target/liquibase-cdi-jakarta-0-SNAPSHOT-javadoc.jar artifacts
echo "Source code not available for liquibase-commercial" > /tmp/readme.source.txt
(cd /tmp && jar cf liquibase-commercial-${{ needs.setup.outputs.proBranchNamePrefix }}-SNAPSHOT-sources.jar readme.source.txt)
echo "Javadocs not available for liquibase-commercial" > /tmp/readme.javadocs.txt
(cd /tmp && jar cf liquibase-commercial-${{ needs.setup.outputs.proBranchNamePrefix }}-SNAPSHOT-javadoc.jar readme.javadocs.txt)
ls -R /Users/runner/.m2/repository/org/liquibase/liquibase-commercial
echo "/Users/runner/.m2/repository/org/liquibase/liquibase-commercial "
commercialJarM2Location=/Users/runner/.m2/repository/org/liquibase/liquibase-commercial/${{ needs.setup.outputs.proBranchNamePrefix }}-SNAPSHOT/liquibase-commercial-${{ needs.setup.outputs.proBranchNamePrefix }}-SNAPSHOT.jar
cp $commercialJarM2Location artifacts
cp /tmp/liquibase-commercial-${{ needs.setup.outputs.proBranchNamePrefix }}-SNAPSHOT-sources.jar artifacts
cp /tmp/liquibase-commercial-${{ needs.setup.outputs.proBranchNamePrefix }}-SNAPSHOT-javadoc.jar artifacts
.github/util/sign-artifacts.sh artifacts
##prepare branch-named convenience artifacts directories
mkdir artifacts-named
cp liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz artifacts-named/liquibase-${{ needs.setup.outputs.thisBranchName }}.tar.gz
#cp liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT/internal/lib/liquibase-core.jar artifacts-named/liquibase-core-${{ needs.setup.outputs.thisBranchName }}.jar
cp liquibase-core/target/liquibase-core-0-SNAPSHOT.jar artifacts-named/liquibase-core-${{ needs.setup.outputs.thisBranchName }}.jar
cp liquibase-maven-plugin/target/liquibase-maven-plugin-0-SNAPSHOT.jar artifacts-named/liquibase-maven-plugin-${{ needs.setup.outputs.thisBranchName }}.jar
cp liquibase-cdi/target/liquibase-cdi-0-SNAPSHOT.jar artifacts-named/liquibase-cdi-${{ needs.setup.outputs.thisBranchName }}.jar
cp liquibase-cdi-jakarta/target/liquibase-cdi-jakarta-0-SNAPSHOT.jar artifacts-named/liquibase-cdi-jakarta-${{ needs.setup.outputs.thisBranchName }}.jar
cp liquibase-extension-testing/target/liquibase-extension-testing-0-SNAPSHOT.jar artifacts-named/liquibase-extension-testing-${{ needs.setup.outputs.thisBranchName }}.jar
cp liquibase-extension-testing/target/liquibase-extension-testing-0-SNAPSHOT-deps.jar artifacts-named/liquibase-extension-testing-${{ needs.setup.outputs.thisBranchName }}-deps.jar
#check why only this step has branchName when there is a standalone PR
cp $commercialJarM2Location artifacts-named/liquibase-commercial-${{ needs.setup.outputs.thisBranchName }}.jar
- name: Archive Packages
uses: actions/upload-artifact@v3
with:
name: liquibase-artifacts
path: artifacts/*
- name: Archive Convenience Zip
uses: actions/upload-artifact@v3
with:
name: liquibase-zip-${{ needs.setup.outputs.thisBranchName }}
path: liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT/*
- name: Archive Convenience Artifacts
uses: actions/upload-artifact@v3
with:
name: liquibase-artifacts-${{ needs.setup.outputs.thisBranchName }}
path: artifacts-named/*
# Publish <commitsha>-SNAPSHOT version to GPM
- name: Version Artifact Publish <commitsha>-SNAPSHOT version to GPM
run: |
./mvnw versions:set "-DnewVersion=${{ needs.setup.outputs.latestMergeSha }}-SNAPSHOT"
- name: Publish <commitsha>-SNAPSHOT package
run: |
./mvnw -B clean deploy -pl '!liquibase-dist' -DskipTests=true "-Dbuild.repository.owner=liquibase" "-Dbuild.repository.name=liquibase" "-Dbuild.branch=${{ needs.setup.outputs.thisBranchName }}" "-Dbuild.number=${{ github.run_number }}" "-Dbuild.commit=${{ needs.setup.outputs.latestMergeSha }}" "-Dbuild.timestamp=${{ needs.setup.outputs.timeStamp }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#Publish to GitHub Packages. We are building a tar file which includes liquibase-commercial hence we need "-Dliquibase-pro.version"
- name: Publish tar.gz package to GPM
run: |
./mvnw -B -pl liquibase-dist -P liquibase-commercial clean deploy -DskipTests=true "-Dliquibase-pro.version=${{ needs.setup.outputs.proBranchNamePrefix }}-SNAPSHOT" "-Dbuild.timestamp=${{ needs.setup.outputs.timestamp }}" "-Dbuild.repository.owner=liquibase" "-Dbuild.repository.name=liquibase" "-Dbuild.branch=${{ needs.setup.outputs.thisBranchName }}" "-Dbuild.number=${{ github.run_number }}" "-Dbuild.commit=${{ needs.setup.outputs.thisSha }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run-functional-tests:
needs: [ setup, build_publish_branch ]
uses: liquibase/liquibase/.github/workflows/run-functional-tests.yml@master
secrets: inherit
with:
latestMergeSha: ${{ needs.setup.outputs.latestMergeSha }}
thisBranchName: ${{ needs.setup.outputs.unmodifiedBranchName }}
run-tests-harness:
needs: [ setup,build_publish_branch ]
uses: liquibase/liquibase/.github/workflows/run-test-harness.yml@master
secrets: inherit
with:
latestMergeSha: ${{ needs.setup.outputs.latestMergeSha }}
thisBranchName: ${{ needs.setup.outputs.unmodifiedBranchName }}