Skip to content
Snippets Groups Projects
Commit 5a78d9d8 authored by Anoop Mazhavancheri's avatar Anoop Mazhavancheri Committed by Pierre Smeyers
Browse files

feat: optional installation of Go tools

In case Go tools used in the template (govulncheck, gocover-cobertura, go-junit-report, go-mod-outdated) are already available in the container image, the template skips their installation
parent 00a69a39
Branches
Tags
No related merge requests found
...@@ -342,9 +342,12 @@ stages: ...@@ -342,9 +342,12 @@ stages:
log_info "--- \\e[32mCoverage report(s) found\\e[0m (\\e[33;1m${coverage_out}\\e[0m): output" log_info "--- \\e[32mCoverage report(s) found\\e[0m (\\e[33;1m${coverage_out}\\e[0m): output"
percent=$(go tool cover -func="$coverage_out" | tail -1 | awk -F" " '{print $NF}') percent=$(go tool cover -func="$coverage_out" | tail -1 | awk -F" " '{print $NF}')
echo "${percent} covered" echo "${percent} covered"
if ! command -v gocover-cobertura > /dev/null
go get github.com/boumenot/gocover-cobertura then
GOFLAGS="$GO_COBERTURA_FLAGS" go run github.com/boumenot/gocover-cobertura < "$coverage_out" > reports/go-coverage.cobertura.xml log_info "Installing gocover-cobertura.."
go install github.com/boumenot/gocover-cobertura@latest
fi
GOFLAGS="$GO_COBERTURA_FLAGS" gocover-cobertura < "$coverage_out" > reports/go-coverage.cobertura.xml
else else
log_info "--- \\e[32mCoverage report(s) not found\\e[0m: skip" log_info "--- \\e[32mCoverage report(s) not found\\e[0m: skip"
fi fi
...@@ -419,7 +422,7 @@ stages: ...@@ -419,7 +422,7 @@ stages:
# produce JUnit report (for GitLab) # produce JUnit report (for GitLab)
install_go_junit_report install_go_junit_report
"$GOBIN/go-junit-report" < "$go_text_report" > reports/go-test.xunit.xml go-junit-report < "$go_text_report" > reports/go-test.xunit.xml
# produce JSON report (for SonarQube) # produce JSON report (for SonarQube)
go tool test2json < "$go_text_report" > reports/go-test.native.json go tool test2json < "$go_text_report" > reports/go-test.native.json
...@@ -429,17 +432,25 @@ stages: ...@@ -429,17 +432,25 @@ stages:
} }
function install_go_junit_report() { function install_go_junit_report() {
if ! command -v go-junit-report > /dev/null
then
cd "$(mktemp -d)" cd "$(mktemp -d)"
go mod init go-junit-report go mod init go-junit-report
log_info "Installing go-junit-report.."
go install github.com/jstemmer/go-junit-report@latest go install github.com/jstemmer/go-junit-report@latest
cd - cd -
fi
} }
function install_go_mod_outdated() { function install_go_mod_outdated() {
if ! command -v go-mod-outdated > /dev/null
then
cd "$(mktemp -d)" cd "$(mktemp -d)"
go mod init go-mod-outdated go mod init go-mod-outdated
log_info "Installing go-mod-outdated.."
go install github.com/psampaz/go-mod-outdated@latest go install github.com/psampaz/go-mod-outdated@latest
cd - cd -
fi
} }
function install_go_govulncheck() { function install_go_govulncheck() {
...@@ -483,6 +494,7 @@ stages: ...@@ -483,6 +494,7 @@ stages:
fi fi
- install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
- cd ${GO_PROJECT_DIR} - cd ${GO_PROJECT_DIR}
- export PATH=$GOBIN:$PATH
go-generate: go-generate:
extends: .go-base extends: .go-base
...@@ -601,9 +613,9 @@ go-mod-outdated: ...@@ -601,9 +613,9 @@ go-mod-outdated:
- go $GO_LIST_ARGS > reports/go-list.native.json - go $GO_LIST_ARGS > reports/go-list.native.json
- install_go_mod_outdated - install_go_mod_outdated
# console output (no fail) # console output (no fail)
- $GOBIN/go-mod-outdated $GO_MOD_OUTDATED_ARGS < reports/go-list.native.json - go-mod-outdated $GO_MOD_OUTDATED_ARGS < reports/go-list.native.json
# text report (-ci fails) # text report (-ci fails)
- $GOBIN/go-mod-outdated $GO_MOD_OUTDATED_ARGS -ci < reports/go-list.native.json > reports/go-mod-outdated.native.txt - go-mod-outdated $GO_MOD_OUTDATED_ARGS -ci < reports/go-list.native.json > reports/go-mod-outdated.native.txt
artifacts: artifacts:
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG" name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
expire_in: 1 day expire_in: 1 day
...@@ -662,7 +674,7 @@ go-govulncheck: ...@@ -662,7 +674,7 @@ go-govulncheck:
script: script:
- mkdir -p -m 777 reports - mkdir -p -m 777 reports
- install_go_govulncheck - install_go_govulncheck
- $GOBIN/govulncheck ${GO_VULNCHECK_ARGS} - govulncheck ${GO_VULNCHECK_ARGS}
rules: rules:
# exclude if GO_CI_LINT_DISABLED set # exclude if GO_CI_LINT_DISABLED set
- if: '$GO_VULNCHECK_DISABLED == "true"' - if: '$GO_VULNCHECK_DISABLED == "true"'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment