diff --git a/.github/workflows/bindings-server.main.kts b/.github/workflows/bindings-server.main.kts
index 8184eb7cbe..610a61e0b2 100755
--- a/.github/workflows/bindings-server.main.kts
+++ b/.github/workflows/bindings-server.main.kts
@@ -82,7 +82,7 @@ workflow(
cleanMavenLocal()
run(
- name = "Execute the script using the bindings from the serve - with /binding",
+ name = "Execute the script using the bindings from the server - with /binding",
command = """
mv .github/workflows/test-script-consuming-jit-bindings-old.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-old.main.kts
.github/workflows/test-script-consuming-jit-bindings-old.main.kts
@@ -101,6 +101,16 @@ workflow(
cleanMavenLocal()
+ run(
+ name = "Execute the script using the bindings from the server - with /refresh",
+ command = """
+ mv .github/workflows/test-script-consuming-jit-bindings-refresh.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-refresh.main.kts
+ .github/workflows/test-script-consuming-jit-bindings-refresh.main.kts
+ """.trimIndent(),
+ )
+
+ cleanMavenLocal()
+
run(
name = "Execute the script using bindings but without dependency on library",
command = """
@@ -126,6 +136,15 @@ workflow(
name = "Fetch maven-metadata.xml for nested action",
command = "curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep 'v4'",
)
+
+ run(
+ name = "Fetch maven-metadata.xml for top-level action - with /refresh",
+ command = "curl --fail http://localhost:8080/refresh/actions/checkout/maven-metadata.xml | grep 'v4'",
+ )
+ run(
+ name = "Fetch maven-metadata.xml for nested action - with /refresh",
+ command = "curl --fail http://localhost:8080/refresh/actions/cache__save/maven-metadata.xml | grep 'v4'",
+ )
}
job(
diff --git a/.github/workflows/test-script-consuming-jit-bindings-refresh.main.do-not-compile.kts b/.github/workflows/test-script-consuming-jit-bindings-refresh.main.do-not-compile.kts
new file mode 100644
index 0000000000..4ca7cf46c4
--- /dev/null
+++ b/.github/workflows/test-script-consuming-jit-bindings-refresh.main.do-not-compile.kts
@@ -0,0 +1,22 @@
+#!/usr/bin/env kotlin
+@file:Repository("https://repo.maven.apache.org/maven2/")
+@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.13.0")
+
+@file:Repository("http://localhost:8080/refresh/")
+
+// Regular, top-level action.
+@file:DependsOn("actions:checkout:v4")
+
+// Nested action.
+@file:DependsOn("gradle:actions__setup-gradle:v3")
+
+// Using specific version.
+@file:DependsOn("actions:cache:v3.3.3")
+
+import io.github.typesafegithub.workflows.actions.actions.Cache
+import io.github.typesafegithub.workflows.actions.actions.Checkout
+import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
+
+println(Checkout())
+println(ActionsSetupGradle())
+println(Cache(path = listOf("some-path"), key = "some-key"))
diff --git a/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt b/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt
index 71fae4d3d8..bae2eb452d 100644
--- a/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt
+++ b/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt
@@ -11,6 +11,7 @@ import io.github.typesafegithub.workflows.mavenbinding.buildVersionArtifacts
import io.github.typesafegithub.workflows.shared.internal.getGithubToken
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
+import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.engine.embeddedServer
@@ -54,6 +55,12 @@ fun main() {
artifact(bindingsCache)
}
+ route("/refresh") {
+ route("{owner}/{name}/{version}/{file}") {
+ artifact(bindingsCache, refresh = true)
+ }
+ }
+
route("{owner}/{name}/{file}") {
metadata()
}
@@ -88,26 +95,12 @@ private fun Route.metadata() {
}
}
-private fun Route.artifact(bindingsCache: Cache>>) {
+private fun Route.artifact(
+ bindingsCache: Cache>>,
+ refresh: Boolean = false,
+) {
get {
- val owner = call.parameters["owner"]!!
- val name = call.parameters["name"]!!
- val version = call.parameters["version"]!!
- val actionCoords =
- ActionCoords(
- owner = owner,
- name = name,
- version = version,
- )
- println("➡️ Requesting ${actionCoords.prettyPrint}")
- val bindingArtifacts =
- bindingsCache
- .get(actionCoords) {
- actionCoords.buildVersionArtifacts()?.let {
- Result.success(it)
- } ?: Result.failure(object : Throwable() {})
- }.getOrNull()
-
+ val bindingArtifacts = call.toBindingArtifacts(bindingsCache, refresh)
if (bindingArtifacts == null) {
call.respondText("Not found", status = HttpStatusCode.NotFound)
return@get
@@ -131,24 +124,8 @@ private fun Route.artifact(bindingsCache: Cache>>,
+ refresh: Boolean,
+): Map? {
+ val owner = parameters["owner"]!!
+ val name = parameters["name"]!!
+ val version = parameters["version"]!!
+ val actionCoords =
+ ActionCoords(
+ owner = owner,
+ name = name,
+ version = version,
+ )
+ println("➡️ Requesting ${actionCoords.prettyPrint}")
+ val bindingArtifacts =
+ if (refresh) {
+ actionCoords.buildVersionArtifacts().also {
+ bindingsCache.put(actionCoords, Result.of(it))
+ }
+ } else {
+ bindingsCache
+ .get(actionCoords) { Result.of(actionCoords.buildVersionArtifacts()) }
+ .getOrNull()
+ }
+ return bindingArtifacts
+}
+
+private fun Result.Companion.failure(): Result = failure(object : Throwable() {})
+
+private fun Result.Companion.of(value: T?): Result = value?.let { success(it) } ?: failure()