Skip to content

Commit

Permalink
feat(CLI): #27416 Adding GHA release CLI workflow steps for publishin…
Browse files Browse the repository at this point in the history
…g binaries into NPM registry. (#27514)

* #27416 Building NPM package before publishing.

* #27416 Building NPM package before publishing. Testing.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering. +1.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering. +2.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering. +3.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering. +4.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering. +5.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering. +6.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering. +7.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering. +8.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering. +8.

* #27416 Building NPM package before publishing. Testing Jinja2 rendering. +9.

* #27416 Testing build package.

* #27416 Improving artifact composition.

* #27416 Testing package composition.

* #27416 Fixing set up package name and package version.

* #27416 Fixing set up package name and package version. +1.

* #27416 Fixing set up package name and package version. +2.

* #27416 Testing package composition. +1.

* #27416 Fixing package composition.

* #27416 Testing prepare package content step.

* #27416 Some improvements over the CLI release workflow.

* #27416 Generating rc suffix to NPM package  when release SNAPSHOT version.

* #27416 Testing package structure.

* #27416 Checking package.json file configuration.

* #27416 Fixing workflow syntax.

* #27416 Testing assembly configuration.

* #27416 Fixing assembly configuration.

* #27416 Testing assembly configuration. +1.

* #27416 Testing assembly configuration.

* #27416 Some improvements on packaging process.

* #27416 Setting project name into package.json file.

* #27416 Preparing package.json file.

* #27416 Fixing package.json file.

* #27416 Fixing some package composition failures.

* #27416 Workflow commit messages changed.

* #27416 NPM package tagging improvements.

* #27416 Testing package version number resolution.

* #27416 Refactoring NPM_PACKAGE_VERSION resolution.

* #27416 Fixing package version generation.

* #27416 Fixing NPM package version generation.

* #27416 Fixing NPM package version generation. +1.

* #27416 Fixing NPM package version generation. +2.

* #27416 Fixing NPM package version generation. +3.

* #27416 Fixing NPM package version generation. +4.

* #27416 Fixing NPM package version generation. +5.

* #27416 Ready to test the whole process.

* #27416 Uncomment an important instruction for NPM package set up.

* #27416 NPM_PACKAGE_NAME fixed.

---------

Co-authored-by: Daniel Colina <daniel.colina@dotcms.com>
  • Loading branch information
dcolina and Daniel Colina committed Feb 7, 2024
1 parent 189ed8f commit b4779ec
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 32 deletions.
135 changes: 114 additions & 21 deletions .github/workflows/cli-release-process.yml
Expand Up @@ -19,7 +19,10 @@ env:
JAVA_DISTRO: temurin
NEXT_VERSION: '1.0.0-SNAPSHOT'
GRAALVM_VERSION: '22.1.0'
PACKAGE_TYPE: 'uber-jar'
MVN_PACKAGE_TYPE: 'uber-jar'
NPM_PACKAGE_NAME: 'dotcli'
MVN_PACKAGE_NAME: 'dotcms-cli'
NODE_VERSION: 19

jobs:
precheck:
Expand Down Expand Up @@ -75,7 +78,7 @@ jobs:
./mvnw -B -ntp versions:set versions:commit -DnewVersion=$RELEASE_VERSION
git commit --allow-empty -a -m "🏁 Releasing version $RELEASE_VERSION"
git commit --allow-empty -a -m "🏁 Releasing CLI version $RELEASE_VERSION"
git push https://${{ secrets.CI_MACHINE_USER }}:${{ secrets.CI_MACHINE_TOKEN }}@github.com/${GITHUB_REPOSITORY}
echo "RELEASE_VERSION=$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
Expand All @@ -89,7 +92,7 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ macos-13-xlarge, macOS-latest, ubuntu-latest, windows-latest ] #
os: [ macos-13-xlarge, macOS-latest, ubuntu-latest ]

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -104,40 +107,40 @@ jobs:
run: |
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
echo "GraalVM on Linux (AMD64)"
ARCH=amd64
PLATFORM=linux
INSTALLATION_PATH=/usr/lib/jvm
else
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
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
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
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"
Expand Down Expand Up @@ -170,7 +173,7 @@ jobs:
echo "JAVA_HOME=${env:JAVA_HOME}" >> "$env:GITHUB_ENV"
echo "Path=${env:Path}" >> "$env:GITHUB_ENV"
gu.cmd install native-image
gu.cmd install native-image
- name: 'Cache Maven packages'
uses: actions/cache@v4
Expand All @@ -196,7 +199,7 @@ jobs:
- name: 'Build uber-jar'
working-directory: ${{ github.workspace }}
run: |
./mvnw package -Dquarkus.package.type=${{ env.PACKAGE_TYPE }} -DskipTests=${{ github.event.inputs.skipTests }} -pl :dotcms-cli
./mvnw package -Dquarkus.package.type=${{ env.MVN_PACKAGE_TYPE }} -DskipTests=${{ github.event.inputs.skipTests }} -pl :dotcms-cli
- name: 'Build Native Image (Linux/MacOS)'
if: ${{ matrix.os != 'windows-latest' }}
Expand Down Expand Up @@ -228,7 +231,7 @@ jobs:
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
${{ github.workspace }}/tools/dotcms-cli/cli/target/distributions/*.tar.gz
release:
needs: [ precheck, build ]
Expand All @@ -249,10 +252,10 @@ jobs:
- name: 'Download all build artifacts'
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: ${{ github.workspace }}/artifacts
pattern: artifacts-*
merge-multiple: true

- name: 'List artifacts'
run: |
ls -R
Expand Down Expand Up @@ -296,5 +299,95 @@ jobs:
./mvnw -B -ntp versions:set versions:commit -DnewVersion=$NEXT_VERSION
git commit --allow-empty -a -m "⬆️ Next version $NEXT_VERSION"
git commit --allow-empty -a -m "⬆️ Next CLI version $NEXT_VERSION"
git push https://${{ secrets.CI_MACHINE_USER }}:${{ secrets.CI_MACHINE_TOKEN }}@github.com/${GITHUB_REPOSITORY}
publish-npm-package:
name: "Publish NPM Package"
if: success()
needs: [ build, release ]
runs-on: ubuntu-latest
steps:
- name: 'Checkout code'
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0

- 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

- name: 'Generate package version suffix'
id: generate-version-suffix
env:
MVN_PACKAGE_VERSION: ${{ github.event.inputs.version }}
IS_SNAPSHOT_VERSION: ${{ contains(github.event.inputs.version, 'SNAPSHOT') }}
run: |
if [ "$IS_SNAPSHOT_VERSION" = "true" ]; then
echo "Snapshot version found.";
TAG="rc"
if npm view $NPM_PACKAGE_NAME &> /dev/null; then
echo "${NPM_PACKAGE_NAME} found.";
LAST_RC_VERSION=$(npm view $NPM_PACKAGE_NAME versions --json | jq -r 'map(select(test("-rc\\d+$"))) | max')
echo $LAST_RC_VERSION
NEXT_RC_VERSION=$(echo "$LAST_RC_VERSION" | awk -F '-rc' '{print $1 "-rc" $2 + 1}')
echo $NEXT_RC_VERSION
RC_SUFFIX=$(echo "$NEXT_RC_VERSION" | sed -n 's/.*-rc\([0-9]*\)/-rc\1/p')
echo $RC_SUFFIX
else
echo "${NPM_PACKAGE_NAME} not found.";
RC_SUFFIX="-rc1"
fi;
else
echo "Release version found.";
TAG="latest"
RC_SUFFIX=""
fi;
VERSION=$(echo "$MVN_PACKAGE_VERSION" | sed 's/-SNAPSHOT//I')
echo "NPM_PACKAGE_VERSION=${VERSION}${RC_SUFFIX}" >> $GITHUB_ENV
echo "NPM_PACKAGE_VERSION_TAG=$TAG" >> $GITHUB_ENV
- 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'
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > ~/.npmrc
npm publish --access public --tag ${NPM_PACKAGE_VERSION_TAG}
12 changes: 4 additions & 8 deletions tools/dotcms-cli/cli/src/assembly/assembly.xml
Expand Up @@ -25,19 +25,15 @@
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 http://maven.apache.org/xsd/assembly-2.2.0.xsd">
<id>dist</id>
<formats>
<format>tar.gz</format>
<!-- <format>tar.gz</format>-->
<format>zip</format>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<!-- <file>-->
<!-- <source>LICENSE.txt</source>-->
<!-- <outputDirectory>./</outputDirectory>-->
<!-- </file>-->
<file>
<source>${project.build.directory}/${project.artifactId}-${project.version}-runner${executable-suffix}</source>
<outputDirectory>./bin</outputDirectory>
<destName>${project.artifactId}${executable-suffix}</destName>
<outputDirectory>./</outputDirectory>
<destName>${project.artifactId}-${project.version}-${os.detected.classifier}${executable-suffix}</destName>
<fileMode>0755</fileMode>
</file>
</files>
Expand Down
6 changes: 3 additions & 3 deletions tools/dotcms-cli/jreleaser.yml
Expand Up @@ -56,10 +56,10 @@ distributions:
platform: 'osx-aarch_64'
- path: '{{artifactsDir}}/distributions/dotcms-cli-{{projectVersion}}-osx-x86_64.zip'
platform: 'osx-x86_64'
- path: '{{artifactsDir}}/distributions/dotcms-cli-{{projectVersion}}-linux-x86_64.tar.gz'
- path: '{{artifactsDir}}/distributions/dotcms-cli-{{projectVersion}}-linux-x86_64.zip'
platform: 'linux-x86_64'
- path: '{{artifactsDir}}/distributions/dotcms-cli-{{projectVersion}}-windows-x86_64.zip'
platform: 'windows-x86_64'
# - path: '{{artifactsDir}}/distributions/dotcms-cli-{{projectVersion}}-windows-x86_64.zip'
# platform: 'windows-x86_64'

upload:
artifactory:
Expand Down
37 changes: 37 additions & 0 deletions tools/dotcms-cli/npm/package.j2
@@ -0,0 +1,37 @@
{
"name": "@dotcms/{{ npmPackageName }}",
"version": "{{ npmPackageVersion }}",
"scripts": {
"postinstall": "node src/postinstall.js install",
"postuninstall": "node src/postinstall.js uninstall && npm prune"
},
"binaries": {
"{{ packageName }}-darwin-arm64": "bin/{{ packageName }}-{{ packageVersion }}-osx-aarch_64",
"{{ packageName }}-darwin-x64": "bin/{{ packageName }}-{{ packageVersion }}-osx-x86_64",
"{{ packageName }}-linux-x64": "bin/{{ packageName }}-{{ packageVersion }}-linux-x86_64"
},
"alias": "{{ npmPackageName }}",
"packageName": "{{ packageName }}",
"files": [
"bin",
"src"
],
"description": "Official command-line tool to manage dotCMS content.",
"repository": {
"type": "git",
"url": "git+https://github.com/dotCMS/core.git#master"
},
"keywords": [
"dotCMS",
"CMS",
"Content Management",
"CLI",
"dotCMS CLI",
"dotCMS command-line tool"
],
"author": "dotcms <dev@dotcms.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/dotCMS/core/issues"
}
}

0 comments on commit b4779ec

Please sign in to comment.