Skip to content

Commit ed8f4d1

Browse files
authored
ci: add end-to-end tests workflow (#1415)
The main goal of this workflow is to use freshly build library from a given commit inside a workflow ran from a Kotlin script.
1 parent 1c97516 commit ed8f4d1

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

.github/workflows/build.main.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ workflow(
9898
command = """
9999
find -name *.main.kts -print0 | while read -d ${'$'}'\0' file
100100
do
101+
if [ "${'$'}file" = "./.github/workflows/end-to-end-tests.main.kts" ]; then
102+
continue
103+
fi
104+
101105
echo "Compiling ${'$'}file..."
102106
kotlinc -Werror -Xallow-any-scripts-in-source-roots "${'$'}file"
103107
done
@@ -125,6 +129,10 @@ workflow(
125129
command = """
126130
find -name "*.main.kts" -print0 | while read -d ${'$'}'\0' file
127131
do
132+
if [ "${'$'}file" = "./.github/workflows/end-to-end-tests.main.kts" ]; then
133+
continue
134+
fi
135+
128136
if [ -x "${'$'}file" ]; then
129137
echo "Regenerating ${'$'}file..."
130138
(${'$'}file)

.github/workflows/build.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ jobs:
125125
run: |-
126126
find -name *.main.kts -print0 | while read -d $'\0' file
127127
do
128+
if [ "$file" = "./.github/workflows/end-to-end-tests.main.kts" ]; then
129+
continue
130+
fi
131+
128132
echo "Compiling $file..."
129133
kotlinc -Werror -Xallow-any-scripts-in-source-roots "$file"
130134
done
@@ -150,6 +154,10 @@ jobs:
150154
run: |-
151155
find -name "*.main.kts" -print0 | while read -d $'\0' file
152156
do
157+
if [ "$file" = "./.github/workflows/end-to-end-tests.main.kts" ]; then
158+
continue
159+
fi
160+
153161
if [ -x "$file" ]; then
154162
echo "Regenerating $file..."
155163
($file)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env kotlin
2+
@file:Repository("file://~/.m2/repository/")
3+
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.14.1-SNAPSHOT")
4+
@file:Repository("https://github-workflows-kt-bindings.colman.com.br/binding/")
5+
@file:DependsOn("actions:checkout:v4")
6+
@file:DependsOn("actions:setup-java:v4")
7+
@file:DependsOn("gradle:actions__setup-gradle:v3")
8+
9+
import io.github.typesafegithub.workflows.actions.actions.Checkout
10+
import io.github.typesafegithub.workflows.actions.actions.SetupJava
11+
import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
12+
import io.github.typesafegithub.workflows.domain.RunnerType
13+
import io.github.typesafegithub.workflows.domain.triggers.PullRequest
14+
import io.github.typesafegithub.workflows.domain.triggers.Push
15+
import io.github.typesafegithub.workflows.dsl.workflow
16+
import io.github.typesafegithub.workflows.yaml.writeToFile
17+
18+
workflow(
19+
name = "End-to-end tests",
20+
on = listOf(
21+
Push(branches = listOf("main")),
22+
PullRequest(),
23+
),
24+
yamlConsistencyJobAdditionalSteps = {
25+
uses(
26+
name = "Set up JDK",
27+
action = SetupJava(
28+
javaVersion = "11",
29+
distribution = SetupJava.Distribution.Zulu,
30+
),
31+
)
32+
uses(action = ActionsSetupGradle(generateJobSummary = false))
33+
run(
34+
name = "Publish to Maven local",
35+
command = "./gradlew publishToMavenLocal",
36+
)
37+
},
38+
sourceFile = __FILE__.toPath(),
39+
) {
40+
job(
41+
id = "main-job",
42+
name = "Main job",
43+
runsOn = RunnerType.UbuntuLatest,
44+
) {
45+
uses(action = Checkout())
46+
run(command = "echo 'Hello world!'")
47+
}
48+
}.writeToFile()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This file was generated using Kotlin DSL (.github/workflows/end-to-end-tests.main.kts).
2+
# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file.
3+
# Generated with https://github.com/typesafegithub/github-workflows-kt
4+
5+
name: 'End-to-end tests'
6+
on:
7+
push:
8+
branches:
9+
- 'main'
10+
pull_request: {}
11+
jobs:
12+
check_yaml_consistency:
13+
name: 'Check YAML consistency'
14+
runs-on: 'ubuntu-latest'
15+
steps:
16+
- id: 'step-0'
17+
name: 'Check out'
18+
uses: 'actions/checkout@v4'
19+
- id: 'step-1'
20+
name: 'Set up JDK'
21+
uses: 'actions/setup-java@v4'
22+
with:
23+
java-version: '11'
24+
distribution: 'zulu'
25+
- id: 'step-2'
26+
uses: 'gradle/actions/setup-gradle@v3'
27+
with:
28+
generate-job-summary: 'false'
29+
- id: 'step-3'
30+
name: 'Publish to Maven local'
31+
run: './gradlew publishToMavenLocal'
32+
- id: 'step-4'
33+
name: 'Execute script'
34+
run: 'rm ''.github/workflows/end-to-end-tests.yaml'' && ''.github/workflows/end-to-end-tests.main.kts'''
35+
- id: 'step-5'
36+
name: 'Consistency check'
37+
run: 'git diff --exit-code ''.github/workflows/end-to-end-tests.yaml'''
38+
main-job:
39+
name: 'Main job'
40+
runs-on: 'ubuntu-latest'
41+
needs:
42+
- 'check_yaml_consistency'
43+
steps:
44+
- id: 'step-0'
45+
uses: 'actions/checkout@v4'
46+
- id: 'step-1'
47+
run: 'echo ''Hello world!'''

github-workflows-kt/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ val validateDuplicatedVersion by tasks.creating<Task> {
8686
rootDir.resolve("github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/docsnippets/GettingStartedSnippets.kt").readText()
8787
.contains("\"io.github.typesafegithub:github-workflows-kt:$version\"")
8888
) { "Library version stated in github-workflows-kt/src/test/.../GettingStarted.kt should be equal to $version!" }
89+
require(
90+
rootDir.resolve(".github/workflows/end-to-end-tests.main.kts").readText()
91+
.contains("\"io.github.typesafegithub:github-workflows-kt:$version\"")
92+
) { "Library version stated in end-to-end-tests.main.kts should be equal to $version!" }
8993
}
9094
}
9195

0 commit comments

Comments
 (0)