Please enter the gitlab-ci coordinator URL: # gitlab的url, gitlab->你的项目->settings -> CI/CD ->Runners settings Please enter the gitlab-ci token for this runner: # gitlab->你的项目->settings -> CI/CD ->Runners settings Please enter the gitlab-ci description for this runner: # 示例:mitaka-runner1 Please enter the gitlab-ci tags for this runner (comma separated): # 示例:golang Whether to run untagged builds [true/false]: # true // 可以运行不加tag的builds Please enter the executor: docker, parallels, shell, kubernetes, docker-ssh, ssh, virtualbox, docker+machine, docker-ssh+machine: # docker // 使用容器 Please enter the default Docker image (e.g. ruby:2.1): # go-tools:1.19.6(之前自己制作的镜像)
#!/bin/bash # # Code coverage generation COVERAGE_DIR="${COVERAGE_DIR:-coverage}" PKG_LIST=$(go list ./... | grep -v /vendor/) # Create the coverage files directory mkdir -p "$COVERAGE_DIR" # Create a coverage file for each package for package in ${PKG_LIST}; do go test -covermode=count -coverprofile "${COVERAGE_DIR}/${package##*/}.cov" "$package" done # Merge the coverage profile files echo 'mode: count' >"${COVERAGE_DIR}"/coverage.cov tail -q -n +2 "${COVERAGE_DIR}"/*.cov >>"${COVERAGE_DIR}"/coverage.cov # Display the global code coverage go tool cover -func="${COVERAGE_DIR}"/coverage.cov # If needed, generate HTML report if [ "$1" == "html" ]; then go tool cover -html="${COVERAGE_DIR}"/coverage.cov -o coverage.html fi # Remove the coverage files directory rm -rf "$COVERAGE_DIR"
# go build检测 build: stage: build script: - go env -w GOMODCACHE=$(pwd)/.mod_cache/ GOPROXY=https://goproxy.cn,direct - go mod tidy - make build cache: key: $(md5sum go.mod) paths: - .mod_cache/ tags: - golang
# 单元测试 unit_tests: stage: test script: - go env -w GOMODCACHE=$(pwd)/.mod_cache/ GOPROXY=https://goproxy.cn,direct - go mod tidy - make test cache: key: $(md5sum go.mod) paths: - .mod_cache/ tags: - golang
# 竞态检测 race_detector: stage: test script: - go env -w GOMODCACHE=$(pwd)/.mod_cache/ GOPROXY=https://goproxy.cn,direct - go mod tidy - make race cache: key: $(md5sum go.mod) paths: - .mod_cache/ tags: - golang
# 代码覆盖率检测 code_coverage: stage: test script: - go env -w GOMODCACHE=$(pwd)/.mod_cache/ GOPROXY=https://goproxy.cn,direct - go mod tidy - make coverage cache: key: $(md5sum go.mod) paths: - .mod_cache/ tags: - golang
# 代码覆盖率导出成html code_coverage_report: stage: test script: - go env -w GOMODCACHE=$(pwd)/.mod_cache/ GOPROXY=https://goproxy.cn,direct - go mod tidy - make coverhtml cache: key: $(md5sum go.mod) paths: - .mod_cache/ only: - master tags: - golang
# golangci-lint代码检测 golangci-lint_code: stage: test script: - go env -w GOMODCACHE=$(pwd)/.mod_cache/ GOPROXY=https://goproxy.cn,direct - go mod tidy - make golangci-lint cache: key: $(md5sum go.mod) paths: - .mod_cache/ tags: - golang