From 613177a8ed76ea01e996741df00e488c64bdfe85 Mon Sep 17 00:00:00 2001 From: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Mon, 24 Jun 2024 19:39:57 -0400 Subject: [PATCH 1/4] gh-actions: Refactor and combine build workflows using job conditionals. --- .../workflows/build-and-release-package.yml | 66 +++++++++++--- .github/workflows/build-package.yml | 90 ------------------- 2 files changed, 53 insertions(+), 103 deletions(-) delete mode 100644 .github/workflows/build-package.yml diff --git a/.github/workflows/build-and-release-package.yml b/.github/workflows/build-and-release-package.yml index bd70105..679835e 100644 --- a/.github/workflows/build-and-release-package.yml +++ b/.github/workflows/build-and-release-package.yml @@ -1,9 +1,33 @@ name: "build-and-release-package" +env: + JAVA_VERSION: "11" + on: + pull_request: + paths: + - ".github/actions/native-lib-build/action.yml" + - ".github/workflows/build-and-release-package.yml" + - ".gitmodules" + - "assembly-lib.xml" + - "assembly-package.xml" + - "CMakeLists.txt" + - "pom.xml" + - "src/**/*" + push: + paths: + - ".github/actions/native-lib-build/action.yml" + - ".github/workflows/build-and-release-package.yml" + - ".gitmodules" + - "assembly-lib.xml" + - "assembly-package.xml" + - "CMakeLists.txt" + - "pom.xml" + - "src/**/*" workflow_dispatch: -concurrency: "build-${{github.ref}}" +# Currency group to prevent multiple workflow instances from trying to publish releases +concurrency: "${{github.workflow}}-${{github.ref}}" jobs: build-lib-for-macos: @@ -14,7 +38,7 @@ jobs: submodules: "recursive" - name: "Install requirements" - run: "brew install cmake gcc java11 maven" + run: "brew install cmake gcc java${{env.JAVA_VERSION}} maven" - name: "Build native library for MacOS" id: "build" @@ -33,6 +57,8 @@ jobs: permissions: contents: "read" packages: "write" + env: + JAVA_DIST: "temurin" steps: - uses: "actions/checkout@v4" with: @@ -40,12 +66,20 @@ jobs: - uses: "actions/setup-java@v4" with: - java-version: "11" - distribution: "temurin" + java-version: "${{env.JAVA_VERSION}}" + distribution: "${{env.JAVA_DIST}}" + server-id: "github" + + # This will override the setup-java step above + - if: "startsWith(github.ref, 'refs/tags/v') && github.event_name == 'workflow_dispatch'" + uses: "actions/setup-java@v4" + with: + java-version: "${{env.JAVA_VERSION}}" + distribution: "${{env.JAVA_DIST}}" server-id: "ossrh" server-username: "MAVEN_USERNAME" server-password: "MAVEN_PASSWORD" - gpg-private-key: "${{ secrets.GPG_PRIVATE_KEY }}" + gpg-private-key: "${{secrets.GPG_PRIVATE_KEY}}" gpg-passphrase: "MAVEN_GPG_PASSPHRASE" - name: "Install requirements" @@ -53,18 +87,24 @@ jobs: sudo apt update sudo apt install -y build-essential cmake - - name: "Build native library for Linux" - id: "build" - uses: "./.github/actions/native-lib-build" + - name: "Build, run tests, and package" + run: "mvn --batch-mode test package" - uses: "actions/download-artifact@v4" with: name: "libclp-ffi-java-macos" path: "./target/." - - name: "Build package, run tests, and deploy to GitHub" - run: "mvn --batch-mode deploy -Pmaven_release" + - if: "github.event_name != 'pull_request' && github.ref == 'refs/heads/main'" + name: "Deploy to GitHub Packages" + run: "mvn --batch-mode deploy -DskipTests -Pgithub_release" + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + - if: "startsWith(github.ref, 'refs/tags/v') && github.event_name == 'workflow_dispatch'" + name: "Deploy to Maven Central" + run: "mvn --batch-mode deploy -DskipTests -Pmaven_release" env: - MAVEN_USERNAME: "${{ secrets.OSSRH_USERNAME }}" - MAVEN_PASSWORD: "${{ secrets.OSSRH_TOKEN }}" - MAVEN_GPG_PASSPHRASE: "${{ secrets.GPG_PASSPHRASE }}" + MAVEN_USERNAME: "${{secrets.OSSRH_USERNAME}}" + MAVEN_PASSWORD: "${{secrets.OSSRH_TOKEN}}" + MAVEN_GPG_PASSPHRASE: "${{secrets.GPG_PASSPHRASE}}" diff --git a/.github/workflows/build-package.yml b/.github/workflows/build-package.yml deleted file mode 100644 index af6d4cc..0000000 --- a/.github/workflows/build-package.yml +++ /dev/null @@ -1,90 +0,0 @@ -name: "build-package" - -on: - push: - branches: ["main"] - paths: - - ".github/actions/native-lib-build/action.yml" - - ".github/workflows/build-and-release-package.yml" - - ".github/workflows/build-package.yml" - - "assembly-lib.xml" - - "assembly-package.xml" - - "CMakeLists.txt" - - "pom.xml" - - "src/**" - pull_request: - branches: ["main"] - paths: - - ".github/actions/native-lib-build/action.yml" - - ".github/workflows/build-and-release-package.yml" - - ".github/workflows/build-package.yml" - - "assembly-lib.xml" - - "assembly-package.xml" - - "CMakeLists.txt" - - "pom.xml" - - "src/**" - workflow_dispatch: - -concurrency: "build-${{github.ref}}" - -jobs: - build-lib-for-macos: - runs-on: "macos-latest" - steps: - - uses: "actions/checkout@v4" - with: - submodules: "recursive" - - - name: "Install requirements" - run: "brew install cmake gcc java11 maven" - - - name: "Build native library" - id: "build" - uses: "./.github/actions/native-lib-build" - - - uses: "actions/upload-artifact@v4" - with: - name: "libclp-ffi-java-macos" - path: "${{github.workspace}}/clp-ffi-*-native-lib/" - if-no-files-found: "error" - retention-days: 1 - - build-package: - needs: "build-lib-for-macos" - runs-on: "ubuntu-20.04" - permissions: - contents: "read" - packages: "write" - steps: - - uses: "actions/checkout@v4" - with: - submodules: "recursive" - - - uses: "actions/setup-java@v4" - with: - java-version: "11" - distribution: "temurin" - server-id: "github" - - - name: "Install requirements" - run: | - sudo apt update - sudo apt install -y build-essential cmake - - - name: "Build native library for Linux" - id: "build" - uses: "./.github/actions/native-lib-build" - - - uses: "actions/download-artifact@v4" - with: - name: "libclp-ffi-java-macos" - path: "./target/." - - - name: "Build package and run tests" - run: "mvn --batch-mode test" - - - name: "Deploy to GitHub" - if: "github.event_name != 'pull_request'" - run: "mvn --batch-mode deploy -DskipTests -Pgithub_release" - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" From 63f38529bf93385d597cd37da430e46be890fce4 Mon Sep 17 00:00:00 2001 From: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Mon, 24 Jun 2024 19:48:02 -0400 Subject: [PATCH 2/4] Rename job; Replace GitHub packages target with env var. --- .github/workflows/build-and-release-package.yml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-release-package.yml b/.github/workflows/build-and-release-package.yml index 679835e..1e9ae13 100644 --- a/.github/workflows/build-and-release-package.yml +++ b/.github/workflows/build-and-release-package.yml @@ -51,7 +51,7 @@ jobs: if-no-files-found: "error" retention-days: 1 - build-package: + build-and-release: needs: "build-lib-for-macos" runs-on: "ubuntu-20.04" permissions: diff --git a/pom.xml b/pom.xml index a2107c7..77e9ba0 100644 --- a/pom.xml +++ b/pom.xml @@ -306,7 +306,7 @@ github GitHub Packages - https://maven.pkg.github.com/y-scope/clp-ffi-java + https://maven.pkg.github.com/${env.GITHUB_REPOSITORY} From 98c739b2aadd2ad39b58a0a10638774541f6938b Mon Sep 17 00:00:00 2001 From: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Mon, 24 Jun 2024 22:21:54 -0400 Subject: [PATCH 3/4] Release from branch rather than tag. --- .github/workflows/build-and-release-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-release-package.yml b/.github/workflows/build-and-release-package.yml index 1e9ae13..bd37203 100644 --- a/.github/workflows/build-and-release-package.yml +++ b/.github/workflows/build-and-release-package.yml @@ -71,7 +71,7 @@ jobs: server-id: "github" # This will override the setup-java step above - - if: "startsWith(github.ref, 'refs/tags/v') && github.event_name == 'workflow_dispatch'" + - if: "startsWith(github.ref, 'refs/heads/v') && github.event_name == 'workflow_dispatch'" uses: "actions/setup-java@v4" with: java-version: "${{env.JAVA_VERSION}}" @@ -101,7 +101,7 @@ jobs: env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - - if: "startsWith(github.ref, 'refs/tags/v') && github.event_name == 'workflow_dispatch'" + - if: "startsWith(github.ref, 'refs/heads/v') && github.event_name == 'workflow_dispatch'" name: "Deploy to Maven Central" run: "mvn --batch-mode deploy -DskipTests -Pmaven_release" env: From c592a024254eb942c2cd71605ff6ec331ed3bc43 Mon Sep 17 00:00:00 2001 From: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:00:55 -0400 Subject: [PATCH 4/4] Fix typo. --- .github/workflows/build-and-release-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-release-package.yml b/.github/workflows/build-and-release-package.yml index bd37203..bedd749 100644 --- a/.github/workflows/build-and-release-package.yml +++ b/.github/workflows/build-and-release-package.yml @@ -26,7 +26,7 @@ on: - "src/**/*" workflow_dispatch: -# Currency group to prevent multiple workflow instances from trying to publish releases +# Concurrency group to prevent multiple workflow instances from trying to publish releases concurrency: "${{github.workflow}}-${{github.ref}}" jobs: