Skip to content

Commit

Permalink
Check consistency and compilability of all GitHub workflows (#229)
Browse files Browse the repository at this point in the history
Now that we have a workflow that runs only on demand, and not in every
PR or on the `main` branch, it's beneficial to have these extra checks.

BTW, I noticed this piece is useful in almost every project, and I'm
planning to release some kind of util (a GitHub action?) that would
encapsulate this logic. It's tracked in
typesafegithub/github-workflows-kt#213

Examples of using this approach in other repos:
*
https://github.com/typesafegithub/github-workflows-kt/blob/0e91c566849a5883b39021a5ecbc18d25b006c1b/.github/workflows/build.main.kts#L95
*
https://github.com/typesafegithub/github-actions-typing-catalog/blob/667df7ec3fc639d19e278fc5956a9f753b26bb90/.github/workflows/test.main.kts#L14
  • Loading branch information
krzema12 authored Aug 21, 2024
1 parent 3487c55 commit 2e33c66
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/build.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,46 @@ workflow(
)
}
}

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 .",
)
}
}
38 changes: 38 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,41 @@ jobs:
- id: 'step-4'
name: 'Build'
run: './gradlew build --stacktrace'
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 .'

0 comments on commit 2e33c66

Please sign in to comment.