Skip to content

Commit 862260e

Browse files
staging to maven central
1 parent 44cf301 commit 862260e

File tree

3 files changed

+38
-100
lines changed

3 files changed

+38
-100
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ jobs:
8888
env:
8989
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.MAVENCENTRAL_SIGNINGKEY }}
9090
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.MAVENCENTRAL_SIGNINGPASS }}
91-
ORG_GRADLE_PROJECT_user: ${{ github.actor == 'sebastian-peter' && secrets.MAVENCENTRAL_USER ||
91+
ORG_GRADLE_PROJECT_mavencental_user: ${{ github.actor == 'sebastian-peter' && secrets.MAVENCENTRAL_USER ||
9292
github.actor == 'danielfeismann' && secrets.MAVENCENTRAL_TEST_USER }}
93-
ORG_GRADLE_PROJECT_password: ${{ github.actor == 'sebastian-peter' && secrets.MAVENCENTRAL_PASS ||
93+
ORG_GRADLE_PROJECT_mavencentral_password: ${{ github.actor == 'sebastian-peter' && secrets.MAVENCENTRAL_PASS ||
9494
github.actor == 'danielfeismann' && secrets.MAVENCENTRAL_TEST_PASS }}
9595

9696
run: |
@@ -103,4 +103,19 @@ jobs:
103103
104104
echo "currentVersion=$currentVersion"
105105
106-
./gradlew uploadToMavenCentralPortal
106+
./gradlew publish -PdeployVersion=$currentVersion
107+
108+
109+
#MavenCentral Staging
110+
- name: MavenCentral Staging
111+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
112+
env:
113+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.MAVENCENTRAL_SIGNINGKEY }}
114+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.MAVENCENTRAL_SIGNINGPASS }}
115+
ORG_GRADLE_PROJECT_mavenCentalUser: ${{ github.actor == 'sebastian-peter' && secrets.MAVENCENTRAL_USER ||
116+
github.actor == 'danielfeismann' && secrets.MAVENCENTRAL_TEST_USER }}
117+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ github.actor == 'sebastian-peter' && secrets.MAVENCENTRAL_PASS ||
118+
github.actor == 'danielfeismann' && secrets.MAVENCENTRAL_TEST_PASS }}
119+
120+
run: |
121+
./gradlew stagingAtMavenCentralPortal

gradle/scripts/deploy.gradle

Lines changed: 15 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,36 @@
1-
publishing {
2-
publications {
3-
mavenJava(MavenPublication) {
4-
from components.java
5-
pom {
6-
description = 'Elaborated data model to model energy systems with a high granularity @ the Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3) @ TU Dortmund University'
7-
name = 'Power System Data Model'
8-
url = 'https://github.com/ie3-institute/PowerSystemDatamodel'
9-
organization {
10-
name = 'Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University'
11-
url = 'https://www.ie3.tu-dortmund.de/'
12-
}
13-
issueManagement {
14-
system = 'GitHub'
15-
url = 'https://github.com/ie3-institute/PowerSystemDataModel/issues'
16-
}
17-
licenses {
18-
license {
19-
name = 'BSD 3-Clause License'
20-
url = 'https://github.com/ie3-institute/PowerSystemDataModel/blob/master/LICENSE'
21-
}
22-
}
23-
developers {
24-
developer {
25-
organization = "Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University"
26-
organizationUrl = "https://ie3.etit.tu-dortmund.de"
27-
}
28-
}
29-
scm {
30-
connection = 'scm:git:git://github.com/ie3-institute/PowerSystemDataModel.git'
31-
developerConnection = 'scm:git:ssh://github.com:ie3-institute/PowerSystemDataModel.git'
32-
url = 'https://github.com/ie3-institute/PowerSystemDataModel'
33-
}
34-
}
35-
}
36-
}
37-
38-
tasks.register("generatePom", GenerateMavenPom) {
39-
destination = file("${layout.buildDirectory}/libs/pom.xml")
40-
pom = publishing.publications.mavenJava.pom
41-
}
42-
}
43-
44-
tasks.register('uploadToMavenCentralPortal') {
1+
tasks.register('stagingAtMavenCentralPortal') {
452
group = 'publishing'
463
description = 'Upload artifacts to Maven Central Portal for manual approval'
474

48-
dependsOn "generatePom"
49-
505
doLast {
51-
def username = System.getenv('ORG_GRADLE_PROJECT_user')
52-
def password = System.getenv('ORG_GRADLE_PROJECT_password')
6+
def username = project.getProperty('mavenCentralUser')
7+
def password = project.getProperty('mavenCentralPassword')
538
def deployVersion = project.findProperty('deployVersion') ?: project.version
549

5510
if (!username || !password) {
5611
throw new GradleException("Sonatype credentials not found. Set sonatypeUser and sonatypePassword properties or environment variables.")
5712
}
5813

59-
// Create bundle directory
60-
def bundleDir = layout.buildDirectory.dir("central-portal-bundle").get().asFile
61-
def artifactPath = "${group.toString().replace('.', '/')}/${project.name}/${deployVersion}"
62-
def bundleArtifactDir = new File(bundleDir, artifactPath)
63-
64-
bundleDir.deleteDir()
65-
bundleArtifactDir.mkdirs()
66-
67-
// Copy artifacts from build/libs using the correct filename
68-
def localJarPath = file("${layout.buildDirectory}/libs/${project.name}-${deployVersion}.jar")
69-
70-
if (!localJarPath.exists()) {
71-
throw new GradleException("Artifacts not found in build/libs: ${localJarPath}")
72-
}
73-
74-
copy {
75-
from localJarPath
76-
into bundleArtifactDir
77-
}
78-
79-
//Copy generated POM file into the bundle directory
80-
copy {
81-
from layout.buildDirectory.file("pom.xml")
82-
into bundleArtifactDir
83-
}
84-
85-
// Create tar.gz bundle including both JAR and POM files
86-
def bundleFile = layout.buildDirectory.file("${project.name}-${deployVersion}-bundle.tar.gz").get().asFile
87-
88-
exec {
89-
workingDir bundleDir
90-
commandLine 'tar', '-czf', bundleFile.absolutePath, '.'
91-
}
14+
// Request API for repo key
15+
def repositoryString = providers.exec {
16+
commandLine 'curl',
17+
'-u', "${username}:${password}",
18+
'https://ossrh-staging-api.central.sonatype.com/manual/search/repositories'
19+
}.getStandardOutput().getAsText().get()
9220

93-
println "Created bundle: ${bundleFile}"
94-
println "Bundle size: ${bundleFile.length()} bytes"
21+
def getRepositoryGroovy = new groovy.json.JsonSlurper().parseText(repositoryString)
9522

23+
def key = getRepositoryGroovy.repositories[0].key
9624

9725
// Upload via curl
98-
def uploadResult = exec {
26+
def stageResult = providers.exec {
9927
ignoreExitValue true
100-
commandLine 'curl', '-s', '-w', '\n%{http_code}',
101-
'-X', 'POST',
102-
'-H', 'Content-Type: multipart/form-data',
103-
'-F', "bundle=@${bundleFile.absolutePath}",
104-
'-F', 'publishingType=USER_MANAGED',
28+
commandLine 'curl',
10529
'-u', "${username}:${password}",
106-
'https://central.sonatype.com/api/v1/publisher/upload'
30+
'-i', '-X', 'POST', "https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/$key"
10731
}
10832

109-
if (uploadResult.exitValue == 0) {
33+
if (stageResult.result.get().exitValue == 0) {
11034
println "✓ Upload successful!"
11135
println "Check status at: https://central.sonatype.com/publishing/deployments"
11236
} else {

gradle/scripts/mavenCentralPublish.gradle

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tasks.register("javadocJar", Jar) {
1111
from { tasks.named("javadoc", Javadoc).get().destinationDir }
1212
}
1313

14-
if (project.hasProperty('user') && project.hasProperty('password') && project.hasProperty('deployVersion')) {
14+
if (project.hasProperty('mavenCentralUser') && project.hasProperty('mavenCentralPassword') && project.hasProperty('deployVersion')) {
1515

1616
// snapshot version differs from normal version
1717
String versionString = project.getProperty('deployVersion')
@@ -72,12 +72,11 @@ if (project.hasProperty('user') && project.hasProperty('password') && project.ha
7272
}
7373
repositories {
7474
maven {
75-
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
76-
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
77-
url = versionString.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
75+
name = "MavenCentral"
76+
url = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
7877
credentials {
79-
username project.getProperty('user')
80-
password project.getProperty('password')
78+
username = project.findProperty('mavenCentralUser')
79+
password = project.findProperty('mavenCentralPassword')
8180
}
8281
}
8382
}

0 commit comments

Comments
 (0)