Skip to content

Commit 9540b44

Browse files
committed
fix(build): Refactor custom tasks to use tasks.register instead of task("name").
1 parent b11cb0e commit 9540b44

File tree

2 files changed

+126
-121
lines changed

2 files changed

+126
-121
lines changed

buildSrc/src/main/kotlin/publish-conventions.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ plugins {
44
signing
55
}
66

7-
val javadocJar = task("javadocJar", Jar::class) {
7+
val javadocJar = tasks.register("javadocJar", Jar::class, fun Jar.() {
88
archiveClassifier.set("javadoc")
99
from(tasks.javadoc)
10-
}
10+
})
1111

12-
val sourceJar = task("sourceJar", Jar::class) {
12+
val sourceJar = tasks.register("sourceJar", Jar::class, fun Jar.() {
1313
dependsOn(tasks["classes"])
1414
archiveClassifier.set("sources")
1515
from(sourceSets["main"].allSource)
16-
}
16+
})
1717

1818
afterEvaluate {
1919
publishing {

website/build.gradle.kts

Lines changed: 122 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import com.varabyte.kobweb.gradle.application.util.configAsKobwebApplication
22
import com.varabyte.kobwebx.gradle.markdown.children
3+
import groovy.json.JsonSlurper
34
import kotlinx.html.link
45
import kotlinx.html.script
56
import kotlinx.html.unsafe
@@ -8,9 +9,7 @@ import org.commonmark.node.Emphasis
89
import org.commonmark.node.Link
910
import org.commonmark.node.Text
1011
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
11-
import java.net.URL
1212
import java.net.HttpURLConnection
13-
import groovy.json.JsonSlurper
1413
import java.net.URI
1514

1615
plugins {
@@ -230,121 +229,127 @@ kobweb {
230229
}
231230

232231
// Task to fetch GitHub releases and generate Kotlin file
233-
task("fetchGitHubReleases") {
234-
group = "kore"
235-
description = "Fetches GitHub releases and generates a Kotlin file with the data"
236-
237-
val projectDir = projectDir
238-
239-
doLast {
240-
val allReleases = mutableListOf<Map<*, *>>()
241-
var page = 1
242-
var hasMorePages = true
243-
244-
// Fetch all pages of releases
245-
while (hasMorePages) {
246-
val apiUrl = "https://api.github.com/repos/Ayfri/Kore/releases?per_page=100&page=$page"
247-
val connection = URI(apiUrl).toURL().openConnection() as HttpURLConnection
248-
connection.requestMethod = "GET"
249-
connection.setRequestProperty("Accept", "application/vnd.github.v3+json")
250-
251-
// Optional: Add GitHub token if available in environment variables
252-
val githubToken = System.getenv("GITHUB_TOKEN")
253-
if (githubToken != null && githubToken.isNotBlank()) {
254-
connection.setRequestProperty("Authorization", "token $githubToken")
255-
}
256-
257-
val responseCode = connection.responseCode
258-
if (responseCode != 200) {
259-
logger.error("Failed to fetch GitHub releases page $page. Response code: $responseCode")
260-
break
261-
}
262-
263-
val inputStream = connection.inputStream
264-
val jsonResponse = inputStream.bufferedReader().use { it.readText() }
265-
inputStream.close()
266-
267-
val jsonSlurper = JsonSlurper()
268-
val pageReleases = jsonSlurper.parseText(jsonResponse) as List<Map<*, *>>
269-
270-
allReleases.addAll(pageReleases)
271-
272-
// Check if we should continue to the next page
273-
hasMorePages = pageReleases.isNotEmpty() && pageReleases.size == 100
274-
page++
275-
}
276-
277-
// Generate Kotlin file with releases data
278-
val outputDir = File(projectDir, "build/generated/kore/src/jsMain/kotlin/io/github/ayfri/kore/website")
279-
outputDir.mkdirs()
280-
281-
val outputFile = File(outputDir, "gitHubReleases.kt")
282-
outputFile.writeText(buildString {
283-
appendLine("// This file is generated. Do not modify directly.")
284-
appendLine("")
285-
appendLine("package io.github.ayfri.kore.website")
286-
appendLine("")
287-
appendLine("import io.github.ayfri.kore.website.components.updates.GitHubAsset")
288-
appendLine("import io.github.ayfri.kore.website.components.updates.GitHubRelease")
289-
appendLine("")
290-
appendLine("val gitHubReleases = listOf(")
291-
292-
allReleases.forEach { release ->
293-
val id = release["id"] as Number
294-
val name = (release["name"] as String).replace("\"", "\\\"")
295-
val tagName = release["tag_name"] as String
296-
val htmlUrl = release["html_url"] as String
297-
val url = release["url"] as String
298-
val createdAt = release["created_at"] as String
299-
val publishedAt = release["published_at"] as String
300-
val body = (release["body"] as String).replace("\"\"\"", "\\\"\\\"\\\"").replace("$", "\\$")
301-
val isPrerelease = release["prerelease"] as Boolean
302-
303-
val assets = release["assets"] as List<Map<*, *>>
304-
305-
appendLine(" GitHubRelease(")
306-
appendLine(" id = $id,")
307-
appendLine(" name = \"$name\",")
308-
appendLine(" tagName = \"$tagName\",")
309-
appendLine(" htmlUrl = \"$htmlUrl\",")
310-
appendLine(" url = \"$url\",")
311-
appendLine(" createdAt = \"$createdAt\",")
312-
appendLine(" publishedAt = \"$publishedAt\",")
313-
appendLine(" body = \"\"\"$body\"\"\",")
314-
appendLine(" isPrerelease = $isPrerelease,")
315-
316-
if (assets.isNotEmpty()) {
317-
appendLine(" assets = listOf(")
318-
assets.forEach { asset ->
319-
val assetId = asset["id"] as Number
320-
val assetName = (asset["name"] as String).replace("\"", "\\\"")
321-
val browserDownloadUrl = asset["browser_download_url"] as String
322-
val contentType = asset["content_type"] as String
323-
val size = asset["size"] as Number
324-
val downloadCount = asset["download_count"] as Number
325-
326-
appendLine(" GitHubAsset(")
327-
appendLine(" id = $assetId,")
328-
appendLine(" name = \"$assetName\",")
329-
appendLine(" browserDownloadUrl = \"$browserDownloadUrl\",")
330-
appendLine(" contentType = \"$contentType\",")
331-
appendLine(" size = $size,")
332-
appendLine(" downloadCount = $downloadCount")
333-
appendLine(" ),")
334-
}
335-
appendLine(" )")
336-
} else {
337-
appendLine(" assets = emptyList()")
338-
}
339-
340-
appendLine(" ),")
341-
}
342-
343-
appendLine(")")
344-
})
345-
346-
logger.lifecycle("Generated GitHub releases file with ${allReleases.size} releases")
347-
}
232+
// Optional: Add GitHub token if available in environment variables
233+
234+
// Check if we should continue to the next page
235+
236+
// Generate Kotlin file with releases data
237+
// Fetch all pages of releases
238+
tasks.register("fetchGitHubReleases") {
239+
group = "kore"
240+
description = "Fetches GitHub releases and generates a Kotlin file with the data"
241+
242+
val projectDir = projectDir
243+
244+
doLast {
245+
val allReleases = mutableListOf<Map<*, *>>()
246+
var page = 1
247+
var hasMorePages = true
248+
249+
// Fetch all pages of releases
250+
while (hasMorePages) {
251+
val apiUrl = "https://api.github.com/repos/Ayfri/Kore/releases?per_page=100&page=$page"
252+
val connection = URI(apiUrl).toURL().openConnection() as HttpURLConnection
253+
connection.requestMethod = "GET"
254+
connection.setRequestProperty("Accept", "application/vnd.github.v3+json")
255+
256+
// Optional: Add GitHub token if available in environment variables
257+
val githubToken = System.getenv("GITHUB_TOKEN")
258+
if (githubToken != null && githubToken.isNotBlank()) {
259+
connection.setRequestProperty("Authorization", "token $githubToken")
260+
}
261+
262+
val responseCode = connection.responseCode
263+
if (responseCode != 200) {
264+
logger.error("Failed to fetch GitHub releases page $page. Response code: $responseCode")
265+
break
266+
}
267+
268+
val inputStream = connection.inputStream
269+
val jsonResponse = inputStream.bufferedReader().use { it.readText() }
270+
inputStream.close()
271+
272+
val jsonSlurper = JsonSlurper()
273+
val pageReleases = jsonSlurper.parseText(jsonResponse) as List<Map<*, *>>
274+
275+
allReleases.addAll(pageReleases)
276+
277+
// Check if we should continue to the next page
278+
hasMorePages = pageReleases.isNotEmpty() && pageReleases.size == 100
279+
page++
280+
}
281+
282+
// Generate Kotlin file with releases data
283+
val outputDir = File(projectDir, "build/generated/kore/src/jsMain/kotlin/io/github/ayfri/kore/website")
284+
outputDir.mkdirs()
285+
286+
val outputFile = File(outputDir, "gitHubReleases.kt")
287+
outputFile.writeText(buildString {
288+
appendLine("// This file is generated. Do not modify directly.")
289+
appendLine("")
290+
appendLine("package io.github.ayfri.kore.website")
291+
appendLine("")
292+
appendLine("import io.github.ayfri.kore.website.components.updates.GitHubAsset")
293+
appendLine("import io.github.ayfri.kore.website.components.updates.GitHubRelease")
294+
appendLine("")
295+
appendLine("val gitHubReleases = listOf(")
296+
297+
allReleases.forEach { release ->
298+
val id = release["id"] as Number
299+
val name = (release["name"] as String).replace("\"", "\\\"")
300+
val tagName = release["tag_name"] as String
301+
val htmlUrl = release["html_url"] as String
302+
val url = release["url"] as String
303+
val createdAt = release["created_at"] as String
304+
val publishedAt = release["published_at"] as String
305+
val body = (release["body"] as String).replace("\"\"\"", "\\\"\\\"\\\"").replace("$", "\\$")
306+
val isPrerelease = release["prerelease"] as Boolean
307+
308+
val assets = release["assets"] as List<Map<*, *>>
309+
310+
appendLine(" GitHubRelease(")
311+
appendLine(" id = $id,")
312+
appendLine(" name = \"$name\",")
313+
appendLine(" tagName = \"$tagName\",")
314+
appendLine(" htmlUrl = \"$htmlUrl\",")
315+
appendLine(" url = \"$url\",")
316+
appendLine(" createdAt = \"$createdAt\",")
317+
appendLine(" publishedAt = \"$publishedAt\",")
318+
appendLine(" body = \"\"\"$body\"\"\",")
319+
appendLine(" isPrerelease = $isPrerelease,")
320+
321+
if (assets.isNotEmpty()) {
322+
appendLine(" assets = listOf(")
323+
assets.forEach { asset ->
324+
val assetId = asset["id"] as Number
325+
val assetName = (asset["name"] as String).replace("\"", "\\\"")
326+
val browserDownloadUrl = asset["browser_download_url"] as String
327+
val contentType = asset["content_type"] as String
328+
val size = asset["size"] as Number
329+
val downloadCount = asset["download_count"] as Number
330+
331+
appendLine(" GitHubAsset(")
332+
appendLine(" id = $assetId,")
333+
appendLine(" name = \"$assetName\",")
334+
appendLine(" browserDownloadUrl = \"$browserDownloadUrl\",")
335+
appendLine(" contentType = \"$contentType\",")
336+
appendLine(" size = $size,")
337+
appendLine(" downloadCount = $downloadCount")
338+
appendLine(" ),")
339+
}
340+
appendLine(" )")
341+
} else {
342+
appendLine(" assets = emptyList()")
343+
}
344+
345+
appendLine(" ),")
346+
}
347+
348+
appendLine(")")
349+
})
350+
351+
logger.lifecycle("Generated GitHub releases file with ${allReleases.size} releases")
352+
}
348353
}
349354

350355
// Make the kobwebExport task depend on fetchGitHubReleases

0 commit comments

Comments
 (0)