Skip to content

Commit

Permalink
GitHub Actions for lint
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jul 26, 2021
1 parent 2776a6d commit 2580dea
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 40 deletions.
21 changes: 10 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ jobs:
docker: [{image: 'docker:20.10-git'}]
environment:
DOCKER_BUILDKIT: 1
BUILDX_VERSION: "v0.6.0"
BUILDKIT_PROGRESS: "plain"
DISABLE_WARN_OUTSIDE_CONTAINER: 1
steps:
- checkout
- setup_remote_docker:
Expand All @@ -19,23 +22,19 @@ jobs:
- 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: apk add make curl
- run: mkdir -vp ~/.docker/cli-plugins/
- run: curl -fsSL --output ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-amd64
- run: chmod a+x ~/.docker/cli-plugins/docker-buildx
- run: docker buildx version
- 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 .
make shellcheck
- run:
name: "Lint"
command: |
docker run --rm cli-linter:$CIRCLE_BUILD_NUM
make lint
cross:
working_directory: /work
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: validate

on:
workflow_dispatch:
push:
branches:
- 'master'
tags:
- 'v*'
pull_request:
branches:
- 'master'

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 }}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fmt:

.PHONY: lint
lint: ## run all the lint tools
gometalinter --config gometalinter.json ./...
docker buildx bake lint

.PHONY: binary
binary:
Expand Down Expand Up @@ -73,7 +73,7 @@ yamldocs: ## generate documentation YAML files consumed by docs repo

.PHONY: shellcheck
shellcheck: ## run shellcheck validation
scripts/validate/shellcheck
docker buildx bake shellcheck

.PHONY: help
help: ## print this help
Expand Down
12 changes: 12 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
31 changes: 13 additions & 18 deletions dockerfiles/Dockerfile.lint
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
# syntax=docker/dockerfile:1.3

ARG GO_VERSION=1.13.15
ARG GOLANGCI_LINTER_SHA="v1.21.0"
ARG GOLANGCI_LINT_VERSION=v1.21.0

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 golang:${GO_VERSION}-alpine AS lint
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 base
WORKDIR /go/src/github.com/docker/cli
ENV GOGC=75
ENTRYPOINT ["/usr/local/bin/golangci-lint"]
CMD ["run", "--config=.golangci.yml"]
COPY . .

FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint

FROM base AS lint
ENV CGO_ENABLED=0
ENV GOGC=75
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/.cache/golangci-lint \
--mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
golangci-lint run --config .golangci.yml ./...
13 changes: 9 additions & 4 deletions dockerfiles/Dockerfile.shellcheck
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
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 base
RUN apk add --no-cache bash
WORKDIR /go/src/github.com/docker/cli
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
COPY . .

FROM base AS shellcheck
RUN --mount=type=bind,target=. \
shellcheck contrib/completion/bash/docker \
&& find scripts/ -type f | grep -v scripts/winresources | grep -v '.*.ps1' | xargs shellcheck
5 changes: 0 additions & 5 deletions scripts/validate/shellcheck

This file was deleted.

0 comments on commit 2580dea

Please sign in to comment.