Skip to content

Commit

Permalink
Merge pull request #218 from crazy-max/lint-multi-platform
Browse files Browse the repository at this point in the history
enable golangci-lint for supported platforms
  • Loading branch information
tonistiigi authored Nov 4, 2024
2 parents c057952 + 312907a commit 8d32dbd
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
target:
- lint
- lint-cross
- validate-generated-files
- validate-gomod
- validate-shfmt
Expand Down
14 changes: 8 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
run:
timeout: 10m
skip-files:
- ".*\\.pb\\.go$"
timeout: 30m

linters:
enable:
Expand All @@ -25,6 +23,10 @@ linters-settings:
- pkg: "io/ioutil"
desc: The io/ioutil package has been deprecated.

# show all
max-issues-per-linter: 0
max-same-issues: 0
issues:
exclude-files:
- ".*\\.pb\\.go$"

# show all
max-issues-per-linter: 0
max-same-issues: 0
1 change: 1 addition & 0 deletions chtimes_nolinux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux

package fsutil
Expand Down
9 changes: 0 additions & 9 deletions copy/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ import (
"github.com/tonistiigi/fsutil"
)

// requiresRoot skips tests that require root
func requiresRoot(t *testing.T) {
t.Helper()
if os.Getuid() != 0 {
t.Skip("skipping test that requires root")
return
}
}

// TODO: Create copy directory which requires privilege
// chown
// mknod
Expand Down
9 changes: 9 additions & 0 deletions copy/copy_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,12 @@ func TestCopyModeTextFormat(t *testing.T) {
})
}
}

// requiresRoot skips tests that require root
func requiresRoot(t *testing.T) {
t.Helper()
if os.Getuid() != 0 {
t.Skip("skipping test that requires root")
return
}
}
1 change: 1 addition & 0 deletions copy/stat_bsd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build darwin || freebsd || netbsd
// +build darwin freebsd netbsd

package fs
Expand Down
1 change: 1 addition & 0 deletions copy/stat_openbsd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build openbsd
// +build openbsd

package fs
Expand Down
41 changes: 24 additions & 17 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ variable "DESTDIR" {
default = "./bin"
}

target "_platforms" {
platforms = [
"darwin/amd64",
"darwin/arm64",
"freebsd/amd64",
"freebsd/arm64",
"linux/386",
"linux/amd64",
"linux/arm",
"linux/arm64",
"linux/ppc64le",
"linux/s390x",
"openbsd/amd64",
"openbsd/arm64",
"windows/amd64",
"windows/arm64"
]
}

group "default" {
targets = ["build"]
}
Expand Down Expand Up @@ -40,6 +59,10 @@ target "lint" {
}
}

target "lint-cross" {
inherits = ["lint", "_platforms"]
}

target "validate-generated-files" {
dockerfile = "./hack/dockerfiles/generated-files.Dockerfile"
output = ["type=cacheonly"]
Expand Down Expand Up @@ -86,21 +109,5 @@ target "shfmt" {
}

target "cross" {
inherits = ["build"]
platforms = [
"linux/amd64",
"linux/386",
"linux/arm64",
"linux/arm",
"linux/ppc64le",
"linux/s390x",
"darwin/amd64",
"darwin/arm64",
"windows/amd64",
"windows/arm64",
"freebsd/amd64",
"freebsd/arm64",
"openbsd/amd64",
"openbsd/arm64"
]
inherits = ["build", "_platforms"]
}
9 changes: 7 additions & 2 deletions hack/dockerfiles/lint.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION=1.23
ARG XX_VERSION=1.5.0
ARG GOLANGCI_LINT_VERSION=1.61.0

FROM golang:${GO_VERSION}-alpine
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine
RUN apk add --no-cache git gcc musl-dev
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/tonistiigi/fsutil
ARG TARGETPLATFORM
RUN --mount=target=. \
--mount=target=/root/.cache,type=cache \
--mount=target=/root/.cache,type=cache,id=lint-cache-$TARGETPLATFORM \
--mount=target=/go/pkg/mod,type=cache \
xx-go --wrap && \
golangci-lint run
1 change: 1 addition & 0 deletions stat_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package fsutil
Expand Down

0 comments on commit 8d32dbd

Please sign in to comment.