From 2a27368ed0969a1ec14cc79b163042d5c295b3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Enrique=20Colina=20Rodr=C3=ADguez?= Date: Fri, 12 Apr 2024 13:31:39 +0200 Subject: [PATCH] Update cli-release.yml --- .github/workflows/cli-release.yml | 377 ++---------------------------- 1 file changed, 14 insertions(+), 363 deletions(-) diff --git a/.github/workflows/cli-release.yml b/.github/workflows/cli-release.yml index fd9cb34467a1..c1b01a9ae4ae 100644 --- a/.github/workflows/cli-release.yml +++ b/.github/workflows/cli-release.yml @@ -1,5 +1,8 @@ name: dotCLI Release on: + release: + types: [ created ] + workflow_dispatch: inputs: version: @@ -7,13 +10,12 @@ on: default: '1.0.0-SNAPSHOT' required: false - workflow_run: - workflows: ["dotCLI Release trigger"] - types: - - completed + # workflow_run: + # workflows: ["dotCLI Release trigger"] + # types: + # - completed + - release: - types: [ created ] concurrency: group: ${{ github.workflow }}-${{ github.ref || github.run_id }} @@ -35,14 +37,14 @@ env: jobs: precheck: - if: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} + if: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' }} 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 }} + # 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: @@ -117,356 +119,5 @@ jobs: 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=true -am -pl :dotcms-cli - - - name: 'Build uber-jar' - working-directory: ${{ github.workspace }} - run: | - ./mvnw package -Dquarkus.package.type=${{ env.MVN_PACKAGE_TYPE }} -DskipTests=true -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=true -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=true -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: - ref: ${{ needs.precheck.outputs.AUXILIARY_BRANCH }} - # token: ${{ secrets.CI_MACHINE_TOKEN }} - - - 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 }}