From dcbdef35cf42eb99bf8d0f28e2ac09ec039a249f Mon Sep 17 00:00:00 2001 From: Joakim Olsson Date: Wed, 28 Dec 2022 20:06:28 +0100 Subject: [PATCH] ci: add pre-commit and remove those checks from test step --- .gitlab-ci.yml | 25 +++++++++++++++++++++---- .pre-commit-config.yaml | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2bf5596..eb0037a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,12 +1,31 @@ include: - template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml' -image: golang:1.19.1 +image: golang:1.19.4 stages: - deps - test +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 + deps: stage: deps script: @@ -17,8 +36,6 @@ test: dependencies: - deps script: - - go fmt $(go list ./...) - - go vet $(go list ./...) - CGO_ENABLED=1 go test -mod=readonly -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(go list ./... | tr '\n' , | sed 's/,$//') ./... - go tool cover -html=coverage.txt -o coverage.html - go tool cover -func=coverage.txt @@ -28,7 +45,7 @@ test: vulnerabilities: stage: test - image: golang:1.19.2 + image: golang:1.19.4 script: - go install golang.org/x/vuln/cmd/govulncheck@latest - govulncheck ./... diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..1136595 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,39 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + args: + - --allow-multiple-documents + - id: check-added-large-files +- repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: markdownlint +- repo: https://gitlab.com/devopshq/gitlab-ci-linter + rev: v1.0.3 + hooks: + - id: gitlab-ci-linter +- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook + rev: v9.3.0 + hooks: + - id: commitlint + stages: [ commit-msg ] + additional_dependencies: [ '@commitlint/config-conventional' ] +- repo: https://github.com/lietu/go-pre-commit + rev: v0.0.1 + hooks: + - id: errcheck + - id: go-fmt-goimports + - id: go-test + - id: golangci-lint + - id: gofumpt + - id: staticcheck +- repo: https://github.com/dnephin/pre-commit-golang + rev: v0.5.1 + hooks: + - id: go-mod-tidy