Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 54 additions & 14 deletions .github/workflows/build-and-release-package.yml
Original file line number Diff line number Diff line change
@@ -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}}"
# Concurrency group to prevent multiple workflow instances from trying to publish releases
concurrency: "${{github.workflow}}-${{github.ref}}"

jobs:
build-lib-for-macos:
Expand All @@ -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"
Expand All @@ -27,44 +51,60 @@ 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:
contents: "read"
packages: "write"
env:
JAVA_DIST: "temurin"
steps:
- uses: "actions/checkout@v4"
with:
submodules: "recursive"

- 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/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-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 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/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 }}"
MAVEN_USERNAME: "${{secrets.OSSRH_USERNAME}}"
MAVEN_PASSWORD: "${{secrets.OSSRH_TOKEN}}"
MAVEN_GPG_PASSPHRASE: "${{secrets.GPG_PASSPHRASE}}"
90 changes: 0 additions & 90 deletions .github/workflows/build-package.yml

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/y-scope/clp-ffi-java</url>
<url>https://maven.pkg.github.com/${env.GITHUB_REPOSITORY}</url>
</repository>
</distributionManagement>
</profile>
Expand Down
Loading