From 2b3753f6c3de96f11cb997d14f491a1e361d653a Mon Sep 17 00:00:00 2001 From: Rounak Datta Date: Tue, 8 Aug 2023 13:40:49 +0530 Subject: [PATCH] PRD-2405 CI/CD setup for publishing CLI artifacts (#1) * Include libcurl install step for linux runner; add macos runner * Just build instead of build+run * Include binary rename step in workflow * Fix path directory * Add additional fields; fix version * Set hardcoded version to start with * Set apt env vars for jreleaser release step as well * Include additiona fields * Set right path for picking up artifacts * Fix names of the artifact archives * Adjust jreleaser zip config * Use versioning and manual release system --- .github/workflows/publish_cli_artifacts.yml | 34 ++++++++++++++++----- build.gradle.kts | 4 ++- jreleaser.yml | 20 ++++++------ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/.github/workflows/publish_cli_artifacts.yml b/.github/workflows/publish_cli_artifacts.yml index e88054b..0a171e5 100644 --- a/.github/workflows/publish_cli_artifacts.yml +++ b/.github/workflows/publish_cli_artifacts.yml @@ -1,12 +1,14 @@ name: Publish CLI Artifacts on: - workflow_dispatch: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+*' # v0.0.1 - this syntax of tags is supported jobs: build_and_assemble: strategy: matrix: - os: [ubuntu-latest] + os: [macos-13, ubuntu-latest] runs-on: ${{ matrix.os }} steps: @@ -19,15 +21,32 @@ jobs: java-version: '17' distribution: 'adopt' + - name: Install prerequisites for Linux runner + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get install libcurl4-openssl-dev + - name: Build Binary - run: ./gradlew runDebugExecutableNative + run: ./gradlew linkDebugExecutableNative + + - name: Rename the Linux binary appropriately + if: matrix.os == 'ubuntu-latest' + working-directory: ./build/bin/native/debugExecutable + run: | + mv cli.kexe cmdk-linux-x86_64 + + - name: Rename the macOS binary appropriately + if: matrix.os == 'macos-13' + working-directory: ./build/bin/native/debugExecutable + run: | + mv cli.kexe cmdk-osx-x86_64 - name: Assemble (rename etc) the binaries uses: jreleaser/release-action@v2 with: arguments: assemble env: - JRELEASER_PROJECT_VERSION: ${{ needs.precheck.outputs.VERSION }} + JRELEASER_PROJECT_VERSION: ${{ github.ref_name }} JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} JRELEASER_PLATFORM_OVERRIDE: ${{ matrix.job.jreleaser_platform }} @@ -37,7 +56,7 @@ jobs: retention-days: 1 name: artifacts path: | - out/jreleaser/cmdk/archive/*.zip + out/jreleaser/assemble/cmdk-cli-client/archive/*.zip release: needs: [ build_and_assemble ] @@ -58,5 +77,6 @@ jobs: with: arguments: full-release -PartifactsDir=artifacts -PskipArchiveResolver env: - JRELEASER_PROJECT_VERSION: ${{ needs.precheck.outputs.VERSION }} - JRELEASER_GITHUB_TOKEN: ${{ secrets.GH_PAT }} + JRELEASER_PROJECT_VERSION: ${{ github.ref_name }} + JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + JRELEASER_PLATFORM_OVERRIDE: ${{ matrix.job.jreleaser_platform }} diff --git a/build.gradle.kts b/build.gradle.kts index 969c465..a9e8f70 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,9 +10,11 @@ repositories { kotlin { val hostOs = System.getProperty("os.name") + val hostArch = System.getProperty("os.arch") val isMingwX64 = hostOs.startsWith("Windows") val nativeTarget = when { - hostOs == "Mac OS X" -> macosArm64("native") + hostOs == "Mac OS X" && hostArch == "x86_64" -> macosX64("native") + hostOs == "Mac OS X" && (hostArch == "arm64" || hostArch == "aarch64") -> macosArm64("native") isMingwX64 -> mingwX64("native") hostOs == "Linux" -> linuxX64("native") else -> throw GradleException("Host OS is not supported: $hostOs") diff --git a/jreleaser.yml b/jreleaser.yml index deb643e..3adfbee 100644 --- a/jreleaser.yml +++ b/jreleaser.yml @@ -3,6 +3,12 @@ project: description: cmdk is the command line client to interact with the CommandK platform links: homepage: https://github.com/commandk-dev/cli + authors: + - Rahul Jain + copyright: CommandK, Inc + website: https://commandk.dev + license: APACHE-2.0 + docsUrl: https://github.com/commandk-dev/java-sdk java: groupId: dev.commandk version: 17 @@ -31,14 +37,8 @@ assemble: active: ALWAYS attachPlatform: true fileSets: - - input: 'build/bin/native/releaseExecutable' - output: 'bin' - includes: [ 'cli.kexe' ] - mapper: - type: 'identity' - includes: - - pattern: 'cli.kexe' - to: 'cmdk-${platform}' + - input: 'build/bin/native/debugExecutable' + includes: [ 'cmdk-*' ] environment: properties: @@ -47,5 +47,7 @@ environment: distributions: cmdk: artifacts: - - path: "{{artifactsDir}}/cmdk-{{platform}}" + - path: "{{artifactsDir}}/cmdk-cli-client-{{projectVersion}}-linux-x86_64.zip" platform: "linux-x86_64" + - path: "{{artifactsDir}}/cmdk-cli-client-{{projectVersion}}-osx-x86_64.zip" + platform: "osx-x86_64"