From ed157faa6361fd6c5d2be5d19a855a45d0c0f58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Krzemi=C5=84ski?= <3110813+krzema12@users.noreply.github.com> Date: Mon, 19 Aug 2024 08:03:20 +0200 Subject: [PATCH] Configure CI to test Kotlin workflows (#27) --- .github/workflows/test.main.kts | 64 +++++++++++++++++++++++++++++++++ .github/workflows/test.yaml | 62 ++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100755 .github/workflows/test.main.kts create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.main.kts b/.github/workflows/test.main.kts new file mode 100755 index 0000000..1c3a247 --- /dev/null +++ b/.github/workflows/test.main.kts @@ -0,0 +1,64 @@ +#!/usr/bin/env kotlin +@file:Repository("https://repo.maven.apache.org/maven2/") +@file:DependsOn("io.github.typesafegithub:github-workflows-kt:2.3.0") + +@file:Repository("https://bindings.krzeminski.it") +@file:DependsOn("actions:checkout:v4") + +import io.github.typesafegithub.workflows.actions.actions.Checkout +import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest +import io.github.typesafegithub.workflows.domain.triggers.PullRequest +import io.github.typesafegithub.workflows.domain.triggers.Push +import io.github.typesafegithub.workflows.dsl.workflow + +workflow( + name = "Test", + on = listOf( + Push(branches = listOf("main")), + PullRequest(), + ), + sourceFile = __FILE__, +) { + job( + id = "build_kotlin_scripts", + name = "Build Kotlin scripts", + runsOn = UbuntuLatest, + ) { + uses(action = Checkout()) + run( + command = """ + find -name *.main.kts -print0 | while read -d ${'$'}'\0' file + do + echo "Compiling ${'$'}file..." + kotlinc -Werror -Xallow-any-scripts-in-source-roots -Xuse-fir-lt=false "${'$'}file" + done + """.trimIndent() + ) + } + + + job( + id = "workflows_consistency_check", + name = "Run consistency check on all GitHub workflows", + runsOn = UbuntuLatest, + ) { + uses(action = Checkout()) + run(command = "cd .github/workflows") + run( + name = "Regenerate all workflow YAMLs", + command = """ + find -name "*.main.kts" -print0 | while read -d ${'$'}'\0' file + do + if [ -x "${'$'}file" ]; then + echo "Regenerating ${'$'}file..." + (${'$'}file) + fi + done + """.trimIndent(), + ) + run( + name = "Check if some file is different after regeneration", + command = "git diff --exit-code .", + ) + } +} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..054a461 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,62 @@ +# This file was generated using Kotlin DSL (.github/workflows/test.main.kts). +# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. +# Generated with https://github.com/typesafegithub/github-workflows-kt + +name: 'Test' +on: + push: + branches: + - 'main' + pull_request: {} +jobs: + check_yaml_consistency: + name: 'Check YAML consistency' + runs-on: 'ubuntu-latest' + steps: + - id: 'step-0' + name: 'Check out' + uses: 'actions/checkout@v4' + - id: 'step-1' + name: 'Execute script' + run: 'rm ''.github/workflows/test.yaml'' && ''.github/workflows/test.main.kts''' + - id: 'step-2' + name: 'Consistency check' + run: 'git diff --exit-code ''.github/workflows/test.yaml''' + build_kotlin_scripts: + name: 'Build Kotlin scripts' + runs-on: 'ubuntu-latest' + needs: + - 'check_yaml_consistency' + steps: + - id: 'step-0' + uses: 'actions/checkout@v4' + - id: 'step-1' + run: |- + find -name *.main.kts -print0 | while read -d $'\0' file + do + echo "Compiling $file..." + kotlinc -Werror -Xallow-any-scripts-in-source-roots -Xuse-fir-lt=false "$file" + done + workflows_consistency_check: + name: 'Run consistency check on all GitHub workflows' + runs-on: 'ubuntu-latest' + needs: + - 'check_yaml_consistency' + steps: + - id: 'step-0' + uses: 'actions/checkout@v4' + - id: 'step-1' + run: 'cd .github/workflows' + - id: 'step-2' + name: 'Regenerate all workflow YAMLs' + run: |- + find -name "*.main.kts" -print0 | while read -d $'\0' file + do + if [ -x "$file" ]; then + echo "Regenerating $file..." + ($file) + fi + done + - id: 'step-3' + name: 'Check if some file is different after regeneration' + run: 'git diff --exit-code .'