From ca2dab397dbe8c4a20070fd2f40d96731f7ea564 Mon Sep 17 00:00:00 2001 From: Matthew Pollock Date: Mon, 15 Sep 2025 10:01:05 -0400 Subject: [PATCH 1/2] add GHA to publish artifacts to maven central --- .github/workflows/publish.yml | 70 +++++++++++++++++++++++++++++++ build.gradle.kts | 79 ++++++++++++++++------------------- 2 files changed, 106 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..8868ab4 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,70 @@ +name: publish + +on: + push: + branches: [ "main" ] + +jobs: + unit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + lfs: true + - name: unit-test + run: ./gradlew test + + release: + needs: [ unit ] + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.nextStrict }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + lfs: true + + - id: version + uses: ietf-tools/semver-action@v1.9.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: main + majorList: feat! + minorList: feat, feature + patchList: fix, bugfix + noVersionBumpBehavior: patch + noNewCommitBehavior: silent + + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Create GitHub Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create "${{ steps.version.outputs.nextStrict }}" --target "${{ github.sha }}" + + - name: Tag Release + env: + TAG: ${{ steps.version.outputs.nextStrict }} + run: | + git tag ${TAG} ${GITHUB_SHA} + git push origin ${TAG} + + - name: Publish package to Maven Central + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USER }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_TOKEN }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_PRIVATE_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.GPG_PUBLIC_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} + COMMONS_RELEASE_VERSION: ${{ steps.version.outputs.nextStrict }} + run: | + ./gradlew publishToMavenCentral diff --git a/build.gradle.kts b/build.gradle.kts index 947a4b9..734c95a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ plugins { `java-library` - `maven-publish` id("com.diffplug.spotless") version "6.23.3" + id("com.vanniktech.maven.publish.base") version "0.34.0" } group = "org.mitre" @@ -66,50 +66,43 @@ spotless { } } -publishing { - publications { - create("mavenJava") { - artifactId = "commons" - from(components["java"]) - versionMapping { - usage("java-api") { - fromResolutionOf("runtimeClasspath") - } - usage("java-runtime") { - fromResolutionResult() - } - } - pom { - name.set(project.name) - description.set("MITRE Commons Library for Aviation") - url.set("https://github.com/mitre-public/commons") +mavenPublishing { + publishToMavenCentral(automaticRelease = true) + signAllPublications() + + val releaseVersion = System.getenv("COMMONS_RELEASE_VERSION") + version = if (releaseVersion.isNullOrBlank()) project.version.toString() else releaseVersion - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - developers { - developer { - id.set("jparker") - name.set("Jon Parker") - email.set("jiparker@mitre.org") - } - developer { - id.set("dbaker") - name.set("David Baker") - email.set("dbaker@mitre.org") - } - } + coordinates("org.mitre.boogie", project.name, version.toString()) - //REQUIRED! To publish to maven central (from experience the leading "scm:git" is required too) - scm { - connection.set("scm:git:https://github.com/mitre-public/commons.git") - developerConnection.set("scm:git:ssh://git@github.com:mitre-public/commons.git") - url.set("https://github.com/mitre-public/commons") - } + pom { + name.set(project.name) + description.set("MITRE Commons Library for Aviation") + inceptionYear.set("2023") + url.set("https://github.com/mitre-public/commons") + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("http://www.apache.org/licenses/LICENSE-2.0.txt") } } + developers { + developer { + id.set("dbaker-mitre") + name.set("David Baker") + url.set("https://github.com/dbaker-mitre") + } + developer { + id.set("mattpollock") + name.set("Matt Pollock") + url.set("https://github.com/mattpollock") + } + } + scm { + url.set("https://github.com/mitre-public/commons") + connection.set("scm:git:https://github.com/mitre-public/commons.git") + developerConnection.set("scm:git:ssh://git@github.com:mitre-public/commons.git") + } } -} \ No newline at end of file +} From b06d9447b41a2f9f5ca61d171d449c3754c8424b Mon Sep 17 00:00:00 2001 From: Matthew Pollock Date: Mon, 15 Sep 2025 11:32:58 -0400 Subject: [PATCH 2/2] correct group --- build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 734c95a..e74227e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -67,13 +67,13 @@ spotless { } mavenPublishing { - publishToMavenCentral(automaticRelease = true) + publishToMavenCentral(automaticRelease = false) signAllPublications() val releaseVersion = System.getenv("COMMONS_RELEASE_VERSION") version = if (releaseVersion.isNullOrBlank()) project.version.toString() else releaseVersion - coordinates("org.mitre.boogie", project.name, version.toString()) + coordinates("org.mitre", project.name, version.toString()) pom { name.set(project.name)