From 698c1554789cfad5c4ca8c5806b9e49165934f61 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 5 Aug 2021 08:44:16 +0200 Subject: [PATCH] GitHub Actions for lint Signed-off-by: CrazyMax --- .circleci/config.yml | 36 ------------------------------- .github/workflows/validate.yml | 30 ++++++++++++++++++++++++++ Makefile | 8 ------- docker-bake.hcl | 12 +++++++++++ docker.Makefile | 21 ++++-------------- dockerfiles/Dockerfile.lint | 28 +++++++++--------------- dockerfiles/Dockerfile.shellcheck | 10 +++++---- scripts/validate/shellcheck | 5 ----- 8 files changed, 62 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/validate.yml delete mode 100755 scripts/validate/shellcheck diff --git a/.circleci/config.yml b/.circleci/config.yml index ff29ae24c9..3e3fa75cdb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,41 +2,6 @@ version: 2 jobs: - lint: - working_directory: /work - docker: [{image: 'docker:20.10-git'}] - environment: - DOCKER_BUILDKIT: 1 - steps: - - checkout - - setup_remote_docker: - version: 20.10.6 - reusable: true - exclusive: false - - run: - name: "Docker version" - command: docker version - - run: - name: "Docker info" - command: docker info - - run: - name: "Shellcheck - build image" - command: | - docker build --progress=plain -f dockerfiles/Dockerfile.shellcheck --tag cli-validator:$CIRCLE_BUILD_NUM . - - run: - name: "Shellcheck" - command: | - docker run --rm cli-validator:$CIRCLE_BUILD_NUM \ - make shellcheck - - run: - name: "Lint - build image" - command: | - docker build --progress=plain -f dockerfiles/Dockerfile.lint --tag cli-linter:$CIRCLE_BUILD_NUM . - - run: - name: "Lint" - command: | - docker run --rm cli-linter:$CIRCLE_BUILD_NUM - cross: working_directory: /work docker: [{image: 'docker:20.10-git'}] @@ -147,7 +112,6 @@ workflows: version: 2 ci: jobs: - - lint - cross - test - validate diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000000..3a38110c7f --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,30 @@ +name: validate + +on: + workflow_dispatch: + push: + branches: + - 'master' + - '[0-9]+.[0-9]{2}' + tags: + - 'v*' + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: + - lint + - shellcheck + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Run + uses: docker/bake-action@v1 + with: + targets: ${{ matrix.target }} diff --git a/Makefile b/Makefile index 9e62210c33..a6cf0abb96 100644 --- a/Makefile +++ b/Makefile @@ -25,10 +25,6 @@ test-coverage: ## run test coverage fmt: go list -f {{.Dir}} ./... | xargs gofmt -w -s -d -.PHONY: lint -lint: ## run all the lint tools - gometalinter --config gometalinter.json ./... - .PHONY: binary binary: docker buildx bake binary @@ -71,10 +67,6 @@ manpages: ## generate man pages from go source and markdown yamldocs: ## generate documentation YAML files consumed by docs repo scripts/docs/generate-yaml.sh -.PHONY: shellcheck -shellcheck: ## run shellcheck validation - scripts/validate/shellcheck - .PHONY: help help: ## print this help @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) diff --git a/docker-bake.hcl b/docker-bake.hcl index 7443f4d627..08662a4c31 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -61,3 +61,15 @@ target "cross" { target "dynbinary-cross" { inherits = ["dynbinary", "_all_platforms"] } + +target "lint" { + dockerfile = "./dockerfiles/Dockerfile.lint" + target = "lint" + output = ["type=cacheonly"] +} + +target "shellcheck" { + dockerfile = "./dockerfiles/Dockerfile.shellcheck" + target = "shellcheck" + output = ["type=cacheonly"] +} diff --git a/docker.Makefile b/docker.Makefile index 4f582b7fb7..da1c708f3d 100644 --- a/docker.Makefile +++ b/docker.Makefile @@ -11,9 +11,7 @@ DOCKER_CLI_GO_BUILD_CACHE ?= y DEV_DOCKER_IMAGE_NAME = docker-cli-dev$(IMAGE_TAG) BINARY_NATIVE_IMAGE_NAME = docker-cli-native$(IMAGE_TAG) -LINTER_IMAGE_NAME = docker-cli-lint$(IMAGE_TAG) CROSS_IMAGE_NAME = docker-cli-cross$(IMAGE_TAG) -VALIDATE_IMAGE_NAME = docker-cli-shell-validate$(IMAGE_TAG) E2E_IMAGE_NAME = docker-cli-e2e$(IMAGE_TAG) E2E_ENGINE_VERSION ?= CACHE_VOLUME_NAME := docker-cli-dev-cache @@ -32,17 +30,6 @@ build_docker_image: # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment cat ./dockerfiles/Dockerfile.dev | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(DEV_DOCKER_IMAGE_NAME) - -# build docker image having the linting tools (dockerfiles/Dockerfile.lint) -.PHONY: build_linter_image -build_linter_image: - # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment - cat ./dockerfiles/Dockerfile.lint | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(LINTER_IMAGE_NAME) - - -.PHONY: build_shell_validate_image -build_shell_validate_image: - # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment - cat ./dockerfiles/Dockerfile.shellcheck | docker build --build-arg=GO_VERSION -t $(VALIDATE_IMAGE_NAME) - - .PHONY: build_binary_native_image build_binary_native_image: # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment @@ -92,8 +79,8 @@ dev: build_docker_image ## start a build container in interactive mode for in-co shell: dev ## alias for dev .PHONY: lint -lint: build_linter_image ## run linters - $(DOCKER_RUN) -it $(LINTER_IMAGE_NAME) +lint: ## run linters + docker buildx bake lint .PHONY: fmt fmt: ## run gofmt @@ -120,8 +107,8 @@ yamldocs: build_docker_image ## generate documentation YAML files consumed by do $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make yamldocs .PHONY: shellcheck -shellcheck: build_shell_validate_image ## run shellcheck validation - $(DOCKER_RUN) -it $(VALIDATE_IMAGE_NAME) make shellcheck +shellcheck: ## run shellcheck validation + docker buildx bake shellcheck .PHONY: test-e2e test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh ## run all e2e tests diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 6d272db227..37a5e0f1e2 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,24 +1,16 @@ # syntax=docker/dockerfile:1.3 ARG GO_VERSION=1.16.6 -ARG GOLANGCI_LINTER_SHA="v1.21.0" +ARG GOLANGCI_LINT_VERSION=v1.23.8 -FROM golang:${GO_VERSION}-alpine AS build -ENV CGO_ENABLED=0 -RUN apk add --no-cache git -ARG GOLANGCI_LINTER_SHA -ARG GO111MODULE=on -RUN --mount=type=cache,target=/root/.cache/go-build \ - --mount=type=cache,target=/go/pkg/mod \ - go get github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINTER_SHA} +FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint -FROM golang:${GO_VERSION}-alpine AS lint -ENV GO111MODULE=off -ENV CGO_ENABLED=0 -ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 -COPY --from=build /go/bin/golangci-lint /usr/local/bin +FROM golang:${GO_VERSION}-alpine AS lint +ENV GO111MODULE=off +ENV CGO_ENABLED=0 +ENV GOGC=75 WORKDIR /go/src/github.com/docker/cli -ENV GOGC=75 -ENTRYPOINT ["/usr/local/bin/golangci-lint"] -CMD ["run", "--config=.golangci.yml"] -COPY . . +COPY --from=golangci-lint /usr/bin/golangci-lint /usr/bin/golangci-lint +RUN --mount=type=bind,target=. \ + --mount=type=cache,target=/root/.cache \ + golangci-lint run diff --git a/dockerfiles/Dockerfile.shellcheck b/dockerfiles/Dockerfile.shellcheck index 188aadeb8a..80ba2e4e94 100644 --- a/dockerfiles/Dockerfile.shellcheck +++ b/dockerfiles/Dockerfile.shellcheck @@ -1,5 +1,7 @@ -FROM koalaman/shellcheck-alpine:v0.7.1 -RUN apk add --no-cache bash make +# syntax=docker/dockerfile:1.3 + +FROM koalaman/shellcheck-alpine:v0.7.1 AS shellcheck WORKDIR /go/src/github.com/docker/cli -ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 -COPY . . +RUN --mount=type=bind,target=. \ + set -eo pipefail; \ + find scripts/ contrib/completion/bash -type f | grep -v scripts/winresources | grep -v '.*.ps1' | xargs shellcheck diff --git a/scripts/validate/shellcheck b/scripts/validate/shellcheck deleted file mode 100755 index 63cedf137b..0000000000 --- a/scripts/validate/shellcheck +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail - -shellcheck contrib/completion/bash/docker -find scripts/ -type f | grep -v scripts/winresources | grep -v '.*.ps1' | xargs shellcheck