From fb5224ab131898f378a3a2e79764818239a2cdc0 Mon Sep 17 00:00:00 2001 From: Alan O'Callaghan Date: Mon, 21 Oct 2024 21:11:43 +0100 Subject: [PATCH 1/3] Actions --- .github/workflows/build.yml | 41 ++++++++++++++++++++++++++ .github/workflows/github_release.yml | 23 +++++++++++++++ .github/workflows/maven.yml | 44 ++++++++++++++++++++++++++++ .github/workflows/maven_release.yml | 12 ++++++++ .github/workflows/maven_snapshot.yml | 10 +++++++ 5 files changed, 130 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/github_release.yml create mode 100644 .github/workflows/maven.yml create mode 100644 .github/workflows/maven_release.yml create mode 100644 .github/workflows/maven_snapshot.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..062c8f0 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,41 @@ +name: Run gradle build + +on: + push: + branches: + - "main" + pull_request: + branches: + - "main" + workflow_dispatch: + workflow_call: + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + + - uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build with Gradle + run: | + ./gradlew build + + - uses: actions/upload-artifact@v4 + with: + path: build/libs/*.jar + name: build + retention-days: 7 diff --git a/.github/workflows/github_release.yml b/.github/workflows/github_release.yml new file mode 100644 index 0000000..f291f04 --- /dev/null +++ b/.github/workflows/github_release.yml @@ -0,0 +1,23 @@ +name: Make draft release + +on: + workflow_dispatch: + +jobs: + build: + name: Run build + uses: ./.github/workflows/build.yml + + release: + needs: build + permissions: + contents: write + runs-on: ubuntu-latest + steps: + + - uses: actions/download-artifact@v4 + + - name: Release + env: + GH_TOKEN: ${{ github.token }} + run: gh release create --draft ${{ github.ref_name }} --title ${{ github.ref_name }} build/*.jar diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..7aca9b8 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,44 @@ +name: Publish to SciJava Maven + +on: + workflow_call: + inputs: + release: + required: false + type: boolean + default: false + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Add release flag if input variable is set + if: ${{ inputs.release }} + shell: bash + run: | + echo "RELEASE_FLAG='-Prelease'" >> $GITHUB_ENV + + - name: Publish + shell: bash + run: | + ./gradlew publish -P toolchain=21 $RELEASE_FLAG + env: + MAVEN_USER: ${{ secrets.MAVEN_USER }} + MAVEN_PASS: ${{ secrets.MAVEN_PASS }} + + - uses: actions/upload-artifact@v3 + if: ${{ inputs.release }} + with: + name: ${{ github.event.repository.name }}-release-jar + path: build/libs + retention-days: 7 diff --git a/.github/workflows/maven_release.yml b/.github/workflows/maven_release.yml new file mode 100644 index 0000000..dc0b76c --- /dev/null +++ b/.github/workflows/maven_release.yml @@ -0,0 +1,12 @@ +name: Publish release to SciJava Maven + +on: + workflow_dispatch: + +jobs: + build: + name: Publish release + uses: ./.github/workflows/maven.yml + secrets: inherit + with: + release: true diff --git a/.github/workflows/maven_snapshot.yml b/.github/workflows/maven_snapshot.yml new file mode 100644 index 0000000..458d45e --- /dev/null +++ b/.github/workflows/maven_snapshot.yml @@ -0,0 +1,10 @@ +name: Publish snapshot to SciJava Maven + +on: + workflow_dispatch: + +jobs: + build: + name: Publish snapshot + uses: ./.github/workflows/maven.yml + secrets: inherit From 8891a50a808b241bc16ebf946625106bad6bd319 Mon Sep 17 00:00:00 2001 From: Alan O'Callaghan Date: Mon, 21 Oct 2024 21:16:24 +0100 Subject: [PATCH 2/3] Make publish work --- build.gradle | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6fa43e1..2afa708 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java-library' + id 'maven-publish' id 'com.github.johnrengelman.shadow' version '8.1.1' // Include this plugin to avoid downloading JavaCPP dependencies for all platforms id 'org.bytedeco.gradle-javacpp-platform' @@ -74,7 +75,7 @@ tasks.register("copyDependencies", Copy) { } /* - * Ensure Java 17 compatibility, and include sources and javadocs when building. + * Ensure Java compatibility, and include sources and javadocs when building. */ java { toolchain { @@ -126,3 +127,35 @@ repositories { url "https://maven.scijava.org/content/repositories/snapshots" } } + + +publishing { + repositories { + maven { + name = "SciJava" + def releasesRepoUrl = uri("https://maven.scijava.org/content/repositories/releases") + def snapshotsRepoUrl = uri("https://maven.scijava.org/content/repositories/snapshots") + // Use gradle -Prelease publish + url = project.hasProperty('release') ? releasesRepoUrl : snapshotsRepoUrl + credentials { + username = System.getenv("MAVEN_USER") + password = System.getenv("MAVEN_PASS") + } + } + } + + publications { + mavenJava(MavenPublication) { + from components.java + + pom { + licenses { + license { + name = 'Apache License v2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0' + } + } + } + } + } +} From ec44c58ca5e4ec8f39743bf400d4581f5cddb122 Mon Sep 17 00:00:00 2001 From: Alan O'Callaghan Date: Mon, 21 Oct 2024 21:18:27 +0100 Subject: [PATCH 3/3] Group --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 2afa708..5de0518 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ base { archivesName = rootProject.name version = '0.1.0-SNAPSHOT' description = 'Connect QuPath to Python using Py4J' + group = 'io.github.qupath' } ext.qupathVersion = gradle.ext.qupathVersion