Skip to content

Commit

Permalink
feat: migrate to kotlin-wrappers:kotlin-actions-toolkit
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Feb 18, 2023
1 parent 535a7ac commit ef8873f
Show file tree
Hide file tree
Showing 59 changed files with 79 additions and 971 deletions.
3 changes: 1 addition & 2 deletions cache-action-entrypoint/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ dependencies {
implementation(project(":cache-proxy"))
implementation(project(":gradle-launcher"))
implementation(project(":layered-cache"))
implementation(project(":wrappers:actions-core"))
implementation(project(":wrappers:actions-io"))
implementation(project(":wrappers:actions-toolkit"))
implementation(project(":wrappers:nodejs"))
implementation(project(":wrappers:octokit-webhooks"))
implementation(npm("string-argv", "0.3.1"))
Expand Down
4 changes: 2 additions & 2 deletions cache-action-entrypoint/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import com.github.burrunan.launcher.install
import com.github.burrunan.launcher.launchGradle
import com.github.burrunan.launcher.resolveDistribution
import com.github.burrunan.wrappers.nodejs.normalizedPath
import kotlinx.js.globalThis
import kotlinx.js.set
import js.core.globalThis
import js.core.set
import node.fs.writeFile
import octokit.currentTrigger
import node.path.path
Expand Down
4 changes: 1 addition & 3 deletions cache-proxy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import org.jetbrains.kotlin.gradle.targets.js.testing.mocha.KotlinMocha
dependencies {
implementation(project(":cache-service-mock"))
implementation(project(":wrappers:actions-cache"))
implementation(project(":wrappers:actions-core"))
implementation(project(":wrappers:actions-exec"))
implementation(project(":wrappers:actions-glob"))
implementation(project(":wrappers:actions-toolkit"))
implementation(project(":wrappers:nodejs"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import node.http.ServerResponse
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.await
import kotlinx.coroutines.launch
import kotlinx.js.jso
import kotlinx.js.set
import js.core.jso
import js.core.set
import node.fs.Stats
import node.fs.stat
import node.http.OutgoingHttpHeaders
Expand All @@ -52,7 +52,7 @@ class CacheProxy {

val cacheUrl: String? get() = _cacheUrl

private val server = node.http.createServer { req, res ->
private val server = node.http.createServer<IncomingMessage, ServerResponse<*>> { req, res ->
val query = node.url.parse(req.url!!, true)
val path = query.pathname ?: ""
res.handle {
Expand All @@ -67,7 +67,7 @@ class CacheProxy {

private val compression = jso<InternalCacheOptions> { compressionMethod = CompressionMethod.Gzip }

private suspend fun putEntry(id: String, req: IncomingMessage, res: ServerResponse) {
private suspend fun putEntry(id: String, req: IncomingMessage, res: ServerResponse<*>) {
val fileName = path.join(TEMP_DIR, "bc-$id")
try {
req.pipeAndWait(createWriteStream(fileName))
Expand Down Expand Up @@ -95,7 +95,7 @@ class CacheProxy {
}
}

private suspend fun getEntry(id: String, res: ServerResponse) {
private suspend fun getEntry(id: String, res: ServerResponse<*>) {
val cacheEntry = getCacheEntry(arrayOf(id), arrayOf(id), compression).await()
?: throw HttpException.notFound("No cache entry found for $id")
val archiveLocation = cacheEntry.archiveLocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import actions.glob.removeFiles
import com.github.burrunan.gradle.cache.CacheService
import com.github.burrunan.test.runTest
import com.github.burrunan.wrappers.nodejs.mkdir
import kotlinx.js.get
import js.core.get
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.encodeToDynamic
import node.fs.copyFile
Expand Down
2 changes: 1 addition & 1 deletion cache-service-mock/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

dependencies {
implementation(project(":wrappers:actions-cache"))
implementation(project(":wrappers:actions-core"))
implementation(project(":wrappers:actions-toolkit"))
implementation(project(":wrappers:nodejs"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import com.github.burrunan.wrappers.js.suspendWithCallback
import com.github.burrunan.wrappers.nodejs.exists
import com.github.burrunan.wrappers.nodejs.readJson
import com.github.burrunan.wrappers.nodejs.readToBuffer
import kotlinx.js.get
import kotlinx.js.jso
import kotlinx.js.set
import js.core.get
import js.core.jso
import js.core.set
import node.http.IncomingMessage
import node.http.OutgoingHttpHeaders
import node.http.ServerResponse
Expand All @@ -41,7 +41,7 @@ class CacheService {

private val storage = CacheStorage()

private val server = node.http.createServer { req, res ->
private val server = node.http.createServer<IncomingMessage, ServerResponse<*>> { req, res ->
val query = node.url.parse(req.url!!, true)
val path = query.pathname ?: ""
res.handle {
Expand All @@ -59,7 +59,7 @@ class CacheService {
}
}

private fun getContents(query: Url, res: ServerResponse) {
private fun getContents(query: Url, res: ServerResponse<*>) {
val key = query.query.unsafeCast<ParsedUrlQuery>()["key"] as String
val entry = storage.getValue(key)
res.writeHead(
Expand All @@ -71,13 +71,13 @@ class CacheService {
res.write(entry.value)
}

private suspend fun cacheOp(cacheId: Number, req: IncomingMessage, res: ServerResponse) = when (req.method) {
private suspend fun cacheOp(cacheId: Number, req: IncomingMessage, res: ServerResponse<*>) = when (req.method) {
"PATCH" -> uploadCache(cacheId, req, res)
"POST" -> commitCache(cacheId, req, res)
else -> throw HttpException.notImplemented("Unknown method: ${req.method}")
}

private fun getCache(query: Url, res: ServerResponse) {
private fun getCache(query: Url, res: ServerResponse<*>) {
val request = query.query.unsafeCast<GetCacheParams>()
var resultKey: String? = null
var resultEntry: CacheEntry? = null
Expand Down Expand Up @@ -114,7 +114,7 @@ class CacheService {
)
}

private suspend fun uploadCache(cacheId: Number, req: IncomingMessage, res: ServerResponse) {
private suspend fun uploadCache(cacheId: Number, req: IncomingMessage, res: ServerResponse<*>) {
val contentRange = req.headers.asDynamic()["content-range"] as String
val (_, start, end) = contentRange.match("bytes (\\d+)-(\\d+)") ?: arrayOf("", "", "")
if (start.isEmpty()) {
Expand All @@ -124,12 +124,12 @@ class CacheService {
res.writeHead(200, "OK")
}

private suspend fun commitCache(cacheId: Number, req: IncomingMessage, res: ServerResponse) {
private suspend fun commitCache(cacheId: Number, req: IncomingMessage, res: ServerResponse<*>) {
storage.commitCache(cacheId, req.readJson<CommitCacheRequest>().size)
res.writeHead(200, "OK")
}

private suspend fun reserveCache(req: IncomingMessage, res: ServerResponse) {
private suspend fun reserveCache(req: IncomingMessage, res: ServerResponse<*>) {
if (req.method != "POST") {
throw HttpException.badRequest("Expecting POST method, got ${req.method}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope

fun ServerResponse.handle(action: suspend CoroutineScope.() -> Unit) =
fun ServerResponse<*>.handle(action: suspend CoroutineScope.() -> Unit) =
GlobalScope.launch {
try {
supervisorScope {
Expand Down
6 changes: 1 addition & 5 deletions gradle-launcher/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

dependencies {
implementation(project(":hashing"))
implementation(project(":wrappers:actions-core"))
implementation(project(":wrappers:actions-exec"))
implementation(project(":wrappers:actions-http-client"))
implementation(project(":wrappers:actions-io"))
implementation(project(":wrappers:actions-tool-cache"))
implementation(project(":wrappers:actions-toolkit"))
implementation(project(":wrappers:java-properties"))
implementation(project(":wrappers:nodejs"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,26 @@ package com.github.burrunan.launcher
import actions.core.ActionFailedException
import actions.core.info
import actions.core.warning
import actions.httpclient.HttpClient
import actions.httpclient.HttpCodes
import actions.httpclient.IHeaders
import actions.http.client.HttpClient
import actions.http.client.HttpCodes
import actions.io.rmRF
import actions.toolcache.cacheDir
import actions.toolcache.downloadTool
import actions.toolcache.extractZip
import actions.tool.cache.cacheDir
import actions.tool.cache.downloadTool
import actions.tool.cache.extractZip
import com.github.burrunan.hashing.hashFiles
import com.github.burrunan.wrappers.nodejs.exists
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.await
import kotlinx.coroutines.launch
import kotlinx.js.jso
import js.core.recordOf
import node.buffer.BufferEncoding
import node.fs.Mode
import node.fs.chmod
import node.fs.readFile
import node.path.path
import node.process.Platform

suspend fun install(distribution: GradleDistribution): String {
val cachedTool = actions.toolcache.find("gradle", distribution.version)
val cachedTool = actions.tool.cache.find("gradle", distribution.version)
val gradleDir = if (cachedTool.isNotEmpty()) {
info("Detected Gradle ${distribution.version} at $cachedTool")
cachedTool
Expand Down Expand Up @@ -71,7 +69,7 @@ suspend fun install(distribution: GradleDistribution): String {
}
}

private val HTTP_AGENT = jso<IHeaders> { set("User-Agent", "burrunan/gradle-cache-action") }
private val HTTP_AGENT = recordOf<String, Any>("User-Agent" to "burrunan/gradle-cache-action")

suspend fun GradleVersion.Official.findUrl(): GradleDistribution {
val url = "https://services.gradle.org/versions/all"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import actions.core.setOutput
import actions.exec.exec
import com.github.burrunan.launcher.internal.GradleErrorCollector
import com.github.burrunan.launcher.internal.GradleOutErrorCollector
import kotlinx.js.jso
import js.core.jso
import node.process.process

class GradleResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.github.burrunan.launcher

import actions.core.info
import actions.toolcache.findAllVersions
import actions.tool.cache.findAllVersions
import com.github.burrunan.test.runTest
import kotlin.test.Test

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ kotlin.code.style=official

kotlinx-coroutines.version=1.6.4
kotlinx-serialization.version=1.3.3
kotlin-wrappers.version=1.0.0-pre.375
kotlin-wrappers.version=1.0.0-pre.499
3 changes: 1 addition & 2 deletions hashing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ plugins {
}

dependencies {
implementation(project(":wrappers:actions-core"))
implementation(project(":wrappers:actions-glob"))
implementation(project(":wrappers:actions-toolkit"))
implementation(project(":wrappers:js"))
implementation(project(":wrappers:nodejs"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ package com.github.burrunan.hashing

import actions.core.ActionFailedException
import actions.core.warning
import actions.glob.Globber
import actions.glob.glob
import com.github.burrunan.wrappers.nodejs.normalizedPath
import com.github.burrunan.wrappers.nodejs.pipeAndWait
import kotlinx.js.jso
import kotlinx.coroutines.await
import kotlinx.serialization.Serializable
import node.WritableStream
import node.crypto.BinaryToTextEncoding
Expand Down Expand Up @@ -70,8 +68,8 @@ suspend fun hashFilesDetailed(
algorithm: String = "sha1",
includeFileName: Boolean = true,
): HashDetails = try {
val globber = Globber(paths.joinToString("\n"))
val fileNames = globber.glob()
val globber = actions.glob.create(paths.joinToString("\n"))
val fileNames = globber.glob().await()
// Sorting is needed for stable overall hash
fileNames.sort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ package com.github.burrunan.hashing

import actions.core.ActionFailedException
import actions.core.warning
import actions.glob.Globber
import actions.glob.glob
import com.github.burrunan.wrappers.nodejs.normalizedPath
import com.github.burrunan.wrappers.nodejs.pipeAndWait
import kotlinx.js.jso
import kotlinx.coroutines.await
import node.WritableStream
import node.buffer.BufferEncoding
import node.crypto.BinaryToTextEncoding
Expand All @@ -42,8 +40,8 @@ suspend fun hashFiles(
algorithm: String = "sha1",
includeFileName: Boolean = true,
): HashResult = try {
val globber = Globber(paths.joinToString("\n"))
val fileNames = globber.glob()
val globber = actions.glob.create(paths.joinToString("\n"))
val fileNames = globber.glob().await()
fileNames.sort()

val githubWorkspace = process.cwd()
Expand Down
4 changes: 1 addition & 3 deletions layered-cache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ dependencies {
implementation(project(":gradle-launcher"))
implementation(project(":hashing"))
implementation(project(":wrappers:actions-cache"))
implementation(project(":wrappers:actions-core"))
implementation(project(":wrappers:actions-exec"))
implementation(project(":wrappers:actions-glob"))
implementation(project(":wrappers:actions-toolkit"))
implementation(project(":wrappers:nodejs"))
implementation(project(":wrappers:octokit-webhooks"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
Expand Down
7 changes: 1 addition & 6 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ include(
"test-library",
"wrappers:js",
"wrappers:nodejs",
"wrappers:actions-toolkit",
"wrappers:actions-cache",
"wrappers:actions-core",
"wrappers:actions-exec",
"wrappers:actions-glob",
"wrappers:actions-http-client",
"wrappers:actions-io",
"wrappers:actions-tool-cache",
"wrappers:java-properties",
"wrappers:octokit-request-error",
"wrappers:octokit-types",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.github.burrunan.test

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.promise
import kotlinx.js.set
import js.core.set
import node.process.process

fun runTest(block: suspend () -> Unit): dynamic = GlobalScope.promise {
Expand Down
5 changes: 2 additions & 3 deletions wrappers/actions-cache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

dependencies {
api(npm("@actions/cache", "3.0.6"))
implementation(project(":wrappers:actions-core"))
api(project(":wrappers:actions-http-client"))
implementation("org.jetbrains.kotlin-wrappers:kotlin-actions-toolkit")
implementation(project(":wrappers:actions-toolkit"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package actions.cache

import actions.core.info
import actions.core.warning
import kotlinx.coroutines.await

suspend fun restoreAndLog(
paths: List<String>, primaryKey: String,
Expand All @@ -32,7 +31,7 @@ suspend fun restoreAndLog(
version + primaryKey,
restoreKeys.map { version + it }.toTypedArray(),
)
}.await()
}
} catch (t: Throwable) {
when (t.asDynamic().name) {
"ValidationError" -> throw t
Expand All @@ -55,7 +54,7 @@ suspend fun saveAndLog(
version: String,
) {
try {
saveCache(paths.toTypedArray(), version + key).await()
saveCache(paths.toTypedArray(), version + key)
} catch (t: Throwable) {
// TODO: propagate error
when (t.asDynamic().name) {
Expand Down
Loading

0 comments on commit ef8873f

Please sign in to comment.