-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 1588 publish to maven central (#1596)
Added steps to publish_assets.yml to push to Sonatype. Modified gradle config to sign artefacts and push.
- Loading branch information
Showing
7 changed files
with
201 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ name: Upload Release Assets | |
on: | ||
release: | ||
types: [ prereleased, released ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
upload-release-assets: | ||
|
@@ -21,9 +22,11 @@ jobs: | |
distribution: 'zulu' | ||
|
||
- name: Generate CLI jar | ||
if: github.event_name == 'release' | ||
run: ./gradlew shadowJar | ||
|
||
- name: Upload JAR Asset | ||
if: github.event_name == 'release' | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
@@ -34,9 +37,11 @@ jobs: | |
asset_content_type: application/java-archive | ||
|
||
- name: Generate rules.json | ||
if: github.event_name == 'release' | ||
run: ./gradlew webClientRulesJSON | ||
|
||
- name: Upload rules.json asset | ||
if: github.event_name == 'release' | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
@@ -47,12 +52,15 @@ jobs: | |
asset_content_type: application/json | ||
|
||
- name: Generate JavaDocs | ||
if: github.event_name == 'release' | ||
run: ./gradlew aggregateJavadoc | ||
|
||
- name: Zip JavaDocs | ||
if: github.event_name == 'release' | ||
run: zip -r javadocs.zip build/docs/aggregateJavadoc | ||
|
||
- name: Upload zipped Javadocs | ||
if: github.event_name == 'release' | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
@@ -62,3 +70,32 @@ jobs: | |
asset_name: javadocs.zip | ||
asset_content_type: application/zip | ||
|
||
# The following steps will publish artifacts to a sonatype staging repo with the aim of promoting them to maven central | ||
# Pretty much everything is done through gradle. | ||
# The version used will be according to the axion-release-plugin, meaning it will take a tag if present. | ||
# The tag should follow semantic versioning, e.g. v1.2.3. There could be a suffix, e.g. v1.2.3-TEST | ||
# gradle will build, sign then upload artifacts to a Sonatype staging repo. | ||
# See https://s01.oss.sonatype.org for accessing these repos. | ||
# At this point it should manually be closed, which will trigger acceptance tests for maven central (but not transfer yet) | ||
# Once closed, the repo is available for testing. | ||
# After testing, it can be manually promoted on the sonatype site, which will then publish to maven central. | ||
# Note than once in maven central a release cannot be removed or altered. | ||
|
||
- name: Load secrets from 1Password | ||
id: onepw_secrets | ||
uses: 1password/[email protected] | ||
with: | ||
export-env: true # Export loaded secrets as environment variables | ||
env: | ||
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} # This is required to connect to the vault in our 1Password account. | ||
MAVEN_GPG_PRIVATE_KEY: "op://rbiv7rvkkrsdlpcrz3bmv7nmcu/yztcx47yzp4vizjyaq7ulvkgoi/Private Key" | ||
MAVEN_GPG_PASSPHRASE: "op://rbiv7rvkkrsdlpcrz3bmv7nmcu/yztcx47yzp4vizjyaq7ulvkgoi/password" | ||
|
||
- name: Build and Publish to Sonatype | ||
run: | | ||
# The gradle java verifying plugin does not work with java 17. | ||
# Don't verify since it has already been done when the PR was created. | ||
./gradlew publish -x verifyGoogleJavaFormat | ||
env: | ||
SONATYPE_USERNAME: ${{secrets.SONATYPE_USERNAME}} | ||
SONATYPE_PASSWORD: ${{secrets.SONATYPE_PASSWORD}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,21 @@ | |
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* A note about publishing and signing. | ||
* Maven central requires that artifacts be signed. And upload is done to Sonatype. | ||
* To publish you will need these environment variables defined: | ||
* SONATYPE_USERNAME | ||
* SONATYPE_PASSWORD | ||
* MAVEN_GPG_PRIVATE_KEY | ||
* MAVEN_GPG_PASSPHRASE | ||
* Suggestion is to put these in a shell script with restricted read permissions, then source it before calling | ||
* ./gradlew publish. | ||
*/ | ||
plugins { | ||
id 'java' | ||
id 'maven-publish' | ||
id 'signing' | ||
id 'test-report-aggregation' | ||
id 'com.github.sherter.google-java-format' version '0.9' | ||
id "io.freefair.aggregate-javadoc" version "6.4.3" | ||
|
@@ -24,7 +36,7 @@ plugins { | |
|
||
// Setup and configure properties that are consistent across all projects, including sub-modules. | ||
allprojects { | ||
group 'org.mobilitydata' | ||
group 'org.mobilitydata.gtfs-validator' | ||
|
||
// Per the axion-release plugin, this computes the project version based | ||
// on the most recent tag in the repo. | ||
|
@@ -66,6 +78,105 @@ allprojects { | |
} | ||
} | ||
|
||
subprojects { | ||
apply plugin: 'java' | ||
|
||
// Cannot publish a SNAPSHOT. The provided sonatype url will not accept it. | ||
tasks.withType(PublishToMavenRepository).all { task -> | ||
task.onlyIf { | ||
if (project.version.toString().contains('SNAPSHOT')) { | ||
throw new GradleException("Publishing is not allowed for SNAPSHOT versions. Currently " + project.version) | ||
} | ||
true | ||
} | ||
} | ||
|
||
task javadocJar(type: Jar) { | ||
archiveClassifier.set('javadoc') | ||
from javadoc | ||
} | ||
|
||
task sourcesJar(type: Jar) { | ||
archiveClassifier.set('sources') | ||
from sourceSets.main.allSource | ||
} | ||
|
||
// These modules require the same publishing configuration, apart from the name of the module | ||
// Also we want to limit artefact publishing to these modules. | ||
if (project.name == 'main' || | ||
project.name == 'core' || | ||
project.name == 'model') { | ||
def fullProjectName = 'gtfs-validator-' + project.name | ||
|
||
afterEvaluate { | ||
publishing { | ||
repositories { | ||
// This is the sonatype staging repo for maven. | ||
// Once uploaded, the repo needs to be manually closed, which will trigger acceptance tests for | ||
// maven central (but not transfer yet). | ||
// Once successfully closed, the repo is available for testing. | ||
// After testing, it can be manually promoted on the sonatype site, which will then publish to maven central. | ||
maven { | ||
url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2' | ||
credentials { | ||
username System.getenv("SONATYPE_USERNAME") | ||
password System.getenv("SONATYPE_PASSWORD") | ||
} | ||
} | ||
} | ||
|
||
publications { | ||
mavenJava(MavenPublication) { | ||
from components.java | ||
artifactId = fullProjectName | ||
|
||
artifact sourcesJar | ||
artifact javadocJar | ||
|
||
// Definition of the pom that will be included with the uploaded artifacts. | ||
pom { | ||
name = fullProjectName | ||
description = 'The ' + project.name + " artifacts from the gtfs validator" | ||
url = 'https://github.com/MobilityData/gtfs-validator' | ||
licenses { | ||
license { | ||
name = 'The Apache License, Version 2.0' | ||
url = 'https://github.com/MobilityData/gtfs-validator/blob/master/LICENSE' | ||
} | ||
} | ||
developers { | ||
developer { | ||
id = 'dev' | ||
name = 'Dev group' | ||
email = '[email protected]' | ||
} | ||
} | ||
scm { | ||
connection = 'scm:git:git://github.com/MobilityData/gtfs-validator.git' | ||
developerConnection = 'scm:git:ssh://github.com/MobilityData/gtfs-validator.git' | ||
url = 'https://github.com/MobilityData/gtfs-validator' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
signing { | ||
useInMemoryPgpKeys(System.getenv('MAVEN_GPG_PRIVATE_KEY'), System.getenv('MAVEN_GPG_PASSPHRASE')) | ||
sign publishing.publications.mavenJava | ||
} | ||
} | ||
|
||
} | ||
compileJava { | ||
options.compilerArgs << '-parameters' | ||
} | ||
|
||
compileTestJava { | ||
options.compilerArgs << '-parameters' | ||
} | ||
|
||
} | ||
|
||
reporting { | ||
reports { | ||
// Necessary for unit test result aggregation. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
plugins { | ||
id 'java' | ||
id 'maven-publish' | ||
id 'signing' | ||
} | ||
|
||
//publishing { | ||
// publishing and signing are done in gtfs-validator build.gradle to minimize repetition | ||
//} | ||
|
||
|
||
dependencies { | ||
annotationProcessor 'com.google.auto.value:auto-value:1.7.4' | ||
compileOnly 'com.google.auto.value:auto-value-annotations:1.7.4' | ||
implementation 'org.jetbrains:annotations:20.1.0' | ||
implementation 'com.google.code.findbugs:jsr305:3.0.2' | ||
} | ||
|
||
compileJava { | ||
options.compilerArgs << '-parameters' | ||
} | ||
|
||
compileTestJava { | ||
options.compilerArgs << '-parameters' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters