From cfb7cc4f2feac5ed717fc753acf62b2ee131a092 Mon Sep 17 00:00:00 2001 From: Joakim Olsson Date: Fri, 30 Sep 2022 22:43:16 +0200 Subject: [PATCH 1/2] ci: add pre-commit config --- .pre-commit-config.yaml | 37 +++++++++++++++++++++++++++++++++++++ README.md | 5 ++++- gitlab/client_test.go | 1 - go.mod | 2 +- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ff232e5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,37 @@ +# 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.3.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files +- repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: markdownlint +- repo: https://github.com/golangci/golangci-lint + rev: v1.49.0 + hooks: + - id: golangci-lint +- 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.1.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: go-vet + - id: gofumpt + - id: staticcheck diff --git a/README.md b/README.md index 76b03fc..1bf8870 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # gitlab-cleanup-handler + [![Build Status](https://gitlab.com/unboundsoftware/gitlab-cleanup-handler/badges/master/pipeline.svg)](https://gitlab.com/unboundsoftware/gitlab-cleanup-handler/commits/master) [![codecov](https://codecov.io/gl/unboundsoftware/gitlab-cleanup-handler/branch/master/graph/badge.svg)](https://codecov.io/gl/unboundsoftware/gitlab-cleanup-handler) -A small container which checks which images from Gitlab container registry are used in the provided namespaces and updates the cleanup policies for those projects. +A small container which checks which images from Gitlab container registry +are used in the provided namespaces and updates the cleanup policies for +those projects. diff --git a/gitlab/client_test.go b/gitlab/client_test.go index c5029d7..dcb2f5f 100644 --- a/gitlab/client_test.go +++ b/gitlab/client_test.go @@ -87,7 +87,6 @@ func TestRestClient_GetTags(t *testing.T) { }, handler: func(t *testing.T) http.HandlerFunc { return func(writer http.ResponseWriter, request *http.Request) { - //writer.Header().Set("Content-Length", "23") writer.WriteHeader(http.StatusOK) _, _ = writer.Write([]byte(`[{"name":"1.0"},{"name": "1.1"}]`)) } diff --git a/go.mod b/go.mod index 00817b7..f1df52a 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/apex/log v1.9.0 github.com/stretchr/testify v1.7.2 gitlab.com/unboundsoftware/apex-mocks v0.2.0 + k8s.io/api v0.25.2 k8s.io/apimachinery v0.25.2 k8s.io/client-go v0.25.2 ) @@ -45,7 +46,6 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/api v0.25.2 // indirect k8s.io/klog/v2 v2.70.1 // indirect k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect -- 2.52.0 From 757dbe43497ab4c29a087788aa96df290da1a4b5 Mon Sep 17 00:00:00 2001 From: Joakim Olsson Date: Fri, 30 Sep 2022 23:46:11 +0200 Subject: [PATCH 2/2] ci: add checking of pre-commit rules --- .gitlab-ci.yml | 19 +++++++++++++++++++ .pre-commit-config.yaml | 5 +---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e55d456..0b60e8c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,6 +9,25 @@ variables: image: buildtool/build-tools:${BUILDTOOLS_VERSION} +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: stage: build services: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ff232e5..607ae00 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,10 +12,6 @@ repos: rev: 3.0.0 hooks: - id: markdownlint -- repo: https://github.com/golangci/golangci-lint - rev: v1.49.0 - hooks: - - id: golangci-lint - repo: https://gitlab.com/devopshq/gitlab-ci-linter rev: v1.0.3 hooks: @@ -33,5 +29,6 @@ repos: - id: go-fmt-goimports - id: go-test - id: go-vet + - id: golangci-lint - id: gofumpt - id: staticcheck -- 2.52.0