Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Nov 13, 2023
1 parent dfc6c18 commit 33cd7b0
Show file tree
Hide file tree
Showing 12 changed files with 476 additions and 75 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
30 changes: 30 additions & 0 deletions .github/workflows/test.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ val kali = mapOf(
"default-absent-tool" to "dos2unix"
)

val openSuseTumbleweed = mapOf(
"wsl-id" to "openSUSE-Tumbleweed",
"user-id" to "openSUSE-Tumbleweed",
"match-pattern" to "*openSUSE*Tumbleweed*",
"default-absent-tool" to "zsh"
)

val openSuseLeap15_3 = mapOf(
"wsl-id" to "openSUSE-Leap-15.3",
"user-id" to "openSUSE-Leap-15.3",
"match-pattern" to "*openSUSE*Leap*15.3*",
"default-absent-tool" to "zsh"
)

val openSuseLeap15_2 = mapOf(
"wsl-id" to "openSUSE-Leap-15.2",
"user-id" to "openSUSE-Leap-15.2",
Expand Down Expand Up @@ -108,6 +122,8 @@ val distributions = listOf(
debian,
alpine,
kali,
openSuseTumbleweed,
openSuseLeap15_3,
openSuseLeap15_2,
ubuntu2204,
ubuntu2004,
Expand Down Expand Up @@ -393,6 +409,13 @@ workflowWithCopyright(
name = "Add user test",
command = "useradd -m -p 4qBD5NWD3IkbU test"
)
usesSelf(
name = "Upgrade PAM on openSUSE Tumbleweed",
action = executeAction.copy(
additionalPackages = listOf("pam")
),
condition = executeActionStep.successOnOpenSuseTumbleweedCondition
)
executeActionStep = usesSelfAfterSuccess(
name = "Set wsl-bash wrapper to use user test by default",
action = executeAction.copy(
Expand Down Expand Up @@ -1055,6 +1078,13 @@ val Step.successOnAlpineCondition
&& (matrix.distribution.user-id == 'Alpine')
""".trimIndent()

val Step.successOnOpenSuseTumbleweedCondition
get() = """
always()
&& ($outcome == 'success')
&& (matrix.distribution.user-id == 'openSUSE-Tumbleweed')
""".trimIndent()

val Step.successNotOnUbuntu2004Condition
get() = """
always()
Expand Down
Loading

0 comments on commit 33cd7b0

Please sign in to comment.