Skip to content

Commit 832dd15

Browse files
committed
Testing GH actions with a SNAPSHOT version
1 parent 7e5cc20 commit 832dd15

File tree

5 files changed

+85
-98
lines changed

5 files changed

+85
-98
lines changed

.github/workflows/publish_assets.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,6 @@ jobs:
9191
asset_name: javadocs.zip
9292
asset_content_type: application/zip
9393

94-
# The following steps will publish artifacts to a sonatype staging repo with the aim of promoting them to maven central
95-
# Pretty much everything is done through gradle.
96-
# The version used will be according to the axion-release-plugin, meaning it will take a tag if present.
97-
# The tag should follow semantic versioning, e.g. v1.2.3. There could be a suffix, e.g. v1.2.3-TEST
98-
# gradle will build, sign then upload artifacts to a Sonatype staging repo.
99-
# See https://s01.oss.sonatype.org for accessing these repos.
100-
# At this point it should manually be closed, which will trigger acceptance tests for maven central (but not transfer yet)
101-
# Once closed, the repo is available for testing.
102-
# After testing, it can be manually promoted on the sonatype site, which will then publish to maven central.
103-
# Note than once in maven central a release cannot be removed or altered.
104-
10594
- name: Load secrets from 1Password
10695
id: onepw_secrets
10796
uses: ./.github/actions/extract-1password-secret
@@ -112,7 +101,12 @@ jobs:
112101

113102
- name: Build and Publish to Sonatype
114103
run: |
115-
# Don't verify since it has already been done when the PR was created.
116-
./gradlew publish --rerun-tasks -x spotlessCheck
117-
./gradlew customPublish
104+
# Publishing to Maven Central will fail if the version is a snapshot, i.e. there is no version tag
105+
# directly on the current commit.
106+
# See https://repo1.maven.org/maven2/org/mobilitydata/gtfs-validator/ for the maven central repository.
107+
# One this step is done, the artefacts will be validated but not yet published.
108+
# See https://central.sonatype.com/publishing/deployments (you need to login as mobilitydata)
109+
# From this page you can examine the list of artefacts, and either drop them or release them.
110+
# Note that once released, the artefacts cannot be removed or altered.
111+
./gradlew publishToMavenCentral
118112

.github/workflows/publish_snapshots.yml

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ name: Publish Jars Snapshots
33
on:
44
push:
55
branches: [ 146-Migrate-maven-repository ]
6-
paths-ignore:
7-
- '**.md'
8-
- '**.py'
9-
- 'Dockerfile'
10-
- '.gitignore'
11-
- 'LICENSE'
12-
- 'docker.yml'
13-
- 'formatting.yml'
14-
- 'test_pack_dock.yml'
15-
- 'triage.yml'
16-
- 'acceptance_test.yml'
17-
- 'web/**'
6+
paths:
7+
- 'core/src/main/**'
8+
- 'main/src/main/**'
9+
- 'model/src/main/**'
10+
- 'build.gradle'
11+
- '.github/workflows/publish_snapshots.yml'
1812
workflow_dispatch:
1913

2014
env:
@@ -38,17 +32,6 @@ jobs:
3832
java-version: ${{ env.java_version }}
3933
distribution: ${{ env.java_distribution }}
4034

41-
# The following steps will publish artifacts to a sonatype staging repo with the aim of promoting them to maven central
42-
# Pretty much everything is done through gradle.
43-
# The version used will be according to the axion-release-plugin, meaning it will take a tag if present.
44-
# The tag should follow semantic versioning, e.g. v1.2.3. There could be a suffix, e.g. v1.2.3-TEST
45-
# gradle will build, sign then upload artifacts to a Sonatype staging repo.
46-
# See https://s01.oss.sonatype.org for accessing these repos.
47-
# At this point it should manually be closed, which will trigger acceptance tests for maven central (but not transfer yet)
48-
# Once closed, the repo is available for testing.
49-
# After testing, it can be manually promoted on the sonatype site, which will then publish to maven central.
50-
# Note than once in maven central a release cannot be removed or altered.
51-
5235
- name: Load secrets from 1Password
5336
id: onepw_secrets
5437
uses: ./.github/actions/extract-1password-secret
@@ -57,7 +40,11 @@ jobs:
5740
VARIABLES_TO_EXTRACT: 'MAVEN_GPG_PASSPHRASE, MAVEN_GPG_PRIVATE_KEY, MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME, MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD'
5841
ONE_PASSWORD_SECRET_REFERENCES: ${{ vars.ONE_PASSWORD_SECRET_REFERENCES }}
5942

60-
- name: Build and Publish to Sonatype
43+
- name: Build and Publish to the snapshot repository
6144
run: |
62-
./gradlew publish --rerun-tasks --info
45+
# Publishing to the snapshot repository will fail if the current commit has a version tag.
46+
# Which in effect makes it a release.
47+
# See https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/org/mobilitydata/gtfs-validator/
48+
# for the snapshot repository.
49+
./gradlew publishToSnapshotRepository
6350

build.gradle

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ plugins {
2626
id 'java'
2727
id 'maven-publish'
2828
id 'signing'
29-
id 'distribution'
3029
id 'test-report-aggregation'
3130
id "io.freefair.aggregate-javadoc" version "6.4.3"
3231
id "pl.allegro.tech.build.axion-release" version "1.15.3"
@@ -39,7 +38,7 @@ allprojects {
3938

4039
// Per the axion-release plugin, this computes the project version based
4140
// on the most recent tag in the repo.
42-
version scmVersion.version
41+
version "1.2-SNAPSHOT"
4342

4443
repositories {
4544
mavenCentral()
@@ -101,24 +100,15 @@ subprojects {
101100

102101
// These modules require the same publishing configuration, apart from the name of the module
103102
// Also we want to limit artefact publishing to these modules.
104-
if (project.name == 'main' ||
105-
project.name == 'core' ||
106-
project.name == 'model') {
103+
if (project.name == 'main'
104+
|| project.name == 'core'
105+
|| project.name == 'model'
106+
) {
107107
def fullProjectName = 'gtfs-validator-' + project.name
108108

109109
afterEvaluate {
110-
tasks.named('publish') {
111-
doFirst {
112-
println "Project version: ${scmVersion.version}"
113-
}
114-
}
115110
publishing {
116111
repositories {
117-
// This is the sonatype staging repo for maven.
118-
// Once uploaded, the repo needs to be manually closed, which will trigger acceptance tests for
119-
// maven central (but not transfer yet).
120-
// Once successfully closed, the repo is available for testing.
121-
// After testing, it can be manually promoted on the sonatype site, which will then publish to maven central.
122112
maven {
123113
if (version.endsWith('SNAPSHOT')) {
124114
url = 'https://central.sonatype.com/repository/maven-snapshots/'
@@ -173,24 +163,34 @@ subprojects {
173163
}
174164

175165

176-
// tasks.named('publish') {
177-
// finalizedBy customPublish
178-
// }
179-
}
180-
task customPublish {
181-
// dependsOn publishMavenJavaPublicationToMavenRepository
182-
// mustRunAfter publish
183-
onlyIf {
184-
if (project.version.toString().contains('SNAPSHOT')) {
185-
throw new GradleException("Publishing to Maven Central Portal is not allowed for SNAPSHOT versions. Currently " + project.version)
166+
tasks.register('publishToMavenCentral') {
167+
if (!version.toString().endsWith('SNAPSHOT')) {
168+
dependsOn tasks.publish
169+
}
170+
doFirst {
171+
if (version.toString().endsWith('SNAPSHOT')) {
172+
throw new GradleException("Version \"" + version +
173+
"\" is a snapshot. Cannot publish to Maven Central")
174+
}
175+
}
176+
177+
doLast {
178+
exec {
179+
workingDir project.projectDir
180+
commandLine 'bash', "${project.rootDir}/scripts/publish_to_maven_central.sh", project.name, project.version
181+
}
186182
}
187-
return true
188183
}
189184

190-
doLast {
191-
exec {
192-
println "Current working directory: ${project.file('.').absolutePath}"
193-
commandLine 'bash', "../scripts/custom_publish.sh", project.name, project.version
185+
tasks.register('publishToSnapshotRepository') {
186+
if (version.toString().endsWith('SNAPSHOT')) {
187+
dependsOn tasks.publish
188+
}
189+
doFirst {
190+
if (!version.toString().endsWith('SNAPSHOT')) {
191+
throw new GradleException("Version \"" + version +
192+
"\" is a NOT a snapshot. Cannot publish to the snapshot repository")
193+
}
194194
}
195195
}
196196
}

scripts/custom_publish.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

scripts/publish_to_maven_central.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# This script uploads a zip file to Maven Central.
3+
# It expects the current working directory to be the one where the build folder is located (e.h. core)
4+
# This build folder should contain the local-repo folder with the artefacts to be zipped and uploaded.
5+
set -e
6+
7+
subproject=$1
8+
version=$2
9+
10+
echo "Running $(basename $0) for subproject \"$subproject\" and version \"$version\""
11+
echo "Executing in directory = $(pwd)"
12+
13+
zipfile=${subproject}.${version}.zip
14+
15+
pushd build/local-repo
16+
zip -qr ${zipfile} *
17+
18+
bearer_token=$(echo "$MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME:$MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD" | base64)
19+
20+
21+
# Upload to maven central.
22+
# publishingType=USER_MANAGED means that the artefacts will be uploaded and verified, but not yet published.
23+
# See https://central.sonatype.com/publishing/deployments (you need to login as mobilitydata)
24+
# From this page you can examine the list of artefacts, and either drop them or release them.
25+
# If you want to remove that step, use publishingType=AUTOMATIC, that will publish directly.
26+
# Note that once published you cannot remove or alter the artifacts.
27+
answer=$(curl --request POST \
28+
--verbose \
29+
--header "Authorization: Bearer ${bearer_token}" \
30+
--form bundle="@${zipfile}" \
31+
'https://central.sonatype.com/api/v1/publisher/upload?publishingType=USER_MANAGED')
32+
33+
echo "curl request answer: $answer"
34+
35+
popd

0 commit comments

Comments
 (0)