Skip to content

Commit 96942fa

Browse files
committed
Determine release body in value source to not CC-cache it
1 parent 06616b4 commit 96942fa

3 files changed

Lines changed: 180 additions & 92 deletions

File tree

gradle/build-logic/src/main/kotlin/net/kautler/publishing.gradle.kts

Lines changed: 15 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ package net.kautler
1818

1919
import io.github.gradlenexus.publishplugin.AbstractNexusStagingRepositoryTask
2020
import io.github.gradlenexus.publishplugin.RetrieveStagingProfile
21+
import net.kautler.util.InitJGit
2122
import net.kautler.util.ProblemsProvider
2223
import net.kautler.util.Property.Companion.boolean
2324
import net.kautler.util.Property.Companion.optionalString
25+
import net.kautler.util.ReleaseBody
2426
import net.kautler.util.afterReleaseBuild
2527
import net.kautler.util.beforeReleaseBuild
2628
import net.kautler.util.cachedProvider
@@ -31,23 +33,11 @@ import net.kautler.util.runBuildTasks
3133
import net.kautler.util.updateVersion
3234
import net.kautler.util.verifyPropertyIsSet
3335
import net.researchgate.release.ReleasePlugin
34-
import org.gradle.kotlin.dsl.newInstance
3536
import org.gradle.tooling.GradleConnector
3637
import org.kohsuke.github.GHIssueState.OPEN
3738
import wooga.gradle.github.base.tasks.Github
3839
import wooga.gradle.github.publish.PublishMethod.update
3940
import wooga.gradle.github.publish.tasks.GithubPublish
40-
import java.awt.GraphicsEnvironment.isHeadless
41-
import java.util.concurrent.CompletableFuture
42-
import javax.swing.JButton
43-
import javax.swing.JFrame
44-
import javax.swing.JOptionPane.DEFAULT_OPTION
45-
import javax.swing.JOptionPane.OK_OPTION
46-
import javax.swing.JOptionPane.QUESTION_MESSAGE
47-
import javax.swing.JOptionPane.showOptionDialog
48-
import javax.swing.JScrollPane
49-
import javax.swing.JTextArea
50-
import javax.swing.SwingUtilities
5141

5242
plugins {
5343
java
@@ -210,94 +200,27 @@ configure(listOf(tasks.release, tasks.runBuildTasks)) {
210200
}
211201
}
212202

203+
// work-around for GitHub plugin using JGit without a ValueSource
204+
// in non-configurable property branchName
205+
providers.of(InitJGit::class) {
206+
parameters {
207+
projectDirectory = layout.projectDirectory
208+
}
209+
}.get()
210+
213211
tasks.withType<GithubPublish>().configureEach {
214212
onlyIf("only publish release versions to GitHub") { releaseVersion }
215213
tagName = releaseTagName
216214
releaseName = releaseTagName
217215
}
218216

219217
tasks.githubPublish {
220-
usesService(grgitService.service)
221-
body = provider {
222-
val releaseBody = grgitService
223-
.service
224-
.get()
225-
.findGrgit()
226-
.map {
227-
it
228-
.log {
229-
github
230-
.clientProvider
231-
.get()
232-
.getRepository(github.repositoryName.get())
233-
.latestRelease
234-
?.apply {
235-
excludes.add(tagName)
236-
}
237-
}
238-
.filter { commit ->
239-
!commit.shortMessage.startsWith("[Gradle Release Plugin] ")
240-
}
241-
.asReversed()
242-
.joinToString("\n") { commit ->
243-
"- ${commit.shortMessage} [${commit.id}]"
244-
}
245-
}
246-
.orElse("")
247-
248-
if (isHeadless()) {
249-
return@provider releaseBody
250-
}
251-
252-
val result = CompletableFuture<String>()
253-
254-
SwingUtilities.invokeLater {
255-
val initialReleaseBody = """
256-
# Highlights
257-
-
258-
259-
# Details
260-
261-
""".trimIndent() + releaseBody
262-
263-
val textArea = JTextArea(initialReleaseBody)
264-
265-
val parentFrame = JFrame().apply {
266-
isUndecorated = true
267-
setLocationRelativeTo(null)
268-
isVisible = true
269-
}
270-
271-
val resetButton = JButton("Reset").apply {
272-
addActionListener {
273-
textArea.text = initialReleaseBody
274-
}
275-
}
276-
277-
result.complete(
278-
try {
279-
when (
280-
showOptionDialog(
281-
parentFrame,
282-
JScrollPane(textArea),
283-
"Release Body",
284-
DEFAULT_OPTION,
285-
QUESTION_MESSAGE,
286-
null,
287-
arrayOf("OK", resetButton),
288-
null
289-
)
290-
) {
291-
OK_OPTION -> textArea.text!!
292-
else -> releaseBody
293-
}
294-
} finally {
295-
parentFrame.dispose()
296-
}
297-
)
218+
body = providers.of(ReleaseBody::class) {
219+
parameters {
220+
projectDirectory = layout.projectDirectory
221+
githubToken = github.token
222+
repositoryName = github.repositoryName
298223
}
299-
300-
return@provider result.join()!!
301224
}
302225
draft = true
303226
from(files(commandFramework.map { it.artifacts.map { it.file } }) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2025 Björn Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.kautler.util
18+
19+
import net.kautler.util.InitJGit.Parameters
20+
import org.ajoberstar.grgit.Grgit
21+
import org.gradle.api.file.DirectoryProperty
22+
import org.gradle.api.provider.ValueSource
23+
import org.gradle.api.provider.ValueSourceParameters
24+
25+
abstract class InitJGit : ValueSource<Unit, Parameters> {
26+
override fun obtain() {
27+
runCatching {
28+
Grgit.open {
29+
currentDir = parameters.projectDirectory.get().asFile
30+
}
31+
}
32+
}
33+
34+
interface Parameters : ValueSourceParameters {
35+
val projectDirectory: DirectoryProperty
36+
}
37+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright 2025 Björn Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.kautler.util
18+
19+
import net.kautler.util.ReleaseBody.Parameters
20+
import org.ajoberstar.grgit.Grgit
21+
import org.gradle.api.file.DirectoryProperty
22+
import org.gradle.api.provider.Property
23+
import org.gradle.api.provider.ValueSource
24+
import org.gradle.api.provider.ValueSourceParameters
25+
import org.kohsuke.github.GitHubBuilder
26+
import java.awt.GraphicsEnvironment.isHeadless
27+
import java.util.concurrent.CompletableFuture
28+
import javax.swing.JButton
29+
import javax.swing.JFrame
30+
import javax.swing.JOptionPane.DEFAULT_OPTION
31+
import javax.swing.JOptionPane.OK_OPTION
32+
import javax.swing.JOptionPane.QUESTION_MESSAGE
33+
import javax.swing.JOptionPane.showOptionDialog
34+
import javax.swing.JScrollPane
35+
import javax.swing.JTextArea
36+
import javax.swing.SwingUtilities
37+
38+
abstract class ReleaseBody : ValueSource<String, Parameters> {
39+
override fun obtain(): String {
40+
val releaseBody = runCatching {
41+
Grgit.open {
42+
currentDir = parameters.projectDirectory.get().asFile
43+
}
44+
}
45+
.getOrNull()
46+
?.use {
47+
it
48+
.log {
49+
GitHubBuilder()
50+
.withOAuthToken(parameters.githubToken.get())
51+
.build()
52+
.getRepository(parameters.repositoryName.get())
53+
.latestRelease
54+
?.apply {
55+
excludes.add(tagName)
56+
}
57+
}
58+
.filter { commit ->
59+
!commit.shortMessage.startsWith("[Gradle Release Plugin] ")
60+
}
61+
.asReversed()
62+
.joinToString("\n") { commit ->
63+
"- ${commit.shortMessage} [${commit.id}]"
64+
}
65+
}
66+
?: ""
67+
68+
if (isHeadless()) {
69+
return releaseBody
70+
}
71+
72+
val result = CompletableFuture<String>()
73+
74+
SwingUtilities.invokeLater {
75+
val initialReleaseBody = """
76+
# Highlights
77+
-
78+
79+
# Details
80+
81+
""".trimIndent() + releaseBody
82+
83+
val textArea = JTextArea(initialReleaseBody)
84+
85+
val parentFrame = JFrame().apply {
86+
isUndecorated = true
87+
setLocationRelativeTo(null)
88+
isVisible = true
89+
}
90+
91+
val resetButton = JButton("Reset").apply {
92+
addActionListener {
93+
textArea.text = initialReleaseBody
94+
}
95+
}
96+
97+
result.complete(
98+
try {
99+
when (
100+
showOptionDialog(
101+
parentFrame,
102+
JScrollPane(textArea),
103+
"Release Body",
104+
DEFAULT_OPTION,
105+
QUESTION_MESSAGE,
106+
null,
107+
arrayOf("OK", resetButton),
108+
null
109+
)
110+
) {
111+
OK_OPTION -> textArea.text!!
112+
else -> releaseBody
113+
}
114+
} finally {
115+
parentFrame.dispose()
116+
}
117+
)
118+
}
119+
120+
return result.join()
121+
}
122+
123+
interface Parameters : ValueSourceParameters {
124+
val projectDirectory: DirectoryProperty
125+
val githubToken: Property<String>
126+
val repositoryName: Property<String>
127+
}
128+
}

0 commit comments

Comments
 (0)