Skip to content

Commit b9496c7

Browse files
authored
Attempts to update release workflow (#20)
Attempts to update release workflow to use new Maven publishing plugin.
1 parent e7740d3 commit b9496c7

File tree

6 files changed

+91
-176
lines changed

6 files changed

+91
-176
lines changed

.github/workflows/Release.yml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,56 @@ on: workflow_dispatch
55
env:
66
TERM: dumb
77

8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
813
jobs:
914
publish:
1015
runs-on: ubuntu-latest
1116

1217
steps:
1318
- name: Checkout the repo
14-
uses: actions/checkout@v2
19+
uses: actions/checkout@v4
1520

16-
- name: Set gradle publish version
21+
- name: Check if tag is on main branch
22+
id: check-branch
1723
run: |
18-
sed --in-place -e "s/-SNAPSHOT/-$(date +%Y%m%d.%H%M)-$(git rev-parse --short HEAD)/" gradle.properties
19-
cat gradle.properties
24+
if git branch -r --contains ${{ github.ref }} | grep -q "origin/main"; then
25+
echo "tag_on_main=true" >> $GITHUB_OUTPUT
26+
else
27+
echo "tag_on_main=false" >> $GITHUB_OUTPUT
28+
fi
29+
30+
- name: Extract version from tag
31+
if: steps.check-branch.outputs.tag_on_main == 'true'
32+
id: version
33+
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
2034

21-
- name: Publish the artifacts
35+
- name: Publish to Maven Central
36+
if: steps.check-branch.outputs.tag_on_main == 'true'
2237
env:
2338
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_CENTRAL_USERNAME }}
2439
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_CENTRAL_PASSWORD }}
2540
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_SECRET_KEY }}
2641
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_SECRET_PASSPHRASE }}
27-
run: bin/gradle clean build publishAllPublicationsToMavenCentralRepository --no-daemon
42+
ORG_GRADLE_PROJECT_VERSION_NAME: ${{ steps.version.outputs.version }}
43+
run: bin/gradle publishToMavenCentral
44+
45+
- name: Build HTML
46+
if: steps.check-branch.outputs.tag_on_main == 'true'
47+
run: bin/gradle dokkaHtmlMultiModule --no-daemon --stacktrace
48+
49+
- name: Upload HTML
50+
if: steps.check-branch.outputs.tag_on_main == 'true'
51+
uses: actions/upload-pages-artifact@v3
52+
with:
53+
path: build/dokka/html
54+
name: 'github-pages'
55+
56+
- name: Deploy GitHub Pages site
57+
if: steps.check-branch.outputs.tag_on_main == 'true'
58+
uses: actions/deploy-pages@v4
59+
with:
60+
artifact_name: github-pages

build.gradle.kts

Lines changed: 30 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,57 @@
1-
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2-
import org.gradle.kotlin.dsl.support.kotlinCompilerOptions
3-
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
4-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
5-
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
61
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
72

8-
plugins {
9-
alias(libs.plugins.kotlinGradlePlugin) apply false
10-
alias(libs.plugins.kotlinBinaryCompatibilityPlugin) apply false
11-
alias(libs.plugins.mavenPublishGradlePlugin) apply false
12-
alias(libs.plugins.versionsGradlePlugin)
13-
alias(libs.plugins.versionCatalogUpdateGradlePlugin)
14-
alias(libs.plugins.dokka)
15-
}
16-
173
repositories {
184
mavenCentral()
19-
gradlePluginPortal()
205
}
216

22-
buildscript {
23-
repositories {
24-
mavenCentral()
25-
}
7+
plugins {
8+
alias(libs.plugins.kotlinGradlePlugin) apply false
9+
alias(libs.plugins.dokka)
10+
alias(libs.plugins.versionsGradlePlugin)
11+
alias(libs.plugins.versionCatalogUpdateGradlePlugin)
12+
alias(libs.plugins.kotlinBinaryCompatibilityPlugin) apply false
2613
}
2714

2815
subprojects {
29-
buildscript {
30-
repositories {
31-
mavenCentral()
32-
gradlePluginPortal()
33-
}
34-
}
35-
36-
repositories {
37-
mavenCentral()
38-
}
16+
apply(plugin = "org.jetbrains.dokka")
3917

40-
apply(plugin = "java")
41-
apply(plugin = "kotlin")
42-
apply(plugin = rootProject.project.libs.plugins.kotlinBinaryCompatibilityPlugin.get().pluginId)
43-
apply(plugin = rootProject.project.libs.plugins.mavenPublishGradlePlugin.get().pluginId)
44-
45-
configure<JavaPluginExtension> {
46-
withSourcesJar()
47-
withJavadocJar()
48-
}
49-
50-
plugins.withId("com.vanniktech.maven.publish.base") {
51-
val publishingExtension = extensions.getByType(PublishingExtension::class.java)
52-
configure<com.vanniktech.maven.publish.MavenPublishBaseExtension> {
53-
pomFromGradleProperties()
54-
publishToMavenCentral(com.vanniktech.maven.publish.SonatypeHost.DEFAULT, true)
55-
signAllPublications()
56-
}
57-
58-
publishingExtension.publications.create<MavenPublication>("maven") {
59-
from(components["java"])
60-
}
61-
}
62-
63-
apply(plugin = "version-catalog")
64-
65-
// Only apply if the project has the kotlin plugin added:
66-
tasks.withType<KotlinJvmCompile>().configureEach {
18+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
6719
compilerOptions {
68-
jvmTarget.set(JvmTarget.JVM_17)
69-
allWarningsAsErrors.set(true)
70-
}
71-
}
72-
73-
plugins.withType<KotlinPluginWrapper> {
74-
tasks.withType<GenerateModuleMetadata> {
75-
suppressedValidationErrors.add("enforced-platform")
76-
}
77-
78-
dependencies {
79-
add("testImplementation", project.rootProject.libs.junitApi)
80-
add("testRuntimeOnly", project.rootProject.libs.junitEngine)
20+
jvmTarget.set(JvmTarget.JVM_11)
8121
}
8222
}
8323

8424
tasks.withType<Test> {
85-
dependsOn("apiCheck")
8625
useJUnitPlatform()
87-
testLogging {
88-
events("started", "passed", "skipped", "failed")
89-
exceptionFormat = TestExceptionFormat.FULL
90-
showStandardStreams = false
91-
}
9226
}
9327

94-
apply(plugin = "com.github.ben-manes.versions")
95-
96-
tasks.withType<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask> {
97-
revision = "release"
98-
resolutionStrategy {
99-
componentSelection {
100-
all {
101-
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
102-
reject("Release candidate")
103-
}
28+
// Configure Dokka for each subproject
29+
tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
30+
dokkaSourceSets {
31+
named("main") {
32+
includes.from("module.md")
33+
moduleName.set(project.name)
34+
sourceLink {
35+
localDirectory.set(file("src/main/kotlin"))
36+
remoteUrl.set(uri("https://github.com/block/ln-invoice/tree/main/${project.name}/src/main/kotlin").toURL())
37+
remoteLineSuffix.set("#L")
10438
}
10539
}
10640
}
10741
}
10842
}
10943

110-
fun isNonStable(version: String): Boolean {
111-
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
112-
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
113-
val isStable = stableKeyword || regex.matches(version)
114-
return isStable.not()
115-
}
116-
117-
// this needs to be defined here for the versionCatalogUpdate
118-
tasks.withType<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask> {
119-
revision = "release"
120-
resolutionStrategy {
121-
componentSelection {
122-
all {
123-
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
124-
reject("Release candidate")
125-
}
126-
}
127-
}
128-
}
44+
// Configure Dokka multi-module task
45+
tasks.dokkaHtmlMultiModule {
46+
outputDirectory.set(layout.buildDirectory.dir("dokka/html"))
47+
includes.from("dokka-docs/module.md")
48+
moduleName.set("ln-invoice")
49+
moduleVersion.set(project.version.toString())
12950
}
13051

131-
versionCatalogUpdate {
132-
/**
133-
* Use @pin and @keep in gradle/lib.versions.toml instead of defining here
134-
*/
135-
sortByKey.set(true)
52+
tasks.register("publishToMavenCentral") {
53+
group = "publishing"
54+
dependsOn(
55+
":lib:publishToMavenCentral",
56+
)
13657
}

gradle-mvn-publish.gradle

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

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ POM_LICENCE_DIST=repo
1010
POM_DEVELOPER_ID=square
1111
POM_DEVELOPER_NAME=Square, Inc.
1212

13-
SONATYPE_HOST=DEFAULT
13+
SONATYPE_HOST=CENTRAL_PORTAL
1414
RELEASE_SIGNING_ENABLED=true

gradle/libs.versions.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ kotestArrow = "2.0.0"
99
# @pin
1010
kotlin = "2.1.20"
1111
kotlinBinaryCompatibilityPlugin = "0.17.0"
12-
mavenPublishGradlePlugin = "0.27.0"
12+
mavenPublish = "0.33.0"
1313
okio = "3.4.0"
1414
quiver = "1.0.0"
1515
slf4j = "2.0.17"
@@ -33,6 +33,7 @@ okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
3333
quiver = { module = "app.cash.quiver:lib", version.ref = "quiver" }
3434
slf4jApi = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
3535
slf4jSimple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }
36+
mavenPublishGradlePlugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "mavenPublish" }
3637

3738
[bundles]
3839
kotest = [
@@ -46,6 +47,6 @@ kotest = [
4647
dokka = "org.jetbrains.dokka:2.0.0"
4748
kotlinBinaryCompatibilityPlugin = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinBinaryCompatibilityPlugin" }
4849
kotlinGradlePlugin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
49-
mavenPublishGradlePlugin = { id = "com.vanniktech.maven.publish.base", version.ref = "mavenPublishGradlePlugin" }
50+
mavenPublish = { id = "com.vanniktech.maven.publish.base", version.ref = "mavenPublish" }
5051
versionCatalogUpdateGradlePlugin = { id = "nl.littlerobots.version-catalog-update", version.ref = "versionCatalogUpdateGradlePlugin" }
5152
versionsGradlePlugin = { id = "com.github.ben-manes.versions", version.ref = "versionsGradlePlugin" }

lib/build.gradle.kts

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
import org.jetbrains.dokka.gradle.DokkaTask
2-
import java.net.URL
3-
41
plugins {
5-
`java-library`
2+
id("java-library")
3+
id("org.jetbrains.kotlin.jvm")
4+
id("com.vanniktech.maven.publish") version "0.33.0"
5+
}
6+
7+
repositories {
8+
mavenCentral()
9+
}
10+
11+
java {
12+
toolchain {
13+
languageVersion.set(JavaLanguageVersion.of(11))
14+
}
15+
withSourcesJar()
16+
}
17+
18+
mavenPublishing {
19+
configure(com.vanniktech.maven.publish.KotlinJvm())
620
}
721

822
dependencies {
@@ -24,29 +38,4 @@ dependencies {
2438

2539
testRuntimeOnly(libs.junitEngine)
2640
testRuntimeOnly(libs.slf4jSimple)
27-
28-
apply(plugin = libs.plugins.dokka.get().pluginId)
2941
}
30-
31-
tasks.withType<Test>().configureEach {
32-
useJUnitPlatform()
33-
}
34-
35-
tasks.withType<DokkaTask>().configureEach {
36-
dokkaSourceSets {
37-
named("main") {
38-
moduleName.set("LN-Invoice")
39-
40-
// Includes custom documentation
41-
includes.from("module.md")
42-
43-
// Points source links to GitHub
44-
sourceLink {
45-
localDirectory.set(file("src/main/kotlin"))
46-
remoteUrl.set(URL("https://github.com/cashapp/ln-invoice/tree/master/lib/src/main/kotlin"))
47-
remoteLineSuffix.set("#L")
48-
}
49-
}
50-
}
51-
}
52-

0 commit comments

Comments
 (0)