Skip to content

Commit f62258c

Browse files
authored
test: add end-to-end test for Kotlin-based step (#1417)
1 parent fd53d15 commit f62258c

File tree

2 files changed

+58
-15
lines changed

2 files changed

+58
-15
lines changed

.github/workflows/end-to-end-tests.main.kts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,39 @@
77
@file:DependsOn("actions:setup-java:v4")
88
@file:DependsOn("actions:setup-python:v5")
99
@file:DependsOn("gradle:actions__setup-gradle:v3")
10+
@file:OptIn(ExperimentalKotlinLogicStep::class)
1011

1112
import io.github.typesafegithub.workflows.actions.actions.*
1213
import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
14+
import io.github.typesafegithub.workflows.annotations.ExperimentalKotlinLogicStep
1315
import io.github.typesafegithub.workflows.domain.JobOutputs
1416
import io.github.typesafegithub.workflows.domain.Mode
1517
import io.github.typesafegithub.workflows.domain.Permission
1618
import io.github.typesafegithub.workflows.domain.RunnerType
1719
import io.github.typesafegithub.workflows.domain.actions.*
1820
import io.github.typesafegithub.workflows.domain.triggers.PullRequest
1921
import io.github.typesafegithub.workflows.domain.triggers.Push
22+
import io.github.typesafegithub.workflows.dsl.JobBuilder
2023
import io.github.typesafegithub.workflows.dsl.expressions.Contexts
2124
import io.github.typesafegithub.workflows.dsl.expressions.expr
2225
import io.github.typesafegithub.workflows.dsl.workflow
2326
import io.github.typesafegithub.workflows.yaml.writeToFile
27+
import java.time.Instant
28+
29+
fun JobBuilder<*>.publishToMavenLocal() {
30+
uses(
31+
name = "Set up JDK",
32+
action = SetupJava(
33+
javaVersion = "11",
34+
distribution = SetupJava.Distribution.Zulu,
35+
),
36+
)
37+
uses(action = ActionsSetupGradle(generateJobSummary = false))
38+
run(
39+
name = "Publish to Maven local",
40+
command = "./gradlew publishToMavenLocal",
41+
)
42+
}
2443

2544
workflow(
2645
name = "End-to-end tests",
@@ -29,18 +48,7 @@ workflow(
2948
PullRequest(),
3049
),
3150
yamlConsistencyJobAdditionalSteps = {
32-
uses(
33-
name = "Set up JDK",
34-
action = SetupJava(
35-
javaVersion = "11",
36-
distribution = SetupJava.Distribution.Zulu,
37-
),
38-
)
39-
uses(action = ActionsSetupGradle(generateJobSummary = false))
40-
run(
41-
name = "Publish to Maven local",
42-
command = "./gradlew publishToMavenLocal",
43-
)
51+
publishToMavenLocal()
4452
},
4553
sourceFile = __FILE__.toPath(),
4654
) {
@@ -193,6 +201,17 @@ workflow(
193201
command = "action=${Contexts.env.GITHUB_ACTION} repo=${Contexts.env.GITHUB_REPOSITORY}",
194202
condition = expr { always() },
195203
)
204+
205+
publishToMavenLocal()
206+
207+
run(
208+
name = "Step with a Kotlin-based logic",
209+
ifKotlin = { Instant.now() > Instant.parse("2022-03-04T12:34:56.00Z") },
210+
) {
211+
println("Hello from Kotlin! Now it's ${Instant.now()}")
212+
println("Running for commit ${github.sha}, branch ${github.ref}")
213+
}
214+
196215
val scriptStep =
197216
uses(
198217
action = GithubScript(

.github/workflows/end-to-end-tests.yaml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ jobs:
4646
env:
4747
$GREETING: 'World'
4848
outputs:
49-
scriptKey: '${{ steps.step-15.outputs.key }}'
50-
scriptKey2: '${{ steps.step-15.outputs.key2 }}'
51-
scriptResult: '${{ steps.step-15.outputs.result }}'
49+
scriptKey: '${{ steps.step-20.outputs.key }}'
50+
scriptKey2: '${{ steps.step-20.outputs.key2 }}'
51+
scriptResult: '${{ steps.step-20.outputs.result }}'
5252
steps:
5353
- id: 'step-0'
5454
name: 'Hello world!'
@@ -117,6 +117,30 @@ jobs:
117117
run: 'action=$GITHUB_ACTION repo=$GITHUB_REPOSITORY'
118118
if: '${{ always() }}'
119119
- id: 'step-15'
120+
name: 'Set up JDK'
121+
uses: 'actions/setup-java@v4'
122+
with:
123+
java-version: '11'
124+
distribution: 'zulu'
125+
- id: 'step-16'
126+
uses: 'gradle/actions/setup-gradle@v3'
127+
with:
128+
generate-job-summary: 'false'
129+
- id: 'step-17'
130+
name: 'Publish to Maven local'
131+
run: './gradlew publishToMavenLocal'
132+
- id: 'step-18'
133+
name: 'Evaluating condition for ''Step with a Kotlin-based logic'''
134+
env:
135+
GHWKT_GITHUB_CONTEXT_JSON: '${{ toJSON(github) }}'
136+
run: 'GHWKT_RUN_STEP=''test_job_1:step-18'' ''.github/workflows/end-to-end-tests.main.kts'''
137+
- id: 'step-19'
138+
name: 'Step with a Kotlin-based logic'
139+
env:
140+
GHWKT_GITHUB_CONTEXT_JSON: '${{ toJSON(github) }}'
141+
run: 'GHWKT_RUN_STEP=''test_job_1:step-19'' ''.github/workflows/end-to-end-tests.main.kts'''
142+
if: '${{ steps.step-18.outputs.evaluation-result }}'
143+
- id: 'step-20'
120144
uses: 'actions/github-script@v7'
121145
with:
122146
script: |-

0 commit comments

Comments
 (0)