forked from dotCMS/core
-
Notifications
You must be signed in to change notification settings - Fork 0
452 lines (376 loc) · 16.8 KB
/
cli-release-process.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
name: dotCLI Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
skipTests:
description: 'Skip tests'
default: 'true'
required: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true
defaults:
run:
shell: bash
env:
JAVA_VERSION: 11
JAVA_DISTRO: temurin
GRAALVM_VERSION: '22.1.0'
MVN_PACKAGE_TYPE: 'uber-jar'
NPM_PACKAGE_SCOPE: '@dotcms'
NPM_PACKAGE_NAME: 'dotcli'
MVN_PACKAGE_NAME: 'dotcms-cli'
NODE_VERSION: 19
jobs:
precheck:
name: 'Pre-check'
runs-on: ubuntu-latest
outputs:
RELEASE_VERSION: ${{ steps.version.outputs.RELEASE_VERSION }}
HEAD: ${{ steps.version.outputs.HEAD }}
AUXILIARY_BRANCH: ${{ steps.version.outputs.AUXILIARY_BRANCH }}
DATE: ${{ steps.get-date.outputs.DATE }}
steps:
- name: 'Log GitHub context'
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: 'Checkout'
uses: actions/checkout@v4
with:
token: ${{ secrets.CI_MACHINE_TOKEN }}
- name: 'Setup Java'
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRO }}
- uses: ./.github/actions/cleanup-runner
- name: 'Get Date'
id: get-date
run: |
echo "DATE=$(/bin/date -u "+%Y-%m")" >> $GITHUB_OUTPUT
shell: bash
- name: 'Restore Maven Repository'
id: cache-maven
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: maven-${{ steps.get-date.outputs.DATE }}-${{ github.run_id }}
- name: 'Setup git config'
run: |
git config user.name "${{ secrets.CI_MACHINE_USER }}"
git config user.email "[email protected]"
# Sets the release version and the next version
# Creates an auxiliary branch for versioning updates
- name: 'Set release version'
id: version
working-directory: ${{ github.workspace }}/tools/dotcms-cli
run: |
RELEASE_VERSION=${{ github.event.inputs.version }}
HEAD=${{ github.ref_name }}
# Create a release branch for versioning updates
AUXILIARY_BRANCH=version-update-${RELEASE_VERSION}-${{ github.run_id }}
git checkout -b $AUXILIARY_BRANCH
# Update version in pom.xml
./mvnw -B -ntp versions:set versions:commit -DnewVersion=$RELEASE_VERSION
# Commit version changes
git commit --allow-empty -a -m "Update dotCLI version to $RELEASE_VERSION"
git push origin $AUXILIARY_BRANCH
echo "RELEASE_VERSION=$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
echo "HEAD=$HEAD" >> "$GITHUB_OUTPUT"
echo "AUXILIARY_BRANCH=$AUXILIARY_BRANCH" >> "$GITHUB_OUTPUT"
# Build native executable per runner
build:
needs: [ precheck ]
name: 'Build native image on ${{ matrix.os }}'
strategy:
fail-fast: true
matrix:
os: [ macos-13-xlarge, macOS-latest, ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ needs.precheck.outputs.AUXILIARY_BRANCH }}
- name: 'Cleanup Runner'
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: ./.github/actions/cleanup-runner
- name: 'Cleanup macOS Runner'
if: ${{ contains(matrix.os, 'macos-') }}
uses: ./.github/actions/cleanup-macos-runner
# Sets up GraalVM for native image compilation (Linux/macOS)
# Downloads and installs GraalVM
# Configures environment variables
- name: 'Set up GraalVM for (Linux/MacOS)'
if: ${{ matrix.os != 'windows-latest' }}
run: |
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
echo "GraalVM on Linux (AMD64)"
ARCH=amd64
PLATFORM=linux
INSTALLATION_PATH=/usr/lib/jvm
else
if [ "${{ matrix.os }}" == "macos-13-xlarge" ]; then
echo "GraalVM on Mac (AARCH64)"
ARCH=aarch64
else
echo "GraalVM on Mac (AMD64)"
ARCH=amd64
fi
PLATFORM=darwin
INSTALLATION_PATH=/Library/Java/JavaVirtualMachines
fi
echo "PLATFORM=$PLATFORM"
echo "ARCH=$ARCH"
echo "INSTALLATION_PATH=$INSTALLATION_PATH"
wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${{ env.GRAALVM_VERSION }}/graalvm-ce-java11-${PLATFORM}-${ARCH}-${{ env.GRAALVM_VERSION }}.tar.gz
sudo mkdir -p $INSTALLATION_PATH
tar -xzf graalvm-ce-java11-${PLATFORM}-${ARCH}-${{ env.GRAALVM_VERSION }}.tar.gz
sudo mv graalvm-ce-java11-${{ env.GRAALVM_VERSION }} $INSTALLATION_PATH
if [ "${{ matrix.os }}" != "ubuntu-latest" ]; then
sudo xattr -r -d com.apple.quarantine /Library/Java/JavaVirtualMachines/graalvm-ce-java11-${{ env.GRAALVM_VERSION }}/Contents/Home
GRAALVM_HOME="${INSTALLATION_PATH}/graalvm-ce-java11-${{ env.GRAALVM_VERSION }}/Contents/Home"
else
GRAALVM_HOME="${INSTALLATION_PATH}/graalvm-ce-java11-${{ env.GRAALVM_VERSION }}"
fi
echo "GRAALVM_HOME=$GRAALVM_HOME" >> $GITHUB_ENV
echo "JAVA_HOME=$GRAALVM_HOME" >> $GITHUB_ENV
PATH="$GRAALVM_HOME/bin:$PATH"
echo "PATH=$PATH" >> $GITHUB_ENV
gu install native-image
- name: 'Set up GraalVM for (Windows)'
if: ${{ matrix.os == 'windows-latest' }}
shell: pwsh
run: |
$ARCH="amd64"
$DOWNLOAD_URL="https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${{ env.GRAALVM_VERSION }}/graalvm-ce-java11-windows-${ARCH}-${{ env.GRAALVM_VERSION }}.zip"
$OUTPUT_PATH="C:\graalvm-ce-java11-windows-${ARCH}-${{ env.GRAALVM_VERSION }}.zip"
$GRAALVM_INSTALLATION_PATH="C:\Program Files (x86)\Java"
Invoke-WebRequest -Uri $DOWNLOAD_URL -OutFile $OUTPUT_PATH
if (Test-Path -Path $GRAALVM_INSTALLATION_PATH -PathType Container) {
Write-Host "GRAALVM installation path exists."
} else {
Write-Host "Creating GRAALVM installation path."
New-Item -ItemType Directory -Path $GRAALVM_INSTALLATION_PATH
}
Expand-Archive -Path $OUTPUT_PATH -DestinationPath $GRAALVM_INSTALLATION_PATH
$env:JAVA_HOME="${GRAALVM_INSTALLATION_PATH}\graalvm-ce-java11-22.1.0"
$env:Path="${env:Path};${env:JAVA_HOME}\bin;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\bin\HostX86\x64"
echo "JAVA_HOME=${env:JAVA_HOME}" >> "$env:GITHUB_ENV"
echo "Path=${env:Path}" >> "$env:GITHUB_ENV"
gu.cmd install native-image
- name: 'Cache Maven packages'
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: maven-${{ needs.precheck.outputs.DATE }}-${{ github.run_id }}
- name: 'Prepare dotCMS license'
env:
DOTCMS_LICENSE_KEY: ${{ secrets.DOTCMS_LICENSE }}
run: |
DOTCMS_LICENSE_PATH=~/.dotcms/license
mkdir -p ${DOTCMS_LICENSE_PATH}
echo "${DOTCMS_LICENSE_KEY}" > ${DOTCMS_LICENSE_PATH}/license.dat
echo "DOTCMS_LICENSE_FILE=${DOTCMS_LICENSE_PATH}/license.dat" >> "$GITHUB_ENV"
- name: 'Compile source code'
working-directory: ${{ github.workspace }}
run: |
./mvnw clean install -Dtest.failure.ignore=true -DskipTests=${{ github.event.inputs.skipTests }} -am -pl :dotcms-cli
- name: 'Build uber-jar'
working-directory: ${{ github.workspace }}
run: |
./mvnw package -Dquarkus.package.type=${{ env.MVN_PACKAGE_TYPE }} -DskipTests=${{ github.event.inputs.skipTests }} -pl :dotcms-cli
# Builds a native image of the CLI using GraalVM (Linux/macOS)
# Runs on a matrix for different operating systems
- name: 'Build Native Image (Linux/MacOS)'
if: ${{ matrix.os != 'windows-latest' }}
working-directory: ${{ github.workspace }}
run: |
./mvnw package -Pnative -DskipTests=${{ github.event.inputs.skipTests }} -pl :dotcms-cli
# Builds a native image of the CLI using GraalVM on Windows
# Uses PowerShell for setup and execution
- name: 'Build Native Image (Windows)'
if: ${{ matrix.os == 'windows-latest' }}
working-directory: ${{ github.workspace }}
shell: pwsh
run: |
cmd /c 'call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && .\mvnw.cmd package -Dnative -DskipTests=true -pl :dotcms-cli'
- name: 'Create distribution'
working-directory: ${{ github.workspace }}
run: |
./mvnw -B -ntp -Pdist package -DskipTests=${{ github.event.inputs.skipTests }} -pl :dotcms-cli
- name: 'Distribution tree'
working-directory: ${{ github.workspace }}/tools/dotcms-cli/
run: |
ls -ltr cli/target/distributions
- name: 'Upload build artifact'
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.os }}
path: |
${{ github.workspace }}/tools/dotcms-cli/cli/target/*-runner.jar
${{ github.workspace }}/tools/dotcms-cli/cli/target/distributions/*.zip
${{ github.workspace }}/tools/dotcms-cli/cli/target/distributions/*.tar.gz
release:
needs: [ precheck, build ]
runs-on: ubuntu-latest
steps:
- name: 'Check out repository'
uses: actions/checkout@v4
with:
token: ${{ secrets.CI_MACHINE_TOKEN }}
ref: ${{ needs.precheck.outputs.AUXILIARY_BRANCH }}
- uses: ./.github/actions/cleanup-runner
- name: 'Create artifacts directory'
run: |
mkdir -p ${{ github.workspace }}/artifacts
echo "artifactsDir=${{ github.workspace }}/artifacts" >> "$GITHUB_ENV"
- name: 'Download all build artifacts'
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/artifacts
pattern: artifacts-*
merge-multiple: true
- name: 'List artifacts'
run: |
ls -R
- name: 'Set up Java'
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRO }}
- name: 'Cache Maven packages'
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: maven-${{ needs.precheck.outputs.DATE }}-${{ github.run_id }}
# Creates automated releases using JReleaser
# Generates builds for different platforms
# Signs artifacts
# Publishes to artifact repositories
- name: 'JReleaser'
env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_PROJECT_VERSION: ${{ needs.precheck.outputs.RELEASE_VERSION }}
JRELEASER_ARTIFACTORY_USERNAME: ${{ secrets.EE_REPO_USERNAME }}
JRELEASER_ARTIFACTORY_PASSWORD: ${{ secrets.EE_REPO_PASSWORD }}
JRELEASER_SLACK_WEBHOOK: ${{ secrets.RELEASE_SLACK_WEBHOOK }}
JRELEASER_SLACK_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
working-directory: ${{ github.workspace }}
run: |
tools/dotcms-cli/mvnw -B -Prelease jreleaser:full-release -DartifactsDir=artifacts -Djreleaser.git.root.search=true -pl :dotcms-cli-parent -Dmaven.plugin.validation=VERBOSE
publish-npm-package:
name: "Publish NPM Package"
if: success() # Run only if explicitly indicated and successful
needs: [ precheck, build, release ]
runs-on: ubuntu-latest
steps:
- name: 'Checkout code'
uses: actions/checkout@v4
with:
ref: ${{ needs.precheck.outputs.HEAD }}
- uses: ./.github/actions/cleanup-runner
- name: 'Set up Node.js'
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: 'Install Jinja2'
run: pip install jinja2-cli
- name: 'Download all build artifacts'
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/artifacts
pattern: artifacts-*
merge-multiple: true
# Determines the NPM package version and tag
# Distinguishes between snapshots and releases
- name: 'Dynamic configuration of NPM package Version and Tag'
run: |
MVN_PACKAGE_VERSION=$(echo ${{ github.event.inputs.version }} | tr '[:lower:]' '[:upper:]')
PACKAGE_FULL_NAME=${{ env.NPM_PACKAGE_SCOPE }}/${{ env.NPM_PACKAGE_NAME }}
# Check if the npm package exists
if ! npm view $PACKAGE_FULL_NAME &> /dev/null; then
echo "::error::The package $PACKAGE_FULL_NAME does not exist on npm."
exit 1
fi
# Check if the package is a snapshot
REGEX="([0-9]+\.[0-9]+\.[0-9]+)-SNAPSHOT"
if [[ $MVN_PACKAGE_VERSION =~ $REGEX ]]; then
echo "::debug::Snapshot version found."
NPM_PACKAGE_VERSION_TAG="rc"
MVN_BASE_VERSION="${BASH_REMATCH[1]}"
# Use regular expression to extract version components
if [[ $MVN_BASE_VERSION =~ ([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
MAJOR=$(echo "${BASH_REMATCH[1]}" | sed "s/\b0\+\([1-9]\)/\1/g")
MINOR=$(echo "${BASH_REMATCH[2]}" | sed "s/\b0\+\([1-9]\)/\1/g")
PATCH=$(echo "${BASH_REMATCH[3]}" | sed "s/\b0\+\([1-9]\)/\1/g")
VERSION_NPM_FORMAT="${MAJOR}.${MINOR}.${PATCH}"
echo "::debug::VERSION_NPM_FORMAT: ${VERSION_NPM_FORMAT}"
else
echo "::error::Invalid Maven version format: $MVN_BASE_VERSION"
exit 1
fi
LAST_RC_VERSION=$(npm view $PACKAGE_FULL_NAME versions --json | jq -r 'map(select(test("-rc\\d+$"))) | max')
if [[ $LAST_RC_VERSION == "$VERSION_NPM_FORMAT"* ]]; then
NEXT_RC_VERSION=$(echo "$LAST_RC_VERSION" | awk -F '-rc' '{print $1 "-rc" $2 + 1}')
RC_SUFFIX=$(echo "$NEXT_RC_VERSION" | sed -n 's/.*-rc\([0-9]*\)/-rc\1/p')
else
RC_SUFFIX="-rc1"
fi;
NPM_PACKAGE_VERSION=${MVN_BASE_VERSION}${RC_SUFFIX}
else
echo "::debug::Release version found."
NPM_PACKAGE_VERSION_TAG="latest"
NPM_PACKAGE_VERSION=${MVN_PACKAGE_VERSION}
fi;
echo "::debug::NPM_PACKAGE_VERSION: $NPM_PACKAGE_VERSION"
echo "::debug::NPM_PACKAGE_VERSION_TAG: $NPM_PACKAGE_VERSION_TAG"
echo "NPM_PACKAGE_VERSION=$NPM_PACKAGE_VERSION" >> $GITHUB_ENV
echo "NPM_PACKAGE_VERSION_TAG=$NPM_PACKAGE_VERSION_TAG" >> $GITHUB_ENV
# Sets up the NPM package
# Creates the bin folder with the binaries
# Adds the postinstall.js script
# Generates the package.json file with Jinja2
- name: 'NPM Package setup'
working-directory: ${{ github.workspace }}/tools/dotcms-cli/npm/
env:
MVN_PACKAGE_VERSION: ${{ github.event.inputs.version }}
run: |
echo "Adding bin folder with all the binaries"
mkdir -p bin
find ${{ github.workspace }}/artifacts/distributions/ -name "*.zip" -exec unzip -d bin {} \;
echo "Adding wrapper script"
mv src/postinstall.js.seed src/postinstall.js
echo "Adding README.md file"
cp ${{ github.workspace }}/tools/dotcms-cli/README.md .
echo "Adding package.json file"
jinja2 package.j2 -D packageName=${MVN_PACKAGE_NAME} -D npmPackageName=${NPM_PACKAGE_NAME} -D npmPackageVersion=${NPM_PACKAGE_VERSION} -D packageVersion=${MVN_PACKAGE_VERSION} --format json -o package.json
rm -f package.j2
cat package.json
cat src/postinstall.js
- name: 'NPM Package tree'
run: ls -R ${{ github.workspace }}/tools/dotcms-cli/npm/
- name: 'Publish to NPM registry'
working-directory: ${{ github.workspace }}/tools/dotcms-cli/npm/
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_ORG_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > ~/.npmrc
npm publish --access public --tag ${NPM_PACKAGE_VERSION_TAG}
clean-up:
name: "Clean Up"
if: always()
needs: [ precheck, build, release, publish-npm-package ]
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ needs.precheck.outputs.HEAD }}
- name: 'Delete release auxiliary branch - ${{ needs.precheck.outputs.AUXILIARY_BRANCH }}'
run: |
git push origin --delete ${{ needs.precheck.outputs.AUXILIARY_BRANCH }}