Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Nov 14, 2023
1 parent dfc6c18 commit 6b4fd62
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 37 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/foo.main.kts
Original file line number Diff line number Diff line change
@@ -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()
87 changes: 87 additions & 0 deletions .github/workflows/foo.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ object Kali : AptGetBasedDistribution(
wslId = "kali-linux",
distributionName = "Kali",
version = SemVer("1.0.0", jso<SemVerRangeOptions>()),
productId = "9pkr34tncv07",
downloadUrl = URL("https://aka.ms/wsl-kali-linux-new"),
installerFile = "kali.exe"
)

Expand Down Expand Up @@ -346,7 +346,7 @@ object OpenSuseLeap15_2 : ZypperBasedDistribution(
wslId = "openSUSE-Leap-15.2",
distributionName = "openSUSE Leap",
version = SemVer("15.2.0", jso<SemVerRangeOptions>()),
productId = "9mzd0n9z4m4h",
downloadUrl = URL("https://aka.ms/wsl-opensuseleap15-2"),
installerFile = "openSUSE-Leap-15.2.exe"
) {
override suspend fun refresh() {
Expand Down
72 changes: 37 additions & 35 deletions src/main/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 6b4fd62

Please sign in to comment.