From 26a586cf39831db7afab1ad97cc8556734919ffb Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 3 May 2022 12:51:31 +0200 Subject: [PATCH 1/2] lint target and workflow job Signed-off-by: CrazyMax --- .github/workflows/validate.yml | 1 + Makefile | 16 +++++++++------- docker-bake.hcl | 7 ++++++- dockerfiles/lint.Dockerfile | 16 ++++++++++++++++ 4 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 dockerfiles/lint.Dockerfile diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index a5b3df8f5..9a5b4dec2 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -18,6 +18,7 @@ jobs: fail-fast: false matrix: target: + - lint - validate-vendor steps: - diff --git a/Makefile b/Makefile index d30459a2d..2f58f44f7 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ BINARIES=$(addprefix bin/,$(COMMANDS)) TESTFLAGS ?= -v $(TESTFLAGS_RACE) TESTFLAGS_PARALLEL ?= 8 -.PHONY: all build binaries check clean test test-race test-full integration coverage validate-vendor vendor mod-outdated +.PHONY: all build binaries clean test test-race test-full integration coverage validate lint validate-vendor vendor mod-outdated .DEFAULT: all all: binaries @@ -48,10 +48,6 @@ version/version.go: @echo "$(WHALE) $@" ./version/version.sh > $@ -check: ## run all linters (TODO: enable "unused", "varcheck", "ineffassign", "unconvert", "staticheck", "goimports", "structcheck") - @echo "$(WHALE) $@" - @golangci-lint run - test: ## run tests, except integration test with test.short @echo "$(WHALE) $@" @go test ${GO_TAGS} -test.short ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}) @@ -101,8 +97,14 @@ clean: ## clean up binaries @echo "$(WHALE) $@" @rm -f $(BINARIES) +validate: ## run all validators + docker buildx bake $@ + +lint: ## run all linters + docker buildx bake $@ + validate-vendor: ## validate vendor - docker buildx bake validate-vendor + docker buildx bake $@ vendor: ## update vendor $(eval $@_TMP_OUT := $(shell mktemp -d -t buildx-output.XXXXXXXXXX)) @@ -112,4 +114,4 @@ vendor: ## update vendor rm -rf $($@_TMP_OUT)/* mod-outdated: ## check outdated dependencies - docker buildx bake mod-outdated + docker buildx bake $@ diff --git a/docker-bake.hcl b/docker-bake.hcl index a6fb56220..4b776fccc 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -3,7 +3,12 @@ group "default" { } group "validate" { - targets = ["validate-vendor"] + targets = ["lint", "validate-vendor"] +} + +target "lint" { + dockerfile = "./dockerfiles/lint.Dockerfile" + output = ["type=cacheonly"] } target "validate-vendor" { diff --git a/dockerfiles/lint.Dockerfile b/dockerfiles/lint.Dockerfile new file mode 100644 index 000000000..e9d8c8f3c --- /dev/null +++ b/dockerfiles/lint.Dockerfile @@ -0,0 +1,16 @@ +# syntax=docker/dockerfile:1 + +ARG GO_VERSION=1.17 +ARG GOLANGCI_LINT_VERSION=v1.44 + +FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint + +FROM golang:${GO_VERSION}-alpine AS base +RUN apk add --no-cache gcc musl-dev +WORKDIR /src + +FROM base +RUN --mount=type=bind,target=. \ + --mount=type=cache,target=/root/.cache \ + --mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \ + golangci-lint run From 7548c315f813916116f4f0af58e5da66f3f4d66e Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 1 May 2022 05:34:19 +0200 Subject: [PATCH 2/2] cleanup old check behavior Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 2 -- script/setup/install-dev-tools | 15 --------------- 2 files changed, 17 deletions(-) delete mode 100755 script/setup/install-dev-tools diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50657e460..d8c977535 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,9 +46,7 @@ jobs: working-directory: ./src/github.com/distribution/distribution run: | DCO_VERBOSITY=-q script/validate/dco - GO111MODULE=on script/setup/install-dev-tools go build -i . - make check make build make binaries if [ "$GOOS" = "linux" ]; then make coverage ; fi diff --git a/script/setup/install-dev-tools b/script/setup/install-dev-tools deleted file mode 100755 index f848981a0..000000000 --- a/script/setup/install-dev-tools +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -GOLANGCI_LINT_VERSION="v1.44.0" - -# -# Install developer tools to $GOBIN (or $GOPATH/bin if unset) -# -set -eu -o pipefail - -# Enable Go modules -export GO111MODULE=on - -# prevent updating go.mod of the project -cd /tmp -go get "github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}"