Skip to content

Commit 698c155

Browse files
committed
GitHub Actions for lint
Signed-off-by: CrazyMax <[email protected]>
1 parent 13e4a09 commit 698c155

File tree

8 files changed

+62
-88
lines changed

8 files changed

+62
-88
lines changed

.circleci/config.yml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,6 @@ version: 2
22

33
jobs:
44

5-
lint:
6-
working_directory: /work
7-
docker: [{image: 'docker:20.10-git'}]
8-
environment:
9-
DOCKER_BUILDKIT: 1
10-
steps:
11-
- checkout
12-
- setup_remote_docker:
13-
version: 20.10.6
14-
reusable: true
15-
exclusive: false
16-
- run:
17-
name: "Docker version"
18-
command: docker version
19-
- run:
20-
name: "Docker info"
21-
command: docker info
22-
- run:
23-
name: "Shellcheck - build image"
24-
command: |
25-
docker build --progress=plain -f dockerfiles/Dockerfile.shellcheck --tag cli-validator:$CIRCLE_BUILD_NUM .
26-
- run:
27-
name: "Shellcheck"
28-
command: |
29-
docker run --rm cli-validator:$CIRCLE_BUILD_NUM \
30-
make shellcheck
31-
- run:
32-
name: "Lint - build image"
33-
command: |
34-
docker build --progress=plain -f dockerfiles/Dockerfile.lint --tag cli-linter:$CIRCLE_BUILD_NUM .
35-
- run:
36-
name: "Lint"
37-
command: |
38-
docker run --rm cli-linter:$CIRCLE_BUILD_NUM
39-
405
cross:
416
working_directory: /work
427
docker: [{image: 'docker:20.10-git'}]
@@ -147,7 +112,6 @@ workflows:
147112
version: 2
148113
ci:
149114
jobs:
150-
- lint
151115
- cross
152116
- test
153117
- validate

.github/workflows/validate.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: validate
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'master'
8+
- '[0-9]+.[0-9]{2}'
9+
tags:
10+
- 'v*'
11+
pull_request:
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
target:
20+
- lint
21+
- shellcheck
22+
steps:
23+
-
24+
name: Checkout
25+
uses: actions/checkout@v2
26+
-
27+
name: Run
28+
uses: docker/bake-action@v1
29+
with:
30+
targets: ${{ matrix.target }}

Makefile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ test-coverage: ## run test coverage
2525
fmt:
2626
go list -f {{.Dir}} ./... | xargs gofmt -w -s -d
2727

28-
.PHONY: lint
29-
lint: ## run all the lint tools
30-
gometalinter --config gometalinter.json ./...
31-
3228
.PHONY: binary
3329
binary:
3430
docker buildx bake binary
@@ -71,10 +67,6 @@ manpages: ## generate man pages from go source and markdown
7167
yamldocs: ## generate documentation YAML files consumed by docs repo
7268
scripts/docs/generate-yaml.sh
7369

74-
.PHONY: shellcheck
75-
shellcheck: ## run shellcheck validation
76-
scripts/validate/shellcheck
77-
7870
.PHONY: help
7971
help: ## print this help
8072
@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)

docker-bake.hcl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,15 @@ target "cross" {
6161
target "dynbinary-cross" {
6262
inherits = ["dynbinary", "_all_platforms"]
6363
}
64+
65+
target "lint" {
66+
dockerfile = "./dockerfiles/Dockerfile.lint"
67+
target = "lint"
68+
output = ["type=cacheonly"]
69+
}
70+
71+
target "shellcheck" {
72+
dockerfile = "./dockerfiles/Dockerfile.shellcheck"
73+
target = "shellcheck"
74+
output = ["type=cacheonly"]
75+
}

docker.Makefile

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ DOCKER_CLI_GO_BUILD_CACHE ?= y
1111

1212
DEV_DOCKER_IMAGE_NAME = docker-cli-dev$(IMAGE_TAG)
1313
BINARY_NATIVE_IMAGE_NAME = docker-cli-native$(IMAGE_TAG)
14-
LINTER_IMAGE_NAME = docker-cli-lint$(IMAGE_TAG)
1514
CROSS_IMAGE_NAME = docker-cli-cross$(IMAGE_TAG)
16-
VALIDATE_IMAGE_NAME = docker-cli-shell-validate$(IMAGE_TAG)
1715
E2E_IMAGE_NAME = docker-cli-e2e$(IMAGE_TAG)
1816
E2E_ENGINE_VERSION ?=
1917
CACHE_VOLUME_NAME := docker-cli-dev-cache
@@ -32,17 +30,6 @@ build_docker_image:
3230
# build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment
3331
cat ./dockerfiles/Dockerfile.dev | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(DEV_DOCKER_IMAGE_NAME) -
3432

35-
# build docker image having the linting tools (dockerfiles/Dockerfile.lint)
36-
.PHONY: build_linter_image
37-
build_linter_image:
38-
# build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment
39-
cat ./dockerfiles/Dockerfile.lint | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(LINTER_IMAGE_NAME) -
40-
41-
.PHONY: build_shell_validate_image
42-
build_shell_validate_image:
43-
# build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment
44-
cat ./dockerfiles/Dockerfile.shellcheck | docker build --build-arg=GO_VERSION -t $(VALIDATE_IMAGE_NAME) -
45-
4633
.PHONY: build_binary_native_image
4734
build_binary_native_image:
4835
# 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
9279
shell: dev ## alias for dev
9380

9481
.PHONY: lint
95-
lint: build_linter_image ## run linters
96-
$(DOCKER_RUN) -it $(LINTER_IMAGE_NAME)
82+
lint: ## run linters
83+
docker buildx bake lint
9784

9885
.PHONY: fmt
9986
fmt: ## run gofmt
@@ -120,8 +107,8 @@ yamldocs: build_docker_image ## generate documentation YAML files consumed by do
120107
$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make yamldocs
121108

122109
.PHONY: shellcheck
123-
shellcheck: build_shell_validate_image ## run shellcheck validation
124-
$(DOCKER_RUN) -it $(VALIDATE_IMAGE_NAME) make shellcheck
110+
shellcheck: ## run shellcheck validation
111+
docker buildx bake shellcheck
125112

126113
.PHONY: test-e2e
127114
test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh ## run all e2e tests

dockerfiles/Dockerfile.lint

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
# syntax=docker/dockerfile:1.3
22

33
ARG GO_VERSION=1.16.6
4-
ARG GOLANGCI_LINTER_SHA="v1.21.0"
4+
ARG GOLANGCI_LINT_VERSION=v1.23.8
55

6-
FROM golang:${GO_VERSION}-alpine AS build
7-
ENV CGO_ENABLED=0
8-
RUN apk add --no-cache git
9-
ARG GOLANGCI_LINTER_SHA
10-
ARG GO111MODULE=on
11-
RUN --mount=type=cache,target=/root/.cache/go-build \
12-
--mount=type=cache,target=/go/pkg/mod \
13-
go get github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINTER_SHA}
6+
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
147

15-
FROM golang:${GO_VERSION}-alpine AS lint
16-
ENV GO111MODULE=off
17-
ENV CGO_ENABLED=0
18-
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
19-
COPY --from=build /go/bin/golangci-lint /usr/local/bin
8+
FROM golang:${GO_VERSION}-alpine AS lint
9+
ENV GO111MODULE=off
10+
ENV CGO_ENABLED=0
11+
ENV GOGC=75
2012
WORKDIR /go/src/github.com/docker/cli
21-
ENV GOGC=75
22-
ENTRYPOINT ["/usr/local/bin/golangci-lint"]
23-
CMD ["run", "--config=.golangci.yml"]
24-
COPY . .
13+
COPY --from=golangci-lint /usr/bin/golangci-lint /usr/bin/golangci-lint
14+
RUN --mount=type=bind,target=. \
15+
--mount=type=cache,target=/root/.cache \
16+
golangci-lint run

dockerfiles/Dockerfile.shellcheck

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
FROM koalaman/shellcheck-alpine:v0.7.1
2-
RUN apk add --no-cache bash make
1+
# syntax=docker/dockerfile:1.3
2+
3+
FROM koalaman/shellcheck-alpine:v0.7.1 AS shellcheck
34
WORKDIR /go/src/github.com/docker/cli
4-
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
5-
COPY . .
5+
RUN --mount=type=bind,target=. \
6+
set -eo pipefail; \
7+
find scripts/ contrib/completion/bash -type f | grep -v scripts/winresources | grep -v '.*.ps1' | xargs shellcheck

scripts/validate/shellcheck

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)