Skip to content

Commit a990ba9

Browse files
author
Lucas Mathis
committed
ci: consolidate CI jobs
1 parent bd2599d commit a990ba9

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ test_examples_manual:
212212
- build_manual
213213
script:
214214
- ./gradlew publish
215+
# Trigger deployment from same IP to ensure Sonatype can find the staging repository
216+
- ./gradlew triggerDeployment
215217

216218
publish:
217219
extends: .publish_base
@@ -222,33 +224,6 @@ publish_manual:
222224
extends: .publish_base
223225
when: manual
224226

225-
## trigger deployment
226-
227-
.trigger_deployment_base:
228-
extends: .publish
229-
stage: publish
230-
image: curlimages/curl:8.14.1
231-
script:
232-
- NAMESPACE="com.deepl.api"
233-
- URL="https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/$NAMESPACE"
234-
- PARAMS="publishing_type=automatic"
235-
- BEARER_TOKEN=$(echo "${ORG_GRADLE_PROJECT_mavenUploadUsername}:${ORG_GRADLE_PROJECT_mavenUploadPassword}" | base64)
236-
- |
237-
curl "$URL?$PARAMS" --header "Authorization: Bearer $BEARER_TOKEN" -d "" --write-out "%{http_code}\n"
238-
239-
trigger_deployment:
240-
extends: .trigger_deployment_base
241-
dependencies:
242-
- publish
243-
rules:
244-
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
245-
246-
trigger_deployment_manual:
247-
extends: .trigger_deployment_base
248-
dependencies:
249-
- publish_manual
250-
when: manual
251-
252227
## gitlab release
253228

254229
gitlab release:

deepl-java/build.gradle.kts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import java.net.HttpURLConnection
2+
import java.net.URL
3+
import java.util.Base64
4+
15
plugins {
26
`java-library`
37
`maven-publish`
@@ -124,3 +128,35 @@ signing {
124128
sign(publishing.publications["mavenJava"])
125129
}
126130

131+
tasks.register("triggerDeployment") {
132+
doLast {
133+
val mavenUploadUsername: String? by project
134+
val mavenUploadPassword: String? by project
135+
val namespace = "com.deepl.api"
136+
val url = "https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/$namespace?publishing_type=automatic"
137+
138+
val credentials = "$mavenUploadUsername:$mavenUploadPassword"
139+
val encodedCredentials = Base64.getEncoder().encodeToString(credentials.toByteArray())
140+
141+
val connection = URL(url).openConnection() as HttpURLConnection
142+
connection.requestMethod = "POST"
143+
connection.setRequestProperty("Authorization", "Bearer $encodedCredentials")
144+
connection.doOutput = true
145+
connection.outputStream.write(byteArrayOf())
146+
147+
val responseCode = connection.responseCode
148+
val response = if (responseCode == 200) {
149+
connection.inputStream.bufferedReader().readText()
150+
} else {
151+
connection.errorStream.bufferedReader().readText()
152+
}
153+
154+
println(response)
155+
println("HTTP Status: $responseCode")
156+
157+
if (responseCode != 200) {
158+
throw GradleException("Failed to trigger deployment: $responseCode - $response")
159+
}
160+
}
161+
}
162+

0 commit comments

Comments
 (0)