Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add yamllint #2595

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ body:
FROM alpine
echo hello
```

```hcl
group "default" {
targets = ["app"]
Expand All @@ -100,7 +100,7 @@ body:
target = "build"
}
```

```console
$ docker buildx build .
$ docker buildx bake
Expand Down
75 changes: 37 additions & 38 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,104 +1,103 @@

# Add 'area/project' label to changes in basic project documentation and .github folder, excluding .github/workflows
area/project:
- all:
- changed-files:
- any-glob-to-any-file:
- .github/**
- LICENSE
- AUTHORS
- MAINTAINERS
- PROJECT.md
- README.md
- .gitignore
- codecov.yml
- all-globs-to-all-files: '!.github/workflows/*'
- all:
- changed-files:
- any-glob-to-any-file:
- .github/**
- LICENSE
- AUTHORS
- MAINTAINERS
- PROJECT.md
- README.md
- .gitignore
- codecov.yml
- all-globs-to-all-files: '!.github/workflows/*'

# Add 'area/github-actions' label to changes in the .github/workflows folder
area/ci:
- changed-files:
- any-glob-to-any-file: '.github/workflows/**'
- any-glob-to-any-file: '.github/workflows/**'

# Add 'area/bake' label to changes in the bake
area/bake:
- changed-files:
- any-glob-to-any-file: 'bake/**'
- any-glob-to-any-file: 'bake/**'

# Add 'area/bake/compose' label to changes in the bake+compose
area/bake/compose:
- changed-files:
- any-glob-to-any-file:
- bake/compose.go
- bake/compose_test.go
- any-glob-to-any-file:
- bake/compose.go
- bake/compose_test.go

# Add 'area/build' label to changes in build files
area/build:
- changed-files:
- any-glob-to-any-file: 'build/**'
- any-glob-to-any-file: 'build/**'

# Add 'area/builder' label to changes in builder files
area/builder:
- changed-files:
- any-glob-to-any-file: 'builder/**'
- any-glob-to-any-file: 'builder/**'

# Add 'area/cli' label to changes in the CLI
area/cli:
- changed-files:
- any-glob-to-any-file:
- cmd/**
- commands/**
- any-glob-to-any-file:
- cmd/**
- commands/**

# Add 'area/controller' label to changes in the controller
area/controller:
- changed-files:
- any-glob-to-any-file: 'controller/**'
- any-glob-to-any-file: 'controller/**'

# Add 'area/docs' label to markdown files in the docs folder
area/docs:
- changed-files:
- any-glob-to-any-file: 'docs/**/*.md'
- any-glob-to-any-file: 'docs/**/*.md'

# Add 'area/dependencies' label to changes in go dependency files
area/dependencies:
- changed-files:
- any-glob-to-any-file:
- go.mod
- go.sum
- vendor/**
- any-glob-to-any-file:
- go.mod
- go.sum
- vendor/**

# Add 'area/driver' label to changes in the driver folder
area/driver:
- changed-files:
- any-glob-to-any-file: 'driver/**'
- any-glob-to-any-file: 'driver/**'

# Add 'area/driver/docker' label to changes in the docker driver
area/driver/docker:
- changed-files:
- any-glob-to-any-file: 'driver/docker/**'
- any-glob-to-any-file: 'driver/docker/**'

# Add 'area/driver/docker-container' label to changes in the docker-container driver
area/driver/docker-container:
- changed-files:
- any-glob-to-any-file: 'driver/docker-container/**'
- any-glob-to-any-file: 'driver/docker-container/**'

# Add 'area/driver/kubernetes' label to changes in the kubernetes driver
area/driver/kubernetes:
- changed-files:
- any-glob-to-any-file: 'driver/kubernetes/**'
- any-glob-to-any-file: 'driver/kubernetes/**'

# Add 'area/driver/remote' label to changes in the remote driver
area/driver/remote:
- changed-files:
- any-glob-to-any-file: 'driver/remote/**'
- any-glob-to-any-file: 'driver/remote/**'

# Add 'area/hack' label to changes in the hack folder
area/hack:
- changed-files:
- any-glob-to-any-file: 'hack/**'
- any-glob-to-any-file: 'hack/**'

# Add 'area/tests' label to changes in test files
area/tests:
- changed-files:
- any-glob-to-any-file:
- tests/**
- '**/*_test.go'
- any-glob-to-any-file:
- tests/**
- '**/*_test.go'
12 changes: 5 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
run:
timeout: 30m
skip-files:
- ".*\\.pb\\.go$"

modules-download-mode: vendor

build-tags:

linters:
enable:
- gofmt
Expand Down Expand Up @@ -57,6 +53,8 @@ linters-settings:
G306: "0644"

issues:
exclude-files:
- ".*\\.pb\\.go$"
exclude-rules:
- linters:
- revive
Expand All @@ -77,6 +75,6 @@ issues:
- revive
text: "if-return"

# show all
max-issues-per-linter: 0
max-same-issues: 0
# show all
max-issues-per-linter: 0
max-same-issues: 0
18 changes: 17 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ group "default" {
}

group "validate" {
targets = ["lint", "lint-gopls", "validate-vendor", "validate-docs"]
targets = ["lint", "lint-gopls", "lint-yaml", "validate-golangci", "validate-vendor", "validate-docs"]
}

target "lint" {
Expand All @@ -51,11 +51,27 @@ target "lint" {
] : []
}

target "validate-golangci" {
description = "Validate .golangci.yml schema (does not run Go linter)"
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/lint.Dockerfile"
target = "validate-golangci"
output = ["type=cacheonly"]
}

target "lint-gopls" {
inherits = ["lint"]
target = "gopls-analyze"
}

target "lint-yaml" {
description = "Lint Github Actions workflows and other YAML files"
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/lint.Dockerfile"
target = "yamllint"
output = ["type=cacheonly"]
}

target "validate-vendor" {
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
Expand Down
14 changes: 13 additions & 1 deletion hack/dockerfiles/lint.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS golang-base
RUN apk add --no-cache git gcc musl-dev

FROM golang-base AS lint
FROM golang-base AS lint-base
ENV GOFLAGS="-buildvcs=false"
ARG GOLANGCI_LINT_VERSION
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v${GOLANGCI_LINT_VERSION}
COPY --link --from=xx / /
WORKDIR /go/src/github.com/docker/buildx
ARG TARGETPLATFORM

FROM lint-base AS lint
RUN --mount=target=/go/src/github.com/docker/buildx \
--mount=target=/root/.cache,type=cache,id=lint-cache-$TARGETPLATFORM \
xx-go --wrap && \
golangci-lint run

FROM lint-base AS validate-golangci
RUN --mount=target=/go/src/github.com/docker/buildx \
golangci-lint config verify

FROM golang-base AS gopls
RUN apk add --no-cache git
ARG GOPLS_VERSION
Expand Down Expand Up @@ -69,4 +75,10 @@ RUN --mount=target=. \
done
EOF

FROM alpine AS yamllint
RUN apk add --no-cache yamllint
WORKDIR /go/src/github.com/docker/buildx
RUN --mount=type=bind \
yamllint -c .yamllint.yml --strict .

FROM lint
Loading