From ef5d8242c19a219777c0cbc0bbaad0972807a8d4 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Tue, 10 Dec 2024 12:36:03 +0100 Subject: [PATCH] build: include '*.yml' files (#33) Signed-off-by: Jendrik Johannes --- ...iero.gradle.check.spotless-yaml.gradle.kts | 2 +- .../hiero/gradle/test/ConventionPluginTest.kt | 2 +- .../org/hiero/gradle/test/QualityGateTest.kt | 40 +++++++++++++++++++ .../gradle/test/fixtures/GradleProject.kt | 2 + 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/test/kotlin/org/hiero/gradle/test/QualityGateTest.kt diff --git a/src/main/kotlin/org.hiero.gradle.check.spotless-yaml.gradle.kts b/src/main/kotlin/org.hiero.gradle.check.spotless-yaml.gradle.kts index 887dc22..0109312 100644 --- a/src/main/kotlin/org.hiero.gradle.check.spotless-yaml.gradle.kts +++ b/src/main/kotlin/org.hiero.gradle.check.spotless-yaml.gradle.kts @@ -3,7 +3,7 @@ plugins { id("com.diffplug.spotless") } spotless { format("actionYaml") { - target(".github/workflows/*.yaml") + target(".github/workflows/*.yaml", ".github/workflows/*.yml") /* * Prettier requires NodeJS and NPM installed; however, the NodeJS Gradle plugin and Spotless do not yet * integrate with each other. Currently there is an open issue report against spotless. diff --git a/src/test/kotlin/org/hiero/gradle/test/ConventionPluginTest.kt b/src/test/kotlin/org/hiero/gradle/test/ConventionPluginTest.kt index 8f4f172..bc18194 100644 --- a/src/test/kotlin/org/hiero/gradle/test/ConventionPluginTest.kt +++ b/src/test/kotlin/org/hiero/gradle/test/ConventionPluginTest.kt @@ -45,7 +45,7 @@ class ConventionPluginTest { .listFiles()!! .filter { it.isFile && it.name.endsWith(".gradle.kts") } .map { it.name.substringBeforeLast(".gradle.kts") } - return pluginList.toTypedArray() + return pluginList.sorted().toTypedArray() } } } diff --git a/src/test/kotlin/org/hiero/gradle/test/QualityGateTest.kt b/src/test/kotlin/org/hiero/gradle/test/QualityGateTest.kt new file mode 100644 index 0000000..c134906 --- /dev/null +++ b/src/test/kotlin/org/hiero/gradle/test/QualityGateTest.kt @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: Apache-2.0 +package org.hiero.gradle.test + +import org.assertj.core.api.Assertions.assertThat +import org.gradle.testkit.runner.TaskOutcome +import org.hiero.gradle.test.fixtures.GradleProject +import org.junit.jupiter.api.Test + +class QualityGateTest { + + @Test + fun `qualityGate formats yml and yaml files`() { + val p = GradleProject().withMinimalStructure() + val flow1 = p.file(".github/workflows/flow1.yml", "name: Flow 1 ") + val flow2 = p.file(".github/workflows/flow2.yaml", "name: Flow 2 ") + val txtFile = p.file(".github/workflows/temp.txt", "name: Flow 3 ") + + val result = p.qualityGate() + + assertThat(flow1) + .hasContent( + """ + # SPDX-License-Identifier: Apache-2.0 + name: Flow 1 + """ + .trimIndent() + ) + assertThat(flow2) + .hasContent( + """ + # SPDX-License-Identifier: Apache-2.0 + name: Flow 2 + """ + .trimIndent() + ) + assertThat(txtFile).hasContent("name: Flow 3 ") // unchanged + + assertThat(result.task(":qualityGate")?.outcome).isEqualTo(TaskOutcome.SUCCESS) + } +} diff --git a/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt b/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt index d3cd661..012980c 100644 --- a/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt +++ b/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt @@ -109,6 +109,8 @@ class GradleProject { fun failQualityCheck(): BuildResult = runner(listOf("qualityCheck")).buildAndFail() + fun qualityGate(): BuildResult = runner(listOf("qualityGate")).build() + private fun File.writeFormatted(content: String) { writeText("$expectedHeader$content\n") }