diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 13ba7b846efe8ab18e05b30e049ed07033197351..e52a95227098229fac36d6a59bb7e337658bb506 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,31 +1,37 @@ +# variables in the GitLab CI/CD variables: + # GITLAB_TOKEN to support the semantic-release + # DOCKER_AUTH_CONFIG to support the usage of private docker images as job docker image + # TMPL_RELEASE_ENABLED to enable the semantic-release job + # TBC_NAMESPACE: smartdatalab/public/ci-cd-components + include: - - component: git.code.tecnalia.com/smartdatalab/public/ci-cd-components/gitlab-ci/extract@master + - component: $CI_SERVER_FQDN/$TBC_NAMESPACE/gitlab-ci/extract@master inputs: extract-script-job-tags: ["docker"] - - component: git.code.tecnalia.com/smartdatalab/public/ci-cd-components/gitlab-ci/validation@master + - component: $CI_SERVER_FQDN/$TBC_NAMESPACE/gitlab-ci/validation@master inputs: check-links-job-tags: ["docker"] tbc-check-job-tags: ["docker"] tbc-check-image: cicd-docker-dev.artifact.tecnalia.com/tbc-check:master gitlab-ci-lint-job-tags: ["docker"] - - component: git.code.tecnalia.com/smartdatalab/public/ci-cd-components/kicker/validation@master + - component: $CI_SERVER_FQDN/$TBC_NAMESPACE/kicker/validation@master inputs: kicker-validation-job-tags: ["docker"] schema-base-url: "https://git.code.tecnalia.com/api/v4/projects/smartdatalab%2Fpublic%2Fci-cd-components%2Fkicker/repository/files" - - component: git.code.tecnalia.com/smartdatalab/public/ci-cd-components/bash/gitlab-ci-bash@master + yajsv-image: "cicd-docker-dev.artifact.tecnalia.com/yajsv:latest" + - component: $CI_SERVER_FQDN/$TBC_NAMESPACE/bash/gitlab-ci-bash@master inputs: bash-shellcheck-job-tags: ["docker"] - - component: git.code.tecnalia.com/smartdatalab/public/ci-cd-components/semantic-release/gitlab-ci-semrel@master + shellcheck-files: "*.sh" + - component: $CI_SERVER_FQDN/$TBC_NAMESPACE/semantic-release/gitlab-ci-semrel@master inputs: semantic-release-job-tags: ["docker"] - -stages: - - build - - publish + - component: $CI_SERVER_FQDN/$TBC_NAMESPACE/gitleaks/gitlab-ci-gitleaks@master + inputs: + gitleaks-job-tags: ["docker"] variables: GITLAB_CI_FILES: "templates/gitlab-ci-golang.yml" - BASH_SHELLCHECK_FILES: "*.sh" GIT_STRATEGY: clone semantic-release: diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b29a96df8e85ed05a5bb0b67a43b8d63a011cdc..2747da4711efeebf8b4f723b8ec8f17d540e3608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,9 @@ -## [4.9.1](https://git.code.tecnalia.com/smartdatalab/public/ci-cd-components/golang/compare/4.9.0...4.9.1) (2024-07-02) +## [4.9.2](https://gitlab.com/to-be-continuous/golang/compare/4.9.1...4.9.2) (2024-07-02) ### Bug Fixes -* **workflow:** disable MR pipeline from prod & integ branches ([de9419c](https://git.code.tecnalia.com/smartdatalab/public/ci-cd-components/golang/commit/de9419ce66b9dcbc10a8cdcb6b15e52f8aae43e2)) +* go-build rule when build & test are run separately ([9c27782](https://gitlab.com/to-be-continuous/golang/commit/9c2778281bb93a12c3376cb128f8c53e9860b826)) ## [4.9.1](https://gitlab.com/to-be-continuous/golang/compare/4.9.0...4.9.1) (2024-05-05) diff --git a/README.md b/README.md index 6caffa844d1da94030e6e6789b53225b4612d581..e887205c3ac1ee96650b2397e04f2490cb54597c 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,17 @@ This project implements a GitLab CI/CD template to build, test and analyse your ## Usage -This template can be used both as a [CI/CD component](https://docs.gitlab.com/ee/ci/components/#use-a-component-in-a-cicd-configuration) +This template can be used both as a [CI/CD component](https://docs.gitlab.com/ee/ci/components/#use-a-component) or using the legacy [`include:project`](https://docs.gitlab.com/ee/ci/yaml/index.html#includeproject) syntax. ### Use as a CI/CD component -Add the following to your `gitlab-ci.yml`: +Add the following to your `.gitlab-ci.yml`: ```yaml include: # 1: include the component - - component: gitlab.com/to-be-continuous/golang/gitlab-ci-golang@4.9.1 + - component: $CI_SERVER_FQDN/to-be-continuous/golang/gitlab-ci-golang@4.10.0 # 2: set/override component inputs inputs: image: "registry.hub.docker.com/library/golang:buster" # ⚠ this is only an example @@ -22,13 +22,13 @@ include: ### Use as a CI/CD template (legacy) -Add the following to your `gitlab-ci.yml`: +Add the following to your `.gitlab-ci.yml`: ```yaml include: # 1: include the template - project: 'to-be-continuous/golang' - ref: '4.9.1' + ref: '4.10.0' file: '/templates/gitlab-ci-golang.yml' variables: diff --git a/templates/gitlab-ci-golang.yml b/templates/gitlab-ci-golang.yml index 843c4925277726c5643887841ccfe590db21c577..fd16d8e4e92ca7c11433be2f2eb0b04260b03305 100644 --- a/templates/gitlab-ci-golang.yml +++ b/templates/gitlab-ci-golang.yml @@ -375,9 +375,12 @@ stages: 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}') echo "${percent} covered" - - go get github.com/boumenot/gocover-cobertura - GOFLAGS="$GO_COBERTURA_FLAGS" go run github.com/boumenot/gocover-cobertura < "$coverage_out" > reports/go-coverage.cobertura.xml + if ! command -v gocover-cobertura > /dev/null + then + 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 log_info "--- \\e[32mCoverage report(s) not found\\e[0m: skip" fi @@ -452,7 +455,7 @@ stages: # produce JUnit report (for GitLab) 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) go tool test2json < "$go_text_report" > reports/go-test.native.json @@ -462,17 +465,25 @@ stages: } function install_go_junit_report() { - cd "$(mktemp -d)" - go mod init go-junit-report - go install github.com/jstemmer/go-junit-report@latest - cd - + if ! command -v go-junit-report > /dev/null + then + cd "$(mktemp -d)" + go mod init go-junit-report + log_info "Installing go-junit-report.." + go install github.com/jstemmer/go-junit-report@latest + cd - + fi } function install_go_mod_outdated() { - cd "$(mktemp -d)" - go mod init go-mod-outdated - go install github.com/psampaz/go-mod-outdated@latest - cd - + if ! command -v go-mod-outdated > /dev/null + then + cd "$(mktemp -d)" + go mod init go-mod-outdated + log_info "Installing go-mod-outdated.." + go install github.com/psampaz/go-mod-outdated@latest + cd - + fi } function install_go_govulncheck() { @@ -495,7 +506,7 @@ stages: image: $GO_IMAGE services: - name: "$TBC_TRACKING_IMAGE" - command: ["--service", "golang", "4.9.1"] + command: ["--service", "golang", "4.10.0"] variables: # The directory where 'go install' will install a command. GOBIN: "$CI_PROJECT_DIR/$GO_PROJECT_DIR/bin" @@ -516,6 +527,7 @@ stages: fi - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - cd ${GO_PROJECT_DIR} + - export PATH=$GOBIN:$PATH go-generate: extends: .go-base @@ -639,9 +651,9 @@ go-mod-outdated: - go $GO_LIST_ARGS > reports/go-list.native.json - install_go_mod_outdated # 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) - - $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: name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG" expire_in: 1 day @@ -702,7 +714,7 @@ go-govulncheck: script: - mkdir -p -m 777 reports - install_go_govulncheck - - $GOBIN/govulncheck ${GO_VULNCHECK_ARGS} + - govulncheck ${GO_VULNCHECK_ARGS} rules: # exclude if GO_CI_LINT_DISABLED set - if: '$GO_VULNCHECK_DISABLED == "true"'