httprouter/.gitlab-ci.yml

125 lines
3.1 KiB
YAML

image: golang:1.19
stages:
- test
- build
- pre-release
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"
.semantic-release:
stage: pre-release
image: node:20-buster-slim
dependencies: []
before_script:
- apt-get update && apt-get install -y --no-install-recommends git-core ca-certificates
- npm install -g semantic-release@23 @semantic-release/gitlab@13 conventional-changelog-conventionalcommits@7
script:
- semantic-release -d $DRY_RUN
variables:
GL_TOKEN: $SEMANTIC_RELEASE_TOKEN
DRY_RUN: "false"
tags:
- docker
semantic-release-dry-run:
extends: .semantic-release
variables:
DRY_RUN: "true"
rules:
- if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "beta"'
semantic-release:
extends: .semantic-release
rules:
- if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "beta"'
when: manual