ci: add pre-commit and remove those checks from Dockerfile

This commit is contained in:
2022-12-16 10:01:04 +01:00
parent d23423c8dc
commit 66a29713cf
4 changed files with 44 additions and 8 deletions
+20 -1
View File
@@ -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 ./...
+17
View File
@@ -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
+6 -3
View File
@@ -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
+1 -4
View File
@@ -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