From afcd06fab2c70229e2baa33393b2d045be2cd7b0 Mon Sep 17 00:00:00 2001 From: limebeck Date: Thu, 11 Apr 2024 21:11:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B2=20=D0=BF=D1=80=D0=B5=D0=B7=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 80 ++++----- .../ci/gitlab/scripts/CompilationCache.kt | 53 ++++++ .../ci/gitlab/scripts/DependenciesResolver.kt | 29 +++ .../limebeck/ci/gitlab/scripts/scriptDef.kt | 69 +------- .../assets/scripting-configuration.svg | 108 ++++++++++++ presentation/assets/scripting-host.svg | 165 +++++++++--------- .../diagrams/scripting-configuration.d2 | 15 +- presentation/diagrams/scripting-host.d2 | 32 ++-- presentation/kotlin-script.reveal.kts | 159 +++++++++++------ 9 files changed, 451 insertions(+), 259 deletions(-) create mode 100644 gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/CompilationCache.kt create mode 100644 gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/DependenciesResolver.kt create mode 100644 presentation/assets/scripting-configuration.svg diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ea18886..25ccb32 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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/jbang-action@v0.114.0 -# with: -# script: revealkt@limebeck.dev -# 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/jbang-action@v0.114.0 + with: + script: revealkt@limebeck.dev + 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 diff --git a/gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/CompilationCache.kt b/gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/CompilationCache.kt new file mode 100644 index 0000000..8662a5e --- /dev/null +++ b/gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/CompilationCache.kt @@ -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() \ No newline at end of file diff --git a/gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/DependenciesResolver.kt b/gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/DependenciesResolver.kt new file mode 100644 index 0000000..ca450df --- /dev/null +++ b/gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/DependenciesResolver.kt @@ -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 { + 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()) \ No newline at end of file diff --git a/gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/scriptDef.kt b/gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/scriptDef.kt index 3917683..2fe9b5d 100644 --- a/gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/scriptDef.kt +++ b/gitlab-ci-kts/script-definition/src/main/kotlin/dev/limebeck/ci/gitlab/scripts/scriptDef.kt @@ -1,17 +1,11 @@ package dev.limebeck.ci.gitlab.scripts -import dev.limebeck.ci.gitlab.scripts.tools.Directories import dev.otbe.gitlab.ci.dsl.PipelineBuilder -import kotlinx.coroutines.runBlocking -import java.io.File -import java.nio.ByteBuffer -import java.security.MessageDigest import kotlin.script.experimental.annotations.KotlinScript import kotlin.script.experimental.api.* -import kotlin.script.experimental.dependencies.* -import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver +import kotlin.script.experimental.dependencies.DependsOn +import kotlin.script.experimental.dependencies.Repository import kotlin.script.experimental.host.ScriptingHostConfiguration -import kotlin.script.experimental.jvm.JvmDependency import kotlin.script.experimental.jvm.compilationCache import kotlin.script.experimental.jvm.dependenciesFromClassContext import kotlin.script.experimental.jvm.jvm @@ -26,10 +20,6 @@ import kotlin.script.experimental.jvmhost.CompiledScriptJarsCache ) abstract class GitlabCiKtScript -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 - object GitlabCiKtScriptCompilationConfiguration : ScriptCompilationConfiguration({ jvm { dependenciesFromClassContext(PipelineBuilder::class, wholeClasspath = true) } defaultImports(DependsOn::class, Repository::class) @@ -41,29 +31,19 @@ object GitlabCiKtScriptCompilationConfiguration : ScriptCompilationConfiguration implicitReceivers(PipelineBuilder::class) ide { acceptedLocations(ScriptAcceptedLocation.Everywhere) } compilerOptions.append("-Xadd-modules=ALL-MODULE-PATH") - - // Callbacks refineConfiguration { - // Process specified annotations with the provided handler onAnnotations(DependsOn::class, Repository::class, handler = ::configureMavenDepsOnAnnotations) } }) object GitlabCiKtHostConfiguration : ScriptingHostConfiguration({ jvm { - val cacheExtSetting = System.getProperty(COMPILED_SCRIPTS_CACHE_DIR_PROPERTY) - ?: System.getenv(COMPILED_SCRIPTS_CACHE_DIR_ENV_VAR) - val cacheBaseDir = 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 } + val cacheBaseDir = findCacheBaseDir() if (cacheBaseDir != null) compilationCache( CompiledScriptJarsCache { script, scriptCompilationConfiguration -> - File(cacheBaseDir, compiledScriptUniqueName(script, scriptCompilationConfiguration) + ".jar") + cacheBaseDir + .resolve(compiledScriptUniqueName(script, scriptCompilationConfiguration) + ".jar") } ) } @@ -73,42 +53,3 @@ object GitlabCiKtEvaluationConfiguration : ScriptEvaluationConfiguration({ scriptsInstancesSharing(false) constructorArgs() }) - -// Handler that reconfigures the compilation on the fly -fun configureMavenDepsOnAnnotations(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics { - 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()) - -private 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() \ No newline at end of file diff --git a/presentation/assets/scripting-configuration.svg b/presentation/assets/scripting-configuration.svg new file mode 100644 index 0000000..b9bb25a --- /dev/null +++ b/presentation/assets/scripting-configuration.svg @@ -0,0 +1,108 @@ +Scripting Host (app)Script DefinitionCompilerEvaluatorCompilation configurationHost configurationEvaluation configuration + + + + + + + + + diff --git a/presentation/assets/scripting-host.svg b/presentation/assets/scripting-host.svg index 2215e1b..454c0db 100644 --- a/presentation/assets/scripting-host.svg +++ b/presentation/assets/scripting-host.svg @@ -1,10 +1,10 @@ -JVM ClassesScripting Host (app)ScriptResultCompilerEvaluator - + .d2-1794569215 .fill-N1{fill:#ffffff;} + .d2-1794569215 .fill-N2{fill:#BAC2DE;} + .d2-1794569215 .fill-N3{fill:#A6ADC8;} + .d2-1794569215 .fill-N4{fill:#585B70;} + .d2-1794569215 .fill-N5{fill:#45475A;} + .d2-1794569215 .fill-N6{fill:#313244;} + .d2-1794569215 .fill-N7{fill:#191919;} + .d2-1794569215 .fill-B1{fill:#ffffff;} + .d2-1794569215 .fill-B2{fill:#CBA6f7;} + .d2-1794569215 .fill-B3{fill:#6C7086;} + .d2-1794569215 .fill-B4{fill:#585B70;} + .d2-1794569215 .fill-B5{fill:#45475A;} + .d2-1794569215 .fill-B6{fill:#313244;} + .d2-1794569215 .fill-AA2{fill:#f38BA8;} + .d2-1794569215 .fill-AA4{fill:#45475A;} + .d2-1794569215 .fill-AA5{fill:#313244;} + .d2-1794569215 .fill-AB4{fill:#45475A;} + .d2-1794569215 .fill-AB5{fill:#313244;} + .d2-1794569215 .stroke-N1{stroke:#ffffff;} + .d2-1794569215 .stroke-N2{stroke:#BAC2DE;} + .d2-1794569215 .stroke-N3{stroke:#A6ADC8;} + .d2-1794569215 .stroke-N4{stroke:#585B70;} + .d2-1794569215 .stroke-N5{stroke:#45475A;} + .d2-1794569215 .stroke-N6{stroke:#313244;} + .d2-1794569215 .stroke-N7{stroke:#191919;} + .d2-1794569215 .stroke-B1{stroke:#ffffff;} + .d2-1794569215 .stroke-B2{stroke:#CBA6f7;} + .d2-1794569215 .stroke-B3{stroke:#6C7086;} + .d2-1794569215 .stroke-B4{stroke:#585B70;} + .d2-1794569215 .stroke-B5{stroke:#45475A;} + .d2-1794569215 .stroke-B6{stroke:#313244;} + .d2-1794569215 .stroke-AA2{stroke:#f38BA8;} + .d2-1794569215 .stroke-AA4{stroke:#45475A;} + .d2-1794569215 .stroke-AA5{stroke:#313244;} + .d2-1794569215 .stroke-AB4{stroke:#45475A;} + .d2-1794569215 .stroke-AB5{stroke:#313244;} + .d2-1794569215 .background-color-N1{background-color:#ffffff;} + .d2-1794569215 .background-color-N2{background-color:#BAC2DE;} + .d2-1794569215 .background-color-N3{background-color:#A6ADC8;} + .d2-1794569215 .background-color-N4{background-color:#585B70;} + .d2-1794569215 .background-color-N5{background-color:#45475A;} + .d2-1794569215 .background-color-N6{background-color:#313244;} + .d2-1794569215 .background-color-N7{background-color:#191919;} + .d2-1794569215 .background-color-B1{background-color:#ffffff;} + .d2-1794569215 .background-color-B2{background-color:#CBA6f7;} + .d2-1794569215 .background-color-B3{background-color:#6C7086;} + .d2-1794569215 .background-color-B4{background-color:#585B70;} + .d2-1794569215 .background-color-B5{background-color:#45475A;} + .d2-1794569215 .background-color-B6{background-color:#313244;} + .d2-1794569215 .background-color-AA2{background-color:#f38BA8;} + .d2-1794569215 .background-color-AA4{background-color:#45475A;} + .d2-1794569215 .background-color-AA5{background-color:#313244;} + .d2-1794569215 .background-color-AB4{background-color:#45475A;} + .d2-1794569215 .background-color-AB5{background-color:#313244;} + .d2-1794569215 .color-N1{color:#ffffff;} + .d2-1794569215 .color-N2{color:#BAC2DE;} + .d2-1794569215 .color-N3{color:#A6ADC8;} + .d2-1794569215 .color-N4{color:#585B70;} + .d2-1794569215 .color-N5{color:#45475A;} + .d2-1794569215 .color-N6{color:#313244;} + .d2-1794569215 .color-N7{color:#191919;} + .d2-1794569215 .color-B1{color:#ffffff;} + .d2-1794569215 .color-B2{color:#CBA6f7;} + .d2-1794569215 .color-B3{color:#6C7086;} + .d2-1794569215 .color-B4{color:#585B70;} + .d2-1794569215 .color-B5{color:#45475A;} + .d2-1794569215 .color-B6{color:#313244;} + .d2-1794569215 .color-AA2{color:#f38BA8;} + .d2-1794569215 .color-AA4{color:#45475A;} + .d2-1794569215 .color-AA5{color:#313244;} + .d2-1794569215 .color-AB4{color:#45475A;} + .d2-1794569215 .color-AB5{color:#313244;}.appendix text.text{fill:#ffffff}.md{--color-fg-default:#ffffff;--color-fg-muted:#BAC2DE;--color-fg-subtle:#A6ADC8;--color-canvas-default:#191919;--color-canvas-subtle:#313244;--color-border-default:#ffffff;--color-border-muted:#CBA6f7;--color-neutral-muted:#313244;--color-accent-fg:#CBA6f7;--color-accent-emphasis:#CBA6f7;--color-attention-subtle:#BAC2DE;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B2{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-B3{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-B4{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-B5{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B6{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-AA2{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-AA4{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-AA5{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-AB4{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-AB5{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N1{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N2{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N5{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N6{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N7{fill:url(#streaks-darker);mix-blend-mode:lighten}.light-code{display: none}.dark-code{display: block}]]>JVM ClassesScripting Host (app)ScriptResultScript DefinitionCompilerEvaluator + + diff --git a/presentation/diagrams/scripting-configuration.d2 b/presentation/diagrams/scripting-configuration.d2 index d817af1..349533d 100644 --- a/presentation/diagrams/scripting-configuration.d2 +++ b/presentation/diagrams/scripting-configuration.d2 @@ -1,6 +1,7 @@ direction: right vars: { d2-config: { + pad: 0 theme-id: 200 layout-engine: elk theme-overrides: { @@ -12,10 +13,7 @@ vars: { } **.style.font-size: 35 - -bytecode: JVM Classes { - near: bottom-center -} +(** <- scriptDef.*)[*].style.stroke-width: 4 host: Scripting Host (app) { grid-columns: 2 @@ -23,13 +21,6 @@ host: Scripting Host (app) { evaluator: Evaluator } -host.compiler -> bytecode: { - style.animated: true -} -bytecode -> host.evaluator: { - style.animated: true -} - scriptDef: Script Definition { near: top-center compilation: Compilation configuration @@ -40,3 +31,5 @@ scriptDef: Script Definition { host.compiler <- scriptDef.compilation host.evaluator <- scriptDef.evaluation host <- scriptDef.host + +(scriptDef.* -> **)[*].style.stroke-width: 40 diff --git a/presentation/diagrams/scripting-host.d2 b/presentation/diagrams/scripting-host.d2 index 13ff233..672623c 100644 --- a/presentation/diagrams/scripting-host.d2 +++ b/presentation/diagrams/scripting-host.d2 @@ -1,6 +1,7 @@ direction: right vars: { d2-config: { + pad: 0 theme-id: 200 layout-engine: elk theme-overrides: { @@ -12,6 +13,7 @@ vars: { } **.style.font-size: 35 +(** -> **)[*].style.stroke-width: 4 bytecode: JVM Classes { near: bottom-center @@ -40,21 +42,25 @@ bytecode -> host.evaluator: { output: Result { near: center-right -# grid-columns: 1 -# stdout -# "Runtime Objects" + # grid-columns: 1 + # stdout + # "Runtime Objects" } host.evaluator -> output: { style.animated: true } -# scriptDef: Script Definition { -# near: top-center -# compilation: Compilation configuration -# host: Host configuration -# evaluation: Evaluation configuration -# } -# -# host.compiler <- scriptDef.compilation -# host.evaluator <- scriptDef.evaluation -# host <- scriptDef.host +scriptDef: Script Definition { + near: top-center + # compilation: Compilation configuration + # host: Host configuration + # evaluation: Evaluation configuration +} + +host.compiler <- scriptDef +host.evaluator <- scriptDef +host <- scriptDef +script <- scriptDef +output <- scriptDef + +(* -> *)[*].style.stroke-width: 10 diff --git a/presentation/kotlin-script.reveal.kts b/presentation/kotlin-script.reveal.kts index dba2370..5f7d285 100755 --- a/presentation/kotlin-script.reveal.kts +++ b/presentation/kotlin-script.reveal.kts @@ -273,7 +273,7 @@ slides { stretch = true } +HtmlDslElement { - br { } + br { } } +regular { "IJ IDEA > Tools > Kotlin > Kotlin REPL (Experimental)" } +note { @@ -544,6 +544,11 @@ slides { } """.trimIndent() } + +code(lang = "bash") { + """ + > java -jar gitlab-cli.jar ./main.gitlab-ci.kts > .gitlab.ci.yaml + """.trimIndent() + } } } verticalSlide { @@ -557,13 +562,12 @@ slides { stretch = true } } - slide {//Добавить схему + slide { +componentsTitle +unorderedListOf( - listOf( - "Описание скрипта - Script Definition", //Визуализация и ассоциация - "Исполнение скрипта - Scripting Host", - ) + "Описание скрипта - Script Definition", + "Исполнение скрипта - Scripting Host", + fragmented = false ) } } @@ -573,13 +577,14 @@ slides { +smallTitle { "Описание скрипта" } +smallTitle { "(Script Definition)" } } + slide { +smallTitle { "Script Definition" } - +img("./img_1.png") { + +img("scripting-configuration.svg") { stretch = true } - //TODO: Host configuration } + val baseExampleTitle = smallTitle { "Базовый пример" } val gitlabCiId = ID("gitlab-ci.kts") slide { @@ -641,11 +646,13 @@ slides { +compilationTitle +exampleTitle +kotlinCode( - lines = "|2|3-8|9|10" + lines = "|2-4|5-10|11|12" ) { """ object GitlabCiKtScriptCompilationConfiguration : ScriptCompilationConfiguration({ - jvm { dependenciesFromClassContext(PipelineBuilder::class, wholeClasspath = true) } + jvm { + dependenciesFromClassContext(PipelineBuilder::class, wholeClasspath = true) + } defaultImports(DependsOn::class, Repository::class) defaultImports( "dev.otbe.gitlab.ci.core.model.*", @@ -672,66 +679,75 @@ slides { } """.trimIndent() } - +regular("example.shiny.kts") + +regular("example.gitlab-ci.kts") +kotlinCode { """ - //this: MyShinyBuilder - shinyProperty = "Hello from my script" - shinyPrint() + //this: PipelineBuilder + stages("build", "deploy") """.trimIndent() } } slide { +compilationTitle +exampleTitle - +kotlinCode { + +kotlinCode(lines = "4") { """ @KotlinScript( - fileExtension = "shiny.kts", - compilationConfiguration = MyShinyScriptCompilationConfiguration::class, + fileExtension = "gitlab-ci.kts", + displayName = "Gitlab CI Kotlin configuration", + compilationConfiguration = GitlabCiKtScriptCompilationConfiguration::class, ) - abstract class MyShinyKtScript + abstract class GitlabCiKtScript """.trimIndent() } } + val externalDeps = smallTitle { "Внешние зависимости" } slide { +compilationTitle - +smallTitle { "Внешние зависимости" } //Добавить пример - +kotlinCode { + +externalDeps + +kotlinCode(lines = "2-9") { """ - object MyShinyScriptCompilationConfiguration : ScriptCompilationConfiguration({ + object GitlabCiKtScriptCompilationConfiguration : ScriptCompilationConfiguration({ refineConfiguration { - // Process specified annotations with the provided handler onAnnotations( DependsOn::class, Repository::class, + // Обработчик аннотаций handler = ::configureMavenDepsOnAnnotations ) } + + jvm { + dependenciesFromClassContext(PipelineBuilder::class, wholeClasspath = true) + } + defaultImports(DependsOn::class, Repository::class) + defaultImports( + "dev.otbe.gitlab.ci.core.model.*", + "dev.otbe.gitlab.ci.dsl.*", + "dev.otbe.gitlab.ci.core.goesTo" + ) + implicitReceivers(PipelineBuilder::class) + ide { acceptedLocations(ScriptAcceptedLocation.Everywhere) } } """.trimIndent() } } slide { +compilationTitle - +smallTitle { "Внешние зависимости" } //Добавить пример - +regular("example.shiny.kts") + +externalDeps + +regular("example.gitlab-ci.kts") +kotlinCode { """ - @file:Repository("https://repo1.maven.org/maven2/") //По умолчанию уже подключен - @file:DependsOn("org.jetbrains.kotlinx:kotlinx-cli-jvm:0.3.6") + @file:Repository("https://private-nexus.company.org/ci-templates/") + @file:DependsOn("org.company.ci.templates:jvm-jobs:1.0.0") - import kotlinx.cli.ArgParser - import kotlinx.cli.ArgType - import kotlinx.cli.default - import kotlinx.cli.required - - val parser = ArgParser("example") - val input by parser.option(ArgType.String, shortName = "i", - description = "Input file").required() - val debug by parser.option(ArgType.Boolean, shortName = "d", - description = "Turn on debug mode").default(false) - parser.parse(args) + import org.company.ci.templates.jvm.jobs.* + + val appName = "kotlin-app" + gradleJob { + task = "build" + artifact = "./build/libs/$`$`{appName}.jar" + } """.trimIndent() } } @@ -758,16 +774,17 @@ slides { +exampleTitle +kotlinCode { """ - object MyShinyScriptEvaluationConfiguration : ScriptEvaluationConfiguration({ + object GitlabCiKtEvaluationConfiguration : ScriptEvaluationConfiguration({ scriptsInstancesSharing(false) }) @KotlinScript( - fileExtension = "shiny.kts", - compilationConfiguration = MyShinyScriptCompilationConfiguration::class, - evaluationConfiguration = MyShinyScriptEvaluationConfiguration::class, + fileExtension = "gitlab-ci.kts", + displayName = "Gitlab CI Kotlin configuration", + compilationConfiguration = GitlabCiKtScriptCompilationConfiguration::class, + evaluationConfiguration = GitlabCiKtEvaluationConfiguration::class, ) - abstract class MyShinyKtScript + abstract class GitlabCiKtScript """.trimIndent() } } @@ -776,17 +793,61 @@ slides { +exampleTitle +kotlinCode { """ - object MyShinyScriptEvaluationConfiguration : ScriptEvaluationConfiguration({ + object GitlabCiKtEvaluationConfiguration : ScriptEvaluationConfiguration({ scriptsInstancesSharing(false) constructorArgs("My Arg String") }) @KotlinScript( - fileExtension = "shiny.kts", - compilationConfiguration = MyShinyScriptCompilationConfiguration::class, - evaluationConfiguration = MyShinyScriptEvaluationConfiguration::class, + fileExtension = "gitlab-ci.kts", + displayName = "Gitlab CI Kotlin configuration", + compilationConfiguration = GitlabCiKtScriptCompilationConfiguration::class, + evaluationConfiguration = GitlabCiKtEvaluationConfiguration::class, ) - abstract class MyShinyKtScript(val arg: String) + abstract class GitlabCiKtScript(val arg: String) + """.trimIndent() + } + } + } + + val hostTitle = smallTitle { "Конфигурация хоста" } + verticalSlide { + slide { + +hostTitle + } + slide { + +hostTitle + +exampleTitle + +kotlinCode { + """ + object GitlabCiKtHostConfiguration : ScriptingHostConfiguration({ + jvm { + val cacheBaseDir = findCacheBaseDir() + if (cacheBaseDir != null) + compilationCache( + CompiledScriptJarsCache { script, scriptCompilationConfiguration -> + cacheBaseDir + .resolve(compiledScriptUniqueName(script, scriptCompilationConfiguration) + ".jar") + } + ) + } + }) + """.trimIndent() + } + } + slide { + +hostTitle + +exampleTitle + +kotlinCode { + """ + @KotlinScript( + displayName = "Gitlab CI Kotlin configuration", + fileExtension = "gitlab-ci.kts", + compilationConfiguration = GitlabCiKtScriptCompilationConfiguration::class, + evaluationConfiguration = GitlabCiKtEvaluationConfiguration::class, + hostConfiguration = GitlabCiKtHostConfiguration::class, + ) + abstract class GitlabCiKtScript """.trimIndent() } } @@ -809,9 +870,9 @@ slides { scriptFile: File ): ResultWithDiagnostics { val compilationConfiguration = - createJvmCompilationConfigurationFromTemplate {} + createJvmCompilationConfigurationFromTemplate {} val evaluationConfiguration = - createJvmEvaluationConfigurationFromTemplate {} + createJvmEvaluationConfigurationFromTemplate {} return eval( script = scriptFile.toScriptSource(), compilationConfiguration = compilationConfiguration,