forked from liquibase/liquibase
-
Notifications
You must be signed in to change notification settings - Fork 0
399 lines (345 loc) · 18.7 KB
/
Copy pathbuild.yml
File metadata and controls
399 lines (345 loc) · 18.7 KB
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
name: Build and Publish
permissions:
contents: write
packages: write
actions: read
id-token: write # Required for OIDC authentication with AWS
# 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 }} # authenticate GitHub Actions to the GitHub API.
github-token: ${{ secrets.GITHUB_TOKEN }} # accessing a private repository
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@v5
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: Configure AWS credentials for vault access
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: ${{ secrets.LIQUIBASE_VAULT_OIDC_ROLE_ARN }}
aws-region: us-east-1
- name: Get secrets from vault
id: vault-secrets
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
,/vault/liquibase
parse-json-secrets: true
- name: Get GitHub App token
id: get-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ env.LIQUIBASE_GITHUB_APP_ID }}
private-key: ${{ env.LIQUIBASE_GITHUB_APP_PRIVATE_KEY }}
owner: liquibase
permission-contents: read
- name: Checkout PRO Repo
uses: actions/checkout@v5
with:
repository: liquibase/liquibase-pro
token: ${{ steps.get-token.outputs.token }}
#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@v8
with:
github-token: ${{ steps.get-token.outputs.token }}
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]
steps:
- uses: actions/checkout@v5
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@v5
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.2.4
with:
key: install4j-A${{ hashFiles('liquibase-dist/src/main/install4j/liquibase.install4j') }}
path: ~/.install4j8/**
- name: Configure AWS credentials for vault access
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: ${{ secrets.LIQUIBASE_VAULT_OIDC_ROLE_ARN }}
aws-region: us-east-1
- name: Get secrets from vault
id: vault-secrets
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
,/vault/liquibase
parse-json-secrets: true
- name: Convert escaped newlines and set GPG key
run: |
{
echo "GPG_KEY_CONTENT<<GPG_EOF"
printf '%b' "${{ env.GPG_SECRET }}"
echo
echo "GPG_EOF"
} >> $GITHUB_ENV
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
java-version: "17"
distribution: "temurin"
gpg-private-key: ${{ env.GPG_KEY_CONTENT }}
gpg-passphrase: GPG_PASSPHRASE
cache: "maven"
overwrite-settings: false
env:
GPG_PASSWORD: ${{ env.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": "${{ env.LIQUIBOT_PAT_GPM_ACCESS }}"
},
{
"id": "liquibase",
"username": "liquibot",
"password": "${{ env.LIQUIBOT_PAT_GPM_ACCESS }}"
}
]
# 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: ${{ env.INSTALL4J_LICENSE }}
GPG_PASSWORD: ${{ env.GPG_PASSPHRASE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
## save install4j code signing keys
mkdir -p liquibase-dist/target/keys
# we are packaging and deploying liquibase tar which includes liquibase-commercial
# Build liquibase-commercial version
./mvnw -B -pl liquibase-dist -P liquibase-commercial source:jar clean package failsafe:integration-test failsafe:verify \
"-Dliquibase.checks=true" \
"-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 }}"
# backup commercial tarball to prevent it from being overwritten
mkdir -p liquibase-dist/backup
mv liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz liquibase-dist/backup/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz
mv liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.zip liquibase-dist/backup/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.zip
# Build liquibase-minimal version
./mvnw -B -pl liquibase-dist -P liquibase-minimal source:jar clean package failsafe:integration-test failsafe:verify \
"-Dliquibase.checks=true" \
"-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 }}"
# Rename liquibase-minimal tarball to avoid overwriting the commercial one
mv liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz liquibase-dist/target/liquibase-minimal-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz
mv liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.zip liquibase-dist/target/liquibase-minimal-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.zip
# Restore commercial tarballs from backup into target dir
mv liquibase-dist/backup/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz
mv liquibase-dist/backup/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.zip liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.zip
# Extract the tarball to allow us to upload the liquibase installation files to our
# github actions workflow so that we don't double zip the archive
mkdir -p branch-artifacts
tar -xzf liquibase-dist/target/liquibase-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz -C branch-artifacts
##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)
# Remove original JARs
find . -name original-*.jar -exec rm {} \;
# Copy artifacts
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-dist/target/liquibase-minimal-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz artifacts
cp liquibase-dist/target/liquibase-minimal-${{ 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
for i in 'liquibase-maven-plugin' 'liquibase-cli'; do
cp $i/target/$i-0-SNAPSHOT.jar artifacts
cp $i/target/$i-0-SNAPSHOT-sources.jar artifacts
cp $i/target/$i-0-SNAPSHOT-javadoc.jar artifacts
done
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-minimal-${{ needs.setup.outputs.thisBranchName }}-SNAPSHOT.tar.gz artifacts-named/liquibase-${{ needs.setup.outputs.thisBranchName }}-minimal.tar.gz
cp liquibase-extension-testing/target/liquibase-extension-testing-0-SNAPSHOT-deps.jar artifacts-named/liquibase-extension-testing-${{ needs.setup.outputs.thisBranchName }}-deps.jar
for i in 'liquibase-core' 'liquibase-maven-plugin' 'liquibase-cli' 'liquibase-extension-testing'; do
cp $i/target/$i-0-SNAPSHOT.jar artifacts-named/$i-${{ needs.setup.outputs.thisBranchName }}.jar
done
#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@v4
with:
name: liquibase-artifacts
path: artifacts/*
- name: Archive Convenience Zip
uses: actions/upload-artifact@v4
with:
name: liquibase-zip-${{ needs.setup.outputs.thisBranchName }}
path: branch-artifacts/*
- name: Archive Convenience Artifacts
uses: actions/upload-artifact@v4
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:
if: github.actor != 'dependabot[bot]'
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 }}
run-pro-build-and-test:
needs: [setup, build_publish_branch]
uses: liquibase/liquibase/.github/workflows/run-pro-build-and-test.yml@master
secrets: inherit
with:
latestMergeSha: ${{ needs.setup.outputs.latestMergeSha }}
thisBranchName: ${{ needs.setup.outputs.unmodifiedBranchName }}