From 4ce67e609795903633e043c4e9d1fd7b5447effa Mon Sep 17 00:00:00 2001 From: Sarah French <15078782+SarahFrench@users.noreply.github.com> Date: Mon, 16 Oct 2023 14:41:07 +0100 Subject: [PATCH] TeamCity: Update build step so tests only run if there are tests to run (#9236) * Update build step so tests only run if there are tests to run * Add guard against empty folders --- .../components/generated/build_components.erb | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/.teamcity/components/generated/build_components.erb b/mmv1/third_party/terraform/.teamcity/components/generated/build_components.erb index 83e6570fe690..36363fbd5a8a 100644 --- a/mmv1/third_party/terraform/.teamcity/components/generated/build_components.erb +++ b/mmv1/third_party/terraform/.teamcity/components/generated/build_components.erb @@ -117,14 +117,40 @@ fun BuildSteps.RunAcceptanceTests() { } else { step(ScriptBuildStep { name = "Compile Test Binary" - scriptContent = "go test -c -o test-binary" workingDir = "%PACKAGE_PATH%" + scriptContent = """ + #!/bin/bash + export TEST_FILE_COUNT=$(ls ./*_test.go | wc -l) + if test ${'$'}TEST_FILE_COUNT -gt "0"; then + echo "Compiling test binary" + go test -c -o test-binary + else + echo "Skipping compilation of test binary; no Go test files found" + fi + """.trimIndent() + }) step(ScriptBuildStep { name = "Run via jen20/teamcity-go-test" - scriptContent = "./test-binary -test.list=\"%TEST_PREFIX%\" | teamcity-go-test -test ./test-binary -parallelism \"%PARALLELISM%\" -timeout \"%TIMEOUT%h\"" workingDir = "%PACKAGE_PATH%" + scriptContent = """ + #!/bin/bash + if ! test -f "./test-binary"; then + echo "Skipping test execution; file ./test-binary does not exist." + exit 0 + fi + + export TEST_COUNT=${'$'}(./test-binary -test.list=%TEST_PREFIX% | wc -l) + echo "Found ${'$'}{TEST_COUNT} tests that match the given test prefix %TEST_PREFIX%" + if test ${'$'}TEST_COUNT -le "0"; then + echo "Skipping test execution; no tests to run" + exit 0 + fi + + echo "Starting tests" + ./test-binary -test.list="%TEST_PREFIX%" | teamcity-go-test -test ./test-binary -parallelism "%PARALLELISM%" -timeout "%TIMEOUT%h" + """.trimIndent() }) } }