diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 018b82e..69f40c9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,97 @@ -include: - - project: 'martinr92/gitlab-ci' - file: '.gitlab-ci-gomod-build-template.yml' +image: golang:1.16 + +stages: + - test + - sonarcloud + - build + +checks: + stage: test + script: + - go fmt $(go list ./...) + - go vet $(go list ./...) + +code coverage: + stage: test + script: + - go install honnef.co/go/tools/cmd/staticcheck@latest + - go fmt $(go list ./...) + - go vet $(go list ./...) + - staticcheck ./... + - go test -coverprofile coverage.cov -p 1 $(go list ./...) + - go tool cover -html=coverage.cov -o coverage.html + - go tool cover -func=coverage.cov + coverage: '/\(statements\)\W+\d+\.\d+%/' + artifacts: + paths: + - coverage.cov + - coverage.html + +codecov.io: + stage: test + script: + - curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --import + - curl -Os https://uploader.codecov.io/latest/linux/codecov + - curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM + - curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig + - gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM + - shasum -a 256 -c codecov.SHA256SUM + - chmod +x codecov + - go test -race -coverprofile=coverage.out -covermode=atomic + - ./codecov -t ${CODECOV_TOKEN} + rules: + - if: $CODECOV_TOKEN + when: on_success + +# stage "sonarcloud" is only needed because of this issue: +# https://gitlab.com/gitlab-org/gitlab/-/issues/30632 +sonarcloud-check: + stage: test + needs: + - checks + image: + name: sonarsource/sonar-scanner-cli:latest + entrypoint: [""] + variables: + SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache + GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task + cache: + key: "${CI_JOB_NAME}" + paths: + - .sonar/cache + script: + - sonar-scanner + allow_failure: true + +# build template +# execute the following command for all os/arch combinations: go tool dist list +.compile: + stage: build + # no dependencies -> no download of artifacts from previous jobs/stages + dependencies: [] + script: + - go build . + +darwin-amd64: + extends: .compile + variables: + GOOS: "darwin" + GOARCH: "amd64" + +linux-amd64: + extends: .compile + variables: + GOOS: "linux" + GOARCH: "amd64" + +linux-arm64: + extends: .compile + variables: + GOOS: "linux" + GOARCH: "arm64" + +windows-amd64: + extends: .compile + variables: + GOOS: "windows" + GOARCH: "amd64"