Skip to content

Commit

Permalink
adapt workflow and build script in order to deploy on maven central (#76
Browse files Browse the repository at this point in the history
)

The purpose of the pull request is to switch deployment of t2iapi (java
part) from github packages to maven central.

# Checklist

The following aspects have been respected by the author of this pull
request, confirmed by both pull request assignee **and** reviewer:

* Changelog update (necessity checked and entry added or not added
respectively)
  * [X] Pull Request Assignee
  * [x] Reviewer
* README update (necessity checked and entry added or not added
respectively)
  * [X] Pull Request Assignee
  * [x] Reviewer

---------

Co-authored-by: Staeck, Philipp <[email protected]>
  • Loading branch information
pstaeck and pstaeck authored May 28, 2024
1 parent f2daf60 commit 87c0432
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 37 deletions.
55 changes: 25 additions & 30 deletions .github/workflows/build-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# Run `git checkout`
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Source dependency versions
working-directory: config
run: |
Expand All @@ -29,13 +29,13 @@ jobs:
wget https://github.com/protocolbuffers/protobuf/releases/download/v${{ env.COMMON_PROTOC_VERSION }}/protoc-${{ env.COMMON_PROTOC_VERSION }}-linux-x86_64.zip -P ${{ runner.temp }}/protoc_install
unzip ${{ runner.temp }}/protoc_install/*.zip -d ${{ runner.temp }}/protoc_install/protoc
echo "${{ runner.temp }}/protoc_install/protoc/bin" >> $GITHUB_PATH
- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}
- name: Execute build
Expand All @@ -46,12 +46,12 @@ jobs:
with:
name: target_jars
path: java/build/libs/*.jar
run-tests-java11:
run-tests-java17:
runs-on: ubuntu-latest
needs: build-java
steps:
# Run `git checkout`
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Download t2iapi jar artifact
uses: actions/download-artifact@v3
with:
Expand All @@ -61,13 +61,13 @@ jobs:
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo RELEASE_VERSION=1 >> $GITHUB_ENV
- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}
- name: Execute tests
Expand All @@ -78,24 +78,16 @@ jobs:
with:
name: test_results
path: tests/java/build/reports/tests/test/**/*.*
deploy-github-packages:
deploy-maven-central:
runs-on: ubuntu-latest
needs: run-tests-java11
needs: run-tests-java17
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
permissions:
packages: write
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Source dependency versions
working-directory: config
run: |
cat versions.txt >> $GITHUB_ENV
- name: Download t2iapi test results artifact
uses: actions/download-artifact@v3
with:
name: test_results
path: test_results/
- name: Detect release version
if: startsWith(github.ref, 'refs/tags/v')
run: |
Expand All @@ -107,21 +99,24 @@ jobs:
wget https://github.com/protocolbuffers/protobuf/releases/download/v${{ env.COMMON_PROTOC_VERSION }}/protoc-${{ env.COMMON_PROTOC_VERSION }}-linux-x86_64.zip -P ${{ runner.temp }}/protoc_install
unzip ${{ runner.temp }}/protoc_install/*.zip -d ${{ runner.temp }}/protoc_install/protoc
echo "${{ runner.temp }}/protoc_install/protoc/bin" >> $GITHUB_PATH
- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up Java for publishing to Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}
- name: Publish package
working-directory: ./java
run: ./gradlew publish
run: |
./gradlew publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
MAVEN_GPG_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
- name: Install zip
if: startsWith(github.ref, 'refs/tags/')
uses: montudor/action-zip@v1
Expand All @@ -140,4 +135,4 @@ jobs:
java/build/publications/maven/pom-default.xml
java-test-results.zip
prerelease: ${{ !startsWith(github.ref, 'refs/tags/v') }}
body_path: CHANGELOG.md
body_path: CHANGELOG.md
54 changes: 48 additions & 6 deletions java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
`maven-publish`
id("com.google.protobuf") version "0.9.1"
id("com.google.osdetector") version "1.7.1"
signing
}

val configFile = File("../config/versions.txt").readLines()
Expand All @@ -14,9 +15,10 @@ val protocVersion = configFileMap["JAVA_PROTOC_VERSION"]
val grpcVersion = configFileMap["JAVA_GRPC_VERSION"]
val baseVersion = configFileMap["BASE_PACKAGE_VERSION"]!!
val buildId: String? = System.getenv("GITHUB_RUN_NUMBER")
val t2iapiVersion: String = when (System.getenv("RELEASE_VERSION") == "1") {
val isRelease = System.getenv("RELEASE_VERSION") == "1"
val t2iapiVersion: String = when (isRelease) {
true -> baseVersion
false -> baseVersion + ( buildId?.let { ".$it" } ?: "" )
false -> baseVersion + ( buildId?.let { ".$it" } ?: "" ) + "-SNAPSHOT"
}

version = t2iapiVersion
Expand Down Expand Up @@ -44,6 +46,11 @@ tasks.compileJava {
targetCompatibility = "11"
}

java {
withJavadocJar()
withSourcesJar()
}

protobuf {
protoc {
// The artifact spec for the Protobuf Compiler
Expand Down Expand Up @@ -74,6 +81,26 @@ publishing {
from(components["java"])
pom {
name.set("test 2 interface api")
url.set("https://github.com/Draegerwerk/t2iapi")
description.set(
"t2iapi describes a product-independent interface to manipulate devices which utilize" +
" ISO/IEEE 11073 SDC during verification."
)

scm {
connection.set("scm:git:git://github.com/Draegerwerk/t2iapi.git")
developerConnection.set("scm:git:ssh://github.com/Draegerwerk/t2iapi.git")
url.set("https://github.com/Draegerwerk/t2iapi")
}

developers {
developer {
id.set("t2i")
name.set("T2I Team")
email.set("[email protected]")
}
}

licenses {
license {
name.set("MIT License")
Expand All @@ -86,12 +113,27 @@ publishing {

repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/Draegerwerk/t2iapi")
name = "Sonatype"

val releaseUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
val snapshotsUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"

url = uri(if (isRelease) releaseUrl else snapshotsUrl)
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
}
}
}
}

signing {
useInMemoryPgpKeys(System.getenv("MAVEN_GPG_PRIVATE_KEY"), System.getenv("MAVEN_GPG_PASSPHRASE"))
sign(publishing.publications["maven"])
}

tasks.javadoc {
if (JavaVersion.current().isJava9Compatible) {
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
}
}
2 changes: 1 addition & 1 deletion tests/java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ val baseVersion = configFileMap["BASE_PACKAGE_VERSION"]!!
val buildId: String? = System.getenv("GITHUB_RUN_NUMBER")
val t2iapiVersion: String = when (System.getenv("RELEASE_VERSION") == "1") {
true -> baseVersion
false -> baseVersion + ( buildId?.let { ".$it" } ?: "" )
false -> baseVersion + ( buildId?.let { ".$it" } ?: "" ) + "-SNAPSHOT"
}

dependencies {
Expand Down

0 comments on commit 87c0432

Please sign in to comment.