-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
451 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
#name: Build and Deploy | ||
#on: | ||
# # Triggers the workflow on push or pull request events but only for the master branch | ||
# push: | ||
# branches: [ master ] | ||
#jobs: | ||
# jbang: | ||
# runs-on: ubuntu-latest | ||
# name: A job to run jbang | ||
# permissions: | ||
# pages: write # to deploy to Pages | ||
# id-token: write # to verify the deployment originates from an appropriate source | ||
# | ||
# environment: | ||
# name: github-pages | ||
# url: ${{ steps.deployment.outputs.page_url }} | ||
# steps: | ||
# - name: checkout | ||
# uses: actions/checkout@v1 | ||
# - uses: actions/cache@v1 | ||
# with: | ||
# path: /root/.jbang | ||
# key: $-jbang-$ | ||
# restore-keys: | | ||
# $-jbang- | ||
# - name: jbang | ||
# uses: jbangdev/[email protected] | ||
# with: | ||
# script: [email protected] | ||
# scriptargs: render ./presentation/GradlePresentation.reveal.kts | ||
# - name: Setup Pages | ||
# uses: actions/configure-pages@v2 | ||
# - name: Upload artifact | ||
# uses: actions/upload-pages-artifact@v1 | ||
# with: | ||
# # Upload build dir | ||
# path: './out' | ||
# - name: Deploy to GitHub Pages | ||
# id: deployment | ||
# uses: actions/deploy-pages@v1 | ||
name: Build and Deploy | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the master branch | ||
push: | ||
branches: [ master ] | ||
jobs: | ||
jbang: | ||
runs-on: ubuntu-latest | ||
name: A job to run jbang | ||
permissions: | ||
pages: write # to deploy to Pages | ||
id-token: write # to verify the deployment originates from an appropriate source | ||
|
||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v1 | ||
- uses: actions/cache@v1 | ||
with: | ||
path: /root/.jbang | ||
key: $-jbang-$ | ||
restore-keys: | | ||
$-jbang- | ||
- name: jbang | ||
uses: jbangdev/[email protected] | ||
with: | ||
script: [email protected] | ||
scriptargs: render ./presentation/GradlePresentation.reveal.kts | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v2 | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
# Upload build dir | ||
path: './out' | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v1 |
53 changes: 53 additions & 0 deletions
53
...-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/CompilationCache.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dev.limebeck.ci.gitlab.scripts | ||
|
||
import dev.limebeck.ci.gitlab.scripts.tools.Directories | ||
import java.io.File | ||
import java.nio.ByteBuffer | ||
import java.security.MessageDigest | ||
import kotlin.script.experimental.api.ScriptCompilationConfiguration | ||
import kotlin.script.experimental.api.SourceCode | ||
|
||
|
||
const val COMPILED_SCRIPTS_CACHE_DIR_ENV_VAR = "KOTLIN_MAIN_KTS_COMPILED_SCRIPTS_CACHE_DIR" | ||
const val COMPILED_SCRIPTS_CACHE_DIR_PROPERTY = "kotlin.main.kts.compiled.scripts.cache.dir" | ||
const val COMPILED_SCRIPTS_CACHE_VERSION = 1 | ||
|
||
internal fun findCacheBaseDir(): File? { | ||
val cacheExtSetting = System.getProperty(COMPILED_SCRIPTS_CACHE_DIR_PROPERTY) | ||
?: System.getenv(COMPILED_SCRIPTS_CACHE_DIR_ENV_VAR) | ||
return when { | ||
cacheExtSetting == null -> Directories(System.getProperties(), System.getenv()).cache | ||
?.takeIf { it.exists() && it.isDirectory } | ||
?.let { File(it, "main.kts.compiled.cache").apply { mkdir() } } | ||
|
||
cacheExtSetting.isBlank() -> null | ||
else -> File(cacheExtSetting) | ||
}?.takeIf { it.exists() && it.isDirectory } | ||
} | ||
|
||
internal fun compiledScriptUniqueName( | ||
script: SourceCode, | ||
scriptCompilationConfiguration: ScriptCompilationConfiguration | ||
): String { | ||
val digestWrapper = MessageDigest.getInstance("SHA-256") | ||
|
||
fun addToDigest(chunk: String) = with(digestWrapper) { | ||
val chunkBytes = chunk.toByteArray() | ||
update(chunkBytes.size.toByteArray()) | ||
update(chunkBytes) | ||
} | ||
|
||
digestWrapper.update(COMPILED_SCRIPTS_CACHE_VERSION.toByteArray()) | ||
addToDigest(script.text) | ||
scriptCompilationConfiguration.notTransientData.entries | ||
.sortedBy { it.key.name } | ||
.forEach { | ||
addToDigest(it.key.name) | ||
addToDigest(it.value.toString()) | ||
} | ||
return digestWrapper.digest().toHexString() | ||
} | ||
|
||
private fun ByteArray.toHexString(): String = joinToString("", transform = { "%02x".format(it) }) | ||
|
||
private fun Int.toByteArray() = ByteBuffer.allocate(Int.SIZE_BYTES).also { it.putInt(this) }.array() |
29 changes: 29 additions & 0 deletions
29
.../script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/DependenciesResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dev.limebeck.ci.gitlab.scripts | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import kotlin.script.experimental.api.* | ||
import kotlin.script.experimental.dependencies.CompoundDependenciesResolver | ||
import kotlin.script.experimental.dependencies.FileSystemDependenciesResolver | ||
import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver | ||
import kotlin.script.experimental.dependencies.resolveFromScriptSourceAnnotations | ||
import kotlin.script.experimental.jvm.JvmDependency | ||
|
||
|
||
// Handler that reconfigures the compilation on the fly | ||
fun configureMavenDepsOnAnnotations( | ||
context: ScriptConfigurationRefinementContext | ||
): ResultWithDiagnostics<ScriptCompilationConfiguration> { | ||
val annotations = context.collectedData | ||
?.get(ScriptCollectedData.collectedAnnotations) | ||
?.takeIf { it.isNotEmpty() } | ||
?: return context.compilationConfiguration.asSuccess() | ||
return runBlocking { | ||
resolver.resolveFromScriptSourceAnnotations(annotations) | ||
}.onSuccess { | ||
context.compilationConfiguration.with { | ||
dependencies.append(JvmDependency(it)) | ||
}.asSuccess() | ||
} | ||
} | ||
|
||
private val resolver = CompoundDependenciesResolver(FileSystemDependenciesResolver(), MavenDependenciesResolver()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.