Skip to content

Commit 66d9ee1

Browse files
committed
extractor: Setup signing for CI snapshots
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
1 parent 504d099 commit 66d9ee1

3 files changed

Lines changed: 127 additions & 26 deletions

File tree

.github/workflows/snapshot.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Publish snapshot
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
- snapshot
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-and-deploy-docs:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v6
15+
16+
- name: set up JDK
17+
uses: actions/setup-java@v5
18+
with:
19+
java-version: 21
20+
distribution: 'temurin'
21+
22+
- name: Cache Gradle dependencies
23+
uses: actions/cache@v5
24+
with:
25+
path: ~/.gradle/caches
26+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
27+
restore-keys: ${{ runner.os }}-gradle
28+
29+
- name: Publish snapshot
30+
env:
31+
PGP_PRIVATE_SIGNING_KEY: ${{ secrets.PGP_PRIVATE_SIGNING_KEY }}
32+
PGP_PRIVATE_SIGNING_KEY_PASSWORD: ${{ secrets.PGP_PRIVATE_SIGNING_KEY_PASSWORD }}
33+
SONATYPE_MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_MAVEN_CENTRAL_USERNAME }}
34+
SONATYPE_MAVEN_CENTRAL_PASSWORD: ${{ secrets.SONATYPE_MAVEN_CENTRAL_PASSWORD }}
35+
run: ./gradlew publishSnapshotPublicationToSonatypeRepository
36+
37+
- name: Upload metadata
38+
uses: actions/upload-artifact@v6
39+
with:
40+
name: NewPipeExtractor-Snapshot
41+
path: extractor/build/publications/snapshot/**

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ If you're using Gradle, you could add NewPipe Extractor as a dependency with the
2525
2626
### Testing changes
2727

28+
#### Maven Central
29+
30+
NewPipe Extractor's snapshots are available on Maven Central's snapshot repository. These versions
31+
are based on the commit's short hash (for e.g. `git rev-parse --short HEAD`) and are available for
32+
90 days since the date of publication/commit.
33+
34+
```kotlin
35+
repositories {
36+
maven(url = "https://central.sonatype.com/repository/maven-snapshots/")
37+
}
38+
39+
dependencies {
40+
implementation("net.newpipe:extractor:${LAST_COMMIT_SHORT_HASH}-SNAPSHOT")
41+
}
42+
```
43+
44+
#### Local
45+
2846
To test changes quickly you can build the library locally. A good approach would be to add something like the following to your `settings.gradle`:
2947

3048
```groovy

extractor/build.gradle.kts

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@
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 shouldSignCIRelease: Boolean
12+
get() = !ciSigningKey.isNullOrEmpty() && !ciSigningPassword.isNullOrEmpty()
13+
14+
val lastCommitHash: String = providers.exec {
15+
commandLine("git", "rev-parse", "--short", "HEAD")
16+
}.standardOutput.asText.map { it.trim() }.get()
17+
918
plugins {
1019
alias(libs.plugins.google.protobuf)
1120
checkstyle
1221
`maven-publish`
22+
signing
1323
}
1424

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

120159
afterEvaluate {
121160
from(components["java"])
122161
}
123162

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-
}
163+
setupPOM()
164+
}
165+
create<MavenPublication>("snapshot") {
166+
groupId = mavenGroupId
167+
artifactId = mavenArtifactId
168+
version = "$lastCommitHash-SNAPSHOT"
141169

142-
developers {
143-
developer {
144-
id = "newpipe"
145-
name = "Team NewPipe"
146-
email = "team@newpipe.net"
147-
}
148-
}
170+
afterEvaluate {
171+
from(components["java"])
149172
}
173+
174+
setupPOM()
150175
}
151176
repositories {
177+
maven {
178+
name = "sonatype"
179+
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
180+
credentials {
181+
username = System.getenv("SONATYPE_MAVEN_CENTRAL_USERNAME")
182+
password = System.getenv("SONATYPE_MAVEN_CENTRAL_PASSWORD")
183+
}
184+
}
152185
maven {
153186
name = "local"
154187
url = uri(layout.buildDirectory.dir("maven"))
155188
}
156189
}
157190
}
158191
}
192+
193+
signing {
194+
useInMemoryPgpKeys(ciSigningKey, ciSigningPassword)
195+
sign(publishing.publications["snapshot"])
196+
}
197+
198+
tasks.withType<Sign> {
199+
onlyIf("Signing credentials are present (only used for maven central)") { shouldSignCIRelease }
200+
}

0 commit comments

Comments
 (0)