diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 01daabf..cbb97d5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,6 +18,25 @@ variables: services: - docker:dind +run-pre-commit: + stage: .pre + image: golang:1.19 + variables: + PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit + cache: + - key: + files: + - .pre-commit-config.yaml + paths: + - ${PRE_COMMIT_HOME} + before_script: + - apt update && apt install -y python3 python3-pip ruby git + - go install github.com/lietu/go-pre-commit@latest + - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0 + - pip install pre-commit + script: + - pre-commit run --all-files + build: extends: .buildtools stage: build @@ -30,7 +49,7 @@ build: vulnerabilities: stage: build - image: golang:1.19.2 + image: golang:1.19.4 script: - go install golang.org/x/vuln/cmd/govulncheck@latest - govulncheck ./... diff --git a/.gitlab/dependabot.yml b/.gitlab/dependabot.yml new file mode 100644 index 0000000..d8b8153 --- /dev/null +++ b/.gitlab/dependabot.yml @@ -0,0 +1,17 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: +- package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 5 +- package-ecosystem: "docker" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 5 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cc06e3e..1136595 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -19,7 +19,7 @@ repos: hooks: - id: gitlab-ci-linter - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook - rev: v9.1.0 + rev: v9.3.0 hooks: - id: commitlint stages: [ commit-msg ] @@ -30,7 +30,10 @@ repos: - id: errcheck - id: go-fmt-goimports - id: go-test - - id: go-vet - id: golangci-lint - id: gofumpt - id: staticcheck +- repo: https://github.com/dnephin/pre-commit-golang + rev: v0.5.1 + hooks: + - id: go-mod-tidy diff --git a/Dockerfile b/Dockerfile index 158c5b4..8fefde1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,7 @@ -FROM golang:1.19.2 as build +FROM golang:1.19.4 as build WORKDIR /build ENV CGO_ENABLED=0 ADD . /build -RUN if [ $(go mod tidy -v 2>&1 | grep -c unused) != 0 ]; then echo "Unused modules, please run 'go mod tidy'"; exit 1; fi -RUN go fmt ./... -RUN go vet ./... RUN CGO_ENABLED=1 go test -mod=readonly -race -coverprofile=coverage.txt.tmp -covermode=atomic -coverpkg=$(go list ./... | tr '\n' , | sed 's/,$//') ./... RUN ["/bin/bash", "-c", "cat coverage.txt.tmp | grep -v testing.go | grep -v -f <(find . -type f | xargs grep -l 'Code generated') > coverage.txt"] RUN go tool cover -html=coverage.txt -o coverage.html