Skip to content

gh-actions: Refactor and combine build and release workflows. #22

gh-actions: Refactor and combine build and release workflows.

gh-actions: Refactor and combine build and release workflows. #22

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 group to prevent multiple workflow instances from trying to publish releases
concurrency: "${{github.workflow}}-${{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 java${{env.JAVA_VERSION}} maven"
- name: "Build native library for MacOS"
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-and-release:
needs: "build-lib-for-macos"
runs-on: "ubuntu-20.04"
permissions:
contents: "read"
packages: "write"
env:
JAVA_DIST: "temurin"
steps:
- uses: "actions/checkout@v4"
with:
submodules: "recursive"
- uses: "actions/setup-java@v4"
with:
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/heads/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-passphrase: "MAVEN_GPG_PASSPHRASE"
- name: "Install requirements"
run: |
sudo apt update
sudo apt install -y build-essential cmake
- 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/."
- 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/heads/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}}"