From 6b4fd6245aae538141b8dfa5b2c785473f06925d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Tue, 14 Nov 2023 02:43:18 +0100 Subject: [PATCH] wip --- .github/workflows/foo.main.kts | 113 ++++++++++++++++++ .github/workflows/foo.yaml | 87 ++++++++++++++ .../github/action/setup_wsl/Distribution.kt | 4 +- .../github/action/setup_wsl/SetupWsl.kt | 72 +++++------ 4 files changed, 239 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/foo.main.kts create mode 100644 .github/workflows/foo.yaml diff --git a/.github/workflows/foo.main.kts b/.github/workflows/foo.main.kts new file mode 100644 index 00000000..a058aa22 --- /dev/null +++ b/.github/workflows/foo.main.kts @@ -0,0 +1,113 @@ +#!/usr/bin/env kotlin + +@file:DependsOn("it.krzeminski:github-actions-kotlin-dsl:0.40.0") + +import it.krzeminski.githubactions.actions.actions.CacheRestoreV3 +import it.krzeminski.githubactions.actions.actions.CacheSaveV3 +import it.krzeminski.githubactions.actions.actions.CheckoutV3 +import it.krzeminski.githubactions.actions.actions.SetupJavaV3 +import it.krzeminski.githubactions.actions.actions.SetupJavaV3.Distribution.Temurin +import it.krzeminski.githubactions.actions.burrunan.GradleCacheActionV1 +import it.krzeminski.githubactions.actions.vampire.SetupWslV2 +import it.krzeminski.githubactions.actions.vampire.SetupWslV2.Distribution +import it.krzeminski.githubactions.domain.RunnerType.WindowsLatest +import it.krzeminski.githubactions.domain.Shell +import it.krzeminski.githubactions.domain.actions.CustomAction +import it.krzeminski.githubactions.domain.triggers.Push +import it.krzeminski.githubactions.dsl.expressions.expr +import it.krzeminski.githubactions.dsl.workflow +import it.krzeminski.githubactions.yaml.writeToFile + +workflow( + name = "Debug", + on = listOf(Push()), + sourceFile = __FILE__.toPath() +) { + val builtArtifacts = listOf( + "action.yml", + "build/distributions/" + ) + + val build = job( + id = "build", + name = "Build", + runsOn = WindowsLatest + ) { + run( + name = "Configure Git", + command = "git config --global core.autocrlf input" + ) + uses( + name = "Checkout", + action = CheckoutV3() + ) + uses( + name = "Setup Java 11", + action = SetupJavaV3( + javaVersion = "11", + distribution = Temurin + ) + ) + uses( + name = "Build", + action = GradleCacheActionV1( + arguments = listOf( + "--show-version", + "build", + "--info", + "--stacktrace", + "--scan" + ), + debug = false, + concurrent = true + ) + ) + uses( + name = "Save built artifacts to cache", + action = CacheSaveV3( + path = builtArtifacts, + key = expr { github.run_id } + ) + ) + } + + job( + id = "test", + name = "Test", + needs = listOf(build), + runsOn = WindowsLatest + ) { + uses( + name = "Restore built artifacts from cache", + action = CacheRestoreV3( + path = builtArtifacts, + key = expr { github.run_id }, + failOnCacheMiss = true + ) + ) + uses( + name = "Execute action", + action = SetupWslV2( +// distribution = Distribution.Alpine + distribution = Distribution.Custom("openSUSE-Tumbleweed") + ), + _customArguments = mapOf( + "uses" to "./" + ) + ) + uses( + name = "Setup tmate session", + action = CustomAction( + actionOwner = "mxschmitt", + actionName = "action-tmate", + actionVersion = "v3", + inputs = emptyMap() + ) + ) + run( + name = "Test - action should fail if an invalid distribution is given", + shell = Shell.Custom("wsl-bash {0}"), + command = "true" + ) + } +}.writeToFile() diff --git a/.github/workflows/foo.yaml b/.github/workflows/foo.yaml new file mode 100644 index 00000000..35dfc240 --- /dev/null +++ b/.github/workflows/foo.yaml @@ -0,0 +1,87 @@ +# This file was generated using Kotlin DSL (.github/workflows/foo.main.kts). +# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. +# Generated with https://github.com/krzema12/github-workflows-kt + +name: Debug +on: + push: {} +jobs: + check_yaml_consistency: + name: Check YAML consistency + runs-on: ubuntu-latest + steps: + - id: step-0 + name: Check out + uses: actions/checkout@v3 + - id: step-1 + name: Execute script + run: rm '.github/workflows/foo.yaml' && '.github/workflows/foo.main.kts' + - id: step-2 + name: Consistency check + run: git diff --exit-code '.github/workflows/foo.yaml' + build: + name: Build + runs-on: windows-latest + needs: + - check_yaml_consistency + steps: + - id: step-0 + name: Configure Git + run: git config --global core.autocrlf input + - id: step-1 + name: Checkout + uses: actions/checkout@v3 + - id: step-2 + name: Setup Java 11 + uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: temurin + - id: step-3 + name: Build + uses: burrunan/gradle-cache-action@v1 + with: + debug: false + concurrent: true + arguments: |- + --show-version + build + --info + --stacktrace + --scan + - id: step-4 + name: Save built artifacts to cache + uses: actions/cache/save@v3 + with: + path: |- + action.yml + build/distributions/ + key: ${{ github.run_id }} + test: + name: Test + runs-on: windows-latest + needs: + - build + - check_yaml_consistency + steps: + - id: step-0 + name: Restore built artifacts from cache + uses: actions/cache/restore@v3 + with: + path: |- + action.yml + build/distributions/ + key: ${{ github.run_id }} + fail-on-cache-miss: true + - id: step-1 + name: Execute action + uses: ./ + with: + distribution: openSUSE-Tumbleweed + - id: step-2 + name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + - id: step-3 + name: Test - action should fail if an invalid distribution is given + shell: wsl-bash {0} + run: true diff --git a/src/main/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt b/src/main/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt index fefc7cc9..03940f73 100644 --- a/src/main/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt +++ b/src/main/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt @@ -260,7 +260,7 @@ object Kali : AptGetBasedDistribution( wslId = "kali-linux", distributionName = "Kali", version = SemVer("1.0.0", jso()), - productId = "9pkr34tncv07", + downloadUrl = URL("https://aka.ms/wsl-kali-linux-new"), installerFile = "kali.exe" ) @@ -346,7 +346,7 @@ object OpenSuseLeap15_2 : ZypperBasedDistribution( wslId = "openSUSE-Leap-15.2", distributionName = "openSUSE Leap", version = SemVer("15.2.0", jso()), - productId = "9mzd0n9z4m4h", + downloadUrl = URL("https://aka.ms/wsl-opensuseleap15-2"), installerFile = "openSUSE-Leap-15.2.exe" ) { override suspend fun refresh() { diff --git a/src/main/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt b/src/main/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt index fab8ed52..4adefeb5 100644 --- a/src/main/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt +++ b/src/main/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt @@ -260,41 +260,43 @@ val wslShellDistributionWrapperPath by lazy { suspend fun main() { runCatching { - group("Verify Windows Environment", ::verifyWindowsEnvironment) - - if (getInput("only safe actions").isEmpty() - || !getBooleanInput("only safe actions") - ) { - if (installationNeeded()) { - group("Install Distribution", ::installDistribution) - } - - if (wslConf.isNotEmpty()) { - group("Create /etc/wsl.conf", ::createWslConf) - } - - if (setAsDefault()) { - group("Set Distribution as Default", ::setDistributionAsDefault) - } - - if (update) { - group("Update Distribution", distribution::update) - } - - if (additionalPackages.isNotEmpty()) { - group("Install Additional Packages", suspend { distribution.install(*additionalPackages) }) - } - - if (wslShellCommand.isNotEmpty() - || !exists(wslShellWrapperPath) - || !exists(wslShellDistributionWrapperPath) - ) { - group("Write WSL Shell Wrapper", ::writeWslShellWrapper) - } - } - - setOutput("wsl-shell-wrapper-path", wslShellWrapperPath) - setOutput("wsl-shell-distribution-wrapper-path", wslShellDistributionWrapperPath) + println(Alpine.downloadUrl()) + +// group("Verify Windows Environment", ::verifyWindowsEnvironment) +// +// if (getInput("only safe actions").isEmpty() +// || !getBooleanInput("only safe actions") +// ) { +// if (installationNeeded()) { +// group("Install Distribution", ::installDistribution) +// } +// +// if (wslConf.isNotEmpty()) { +// group("Create /etc/wsl.conf", ::createWslConf) +// } +// +// if (setAsDefault()) { +// group("Set Distribution as Default", ::setDistributionAsDefault) +// } +// +// if (update) { +// group("Update Distribution", distribution::update) +// } +// +// if (additionalPackages.isNotEmpty()) { +// group("Install Additional Packages", suspend { distribution.install(*additionalPackages) }) +// } +// +// if (wslShellCommand.isNotEmpty() +// || !exists(wslShellWrapperPath) +// || !exists(wslShellDistributionWrapperPath) +// ) { +// group("Write WSL Shell Wrapper", ::writeWslShellWrapper) +// } +// } +// +// setOutput("wsl-shell-wrapper-path", wslShellWrapperPath) +// setOutput("wsl-shell-distribution-wrapper-path", wslShellDistributionWrapperPath) }.onFailure { debug(it.stackTraceToString()) setFailed(it.message ?: "$it")