Skip to content

Commit 7c87342

Browse files
committed
extractor: Setup signing for CI snapshots
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
1 parent 4701a17 commit 7c87342

2 files changed

Lines changed: 92 additions & 26 deletions

File tree

.github/workflows/snapshot.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish snapshot
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
8+
jobs:
9+
build-and-deploy-docs:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v6
13+
14+
- name: set up JDK
15+
uses: actions/setup-java@v5
16+
with:
17+
java-version: 21
18+
distribution: 'temurin'
19+
20+
- name: Cache Gradle dependencies
21+
uses: actions/cache@v5
22+
with:
23+
path: ~/.gradle/caches
24+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
25+
restore-keys: ${{ runner.os }}-gradle
26+
27+
- name: Publish snapshot
28+
run: ./gradlew publishSnapshotPublicationToSonatypeRepository

extractor/build.gradle.kts

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
77
import org.gradle.api.tasks.testing.logging.TestLogEvent
88

9+
val ciSigningKey: String? = System.getenv("PGP_PRIVATE_SIGNING_KEY")
10+
val ciSigningPassword: String? = System.getenv("PGP_PRIVATE_SIGNING_KEY_PASSWORD")
11+
val shouldSignRelease: Boolean
12+
get() = !ciSigningKey.isNullOrEmpty() && !ciSigningPassword.isNullOrEmpty()
13+
914
plugins {
1015
alias(libs.plugins.google.protobuf)
1116
checkstyle
1217
`maven-publish`
18+
signing
1319
}
1420

1521
java {
@@ -112,47 +118,79 @@ protobuf {
112118
// Run "./gradlew publishReleasePublicationToLocalRepository" to generate release JARs locally
113119
publishing {
114120
publications {
121+
val mavenGroupId = "net.newpipe"
122+
val mavenArtifactId = "extractor"
123+
fun MavenPublication.setupPOM() = pom {
124+
name = "NewPipe Extractor"
125+
description = "A library for extracting data from streaming websites, used in NewPipe"
126+
url = "https://github.com/TeamNewPipe/NewPipeExtractor"
127+
128+
licenses {
129+
license {
130+
name = "GNU GENERAL PUBLIC LICENSE, Version 3"
131+
url = "https://www.gnu.org/licenses/gpl-3.0.txt"
132+
}
133+
}
134+
135+
scm {
136+
url = "https://github.com/TeamNewPipe/NewPipeExtractor"
137+
connection = "scm:git:git@github.com:TeamNewPipe/NewPipeExtractor.git"
138+
developerConnection = "scm:git:git@github.com:TeamNewPipe/NewPipeExtractor.git"
139+
}
140+
141+
developers {
142+
developer {
143+
id = "newpipe"
144+
name = "Team NewPipe"
145+
email = "team@newpipe.net"
146+
}
147+
}
148+
}
149+
115150
create<MavenPublication>("release") {
116-
groupId = "net.newpipe"
117-
artifactId = "extractor"
151+
groupId = mavenGroupId
152+
artifactId = mavenArtifactId
118153
version = rootProject.version.toString()
119154

120155
afterEvaluate {
121156
from(components["java"])
122157
}
123158

124-
pom {
125-
name = "NewPipe Extractor"
126-
description = "A library for extracting data from streaming websites, used in NewPipe"
127-
url = "https://github.com/TeamNewPipe/NewPipeExtractor"
128-
129-
licenses {
130-
license {
131-
name = "GNU GENERAL PUBLIC LICENSE, Version 3"
132-
url = "https://www.gnu.org/licenses/gpl-3.0.txt"
133-
}
134-
}
135-
136-
scm {
137-
url = "https://github.com/TeamNewPipe/NewPipeExtractor"
138-
connection = "scm:git:git@github.com:TeamNewPipe/NewPipeExtractor.git"
139-
developerConnection = "scm:git:git@github.com:TeamNewPipe/NewPipeExtractor.git"
140-
}
159+
setupPOM()
160+
}
161+
create<MavenPublication>("snapshot") {
162+
groupId = mavenGroupId
163+
artifactId = mavenArtifactId
164+
version = "${rootProject.version}-SNAPSHOT"
141165

142-
developers {
143-
developer {
144-
id = "newpipe"
145-
name = "Team NewPipe"
146-
email = "team@newpipe.net"
147-
}
148-
}
166+
afterEvaluate {
167+
from(components["java"])
149168
}
169+
170+
setupPOM()
150171
}
151172
repositories {
173+
maven {
174+
name = "sonatype"
175+
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
176+
credentials {
177+
username = System.getenv("SONATYPE_MAVEN_CENTRAL_USERNAME")
178+
password = System.getenv("SONATYPE_MAVEN_CENTRAL_PASSWORD")
179+
}
180+
}
152181
maven {
153182
name = "local"
154183
url = uri(layout.buildDirectory.dir("maven"))
155184
}
156185
}
157186
}
158187
}
188+
189+
signing {
190+
useInMemoryPgpKeys(ciSigningKey, ciSigningPassword)
191+
sign(publishing.publications["snapshot"])
192+
}
193+
194+
tasks.withType<Sign> {
195+
onlyIf("Signing credentials are present (only used for maven central)") { shouldSignRelease }
196+
}

0 commit comments

Comments
 (0)