Loading templates/gitlab-ci-golang.yml +23 −15 Original line number Diff line number Diff line Loading @@ -134,19 +134,37 @@ stages: } function go_test() { mkdir reports local go_tests_report="reports/tests-output.txt" mkdir -p reports local go_text_report="reports/tests-output.txt" local go_json_report="reports/sonar-tests-report.json" local junit_tests_report="reports/junit-tests-report.xml" local coverage_report_opts=-coverprofile=reports/coverage.out # maybe produce Sonar test report (not failing) sonar_tests_report || true set +e # shellcheck disable=SC2086 go test $GO_TEST_FLAGS "$coverage_report_opts" $GO_TEST_PACKAGES | tee "$go_tests_report" go test $GO_TEST_FLAGS "$coverage_report_opts" $GO_TEST_PACKAGES > "$go_text_report" test_rc=$? set -e # dump text report in the console cat "$go_text_report" # compute and dump code coverage in the console output_coverage # produce JUnit report (for GitLab) install_go_junit_report # shellcheck disable=SC2002 cat "$go_tests_report" | "$GOBIN/go-junit-report" > "$junit_tests_report" sonar_tests_report cat "$go_text_report" | "$GOBIN/go-junit-report" > "$junit_tests_report" # produce JSON report (for SonarQube) cat "$go_text_report" | go tool test2json > "$go_json_report" # maybe fail if [[ "$test_rc" != "0" ]]; then exit "$test_rc"; fi } function install_go_junit_report() { Loading @@ -156,16 +174,6 @@ stages: cd - } function sonar_tests_report() { if [[ -n "$SONAR_URL" ]] then log_info "SonarQube template detected (\$SONAR_URL): generate tests report for SonarQube (\\e[33;1mreports/sonar-tests-report.json\\e[0m)" mkdir -p reports # shellcheck disable=SC2086 go test $GO_TEST_FLAGS -json $GO_TEST_PACKAGES > reports/sonar-tests-report.json fi } function sonar_lint_report() { if [[ "${SONAR_HOST_URL:-$SONAR_URL}" ]] then Loading Loading
templates/gitlab-ci-golang.yml +23 −15 Original line number Diff line number Diff line Loading @@ -134,19 +134,37 @@ stages: } function go_test() { mkdir reports local go_tests_report="reports/tests-output.txt" mkdir -p reports local go_text_report="reports/tests-output.txt" local go_json_report="reports/sonar-tests-report.json" local junit_tests_report="reports/junit-tests-report.xml" local coverage_report_opts=-coverprofile=reports/coverage.out # maybe produce Sonar test report (not failing) sonar_tests_report || true set +e # shellcheck disable=SC2086 go test $GO_TEST_FLAGS "$coverage_report_opts" $GO_TEST_PACKAGES | tee "$go_tests_report" go test $GO_TEST_FLAGS "$coverage_report_opts" $GO_TEST_PACKAGES > "$go_text_report" test_rc=$? set -e # dump text report in the console cat "$go_text_report" # compute and dump code coverage in the console output_coverage # produce JUnit report (for GitLab) install_go_junit_report # shellcheck disable=SC2002 cat "$go_tests_report" | "$GOBIN/go-junit-report" > "$junit_tests_report" sonar_tests_report cat "$go_text_report" | "$GOBIN/go-junit-report" > "$junit_tests_report" # produce JSON report (for SonarQube) cat "$go_text_report" | go tool test2json > "$go_json_report" # maybe fail if [[ "$test_rc" != "0" ]]; then exit "$test_rc"; fi } function install_go_junit_report() { Loading @@ -156,16 +174,6 @@ stages: cd - } function sonar_tests_report() { if [[ -n "$SONAR_URL" ]] then log_info "SonarQube template detected (\$SONAR_URL): generate tests report for SonarQube (\\e[33;1mreports/sonar-tests-report.json\\e[0m)" mkdir -p reports # shellcheck disable=SC2086 go test $GO_TEST_FLAGS -json $GO_TEST_PACKAGES > reports/sonar-tests-report.json fi } function sonar_lint_report() { if [[ "${SONAR_HOST_URL:-$SONAR_URL}" ]] then Loading