2023-02-23 00:45:10 +08:00
|
|
|
# syntax=docker/dockerfile:1
|
2019-03-23 04:29:28 +08:00
|
|
|
|
2024-11-07 20:46:47 +08:00
|
|
|
ARG GO_VERSION=1.23
|
2023-12-15 05:26:38 +08:00
|
|
|
ARG XX_VERSION=1.3.0
|
2024-11-07 20:53:54 +08:00
|
|
|
ARG GOLANGCI_LINT_VERSION=1.62.0
|
|
|
|
ARG GOPLS_VERSION=v0.26.0
|
2024-04-25 08:58:39 +08:00
|
|
|
# disabled: deprecated unusedvariable simplifyrange
|
2024-11-07 20:53:54 +08:00
|
|
|
ARG GOPLS_ANALYZERS="embeddirective fillreturns infertypeargs nonewvars norangeoverfunc noresultvalues simplifycompositelit simplifyslice undeclaredname unusedparams useany"
|
2021-09-03 05:11:05 +08:00
|
|
|
|
2023-12-15 05:26:38 +08:00
|
|
|
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
|
2024-04-25 08:20:27 +08:00
|
|
|
|
2024-04-25 08:58:39 +08:00
|
|
|
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS golang-base
|
2022-04-01 17:16:04 +08:00
|
|
|
RUN apk add --no-cache git gcc musl-dev
|
2024-04-25 08:58:39 +08:00
|
|
|
|
2024-07-13 07:18:42 +08:00
|
|
|
FROM golang-base AS lint-base
|
2023-10-19 18:24:07 +08:00
|
|
|
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}
|
2023-12-15 05:26:38 +08:00
|
|
|
COPY --link --from=xx / /
|
2019-04-25 10:29:56 +08:00
|
|
|
WORKDIR /go/src/github.com/docker/buildx
|
2023-12-15 05:26:38 +08:00
|
|
|
ARG TARGETPLATFORM
|
2024-07-13 07:18:42 +08:00
|
|
|
|
|
|
|
FROM lint-base AS lint
|
2023-10-19 18:24:07 +08:00
|
|
|
RUN --mount=target=/go/src/github.com/docker/buildx \
|
2023-12-15 05:26:38 +08:00
|
|
|
--mount=target=/root/.cache,type=cache,id=lint-cache-$TARGETPLATFORM \
|
|
|
|
xx-go --wrap && \
|
2023-10-19 18:24:07 +08:00
|
|
|
golangci-lint run
|
2024-04-25 08:58:39 +08:00
|
|
|
|
2024-07-13 07:18:42 +08:00
|
|
|
FROM lint-base AS validate-golangci
|
|
|
|
RUN --mount=target=/go/src/github.com/docker/buildx \
|
|
|
|
golangci-lint config verify
|
|
|
|
|
2024-04-25 08:58:39 +08:00
|
|
|
FROM golang-base AS gopls
|
|
|
|
RUN apk add --no-cache git
|
|
|
|
ARG GOPLS_VERSION
|
|
|
|
WORKDIR /src
|
|
|
|
RUN git clone https://github.com/golang/tools.git && \
|
|
|
|
cd tools && git checkout ${GOPLS_VERSION}
|
|
|
|
WORKDIR tools/gopls
|
|
|
|
ARG GOPLS_ANALYZERS
|
|
|
|
RUN <<'EOF'
|
|
|
|
set -ex
|
|
|
|
mkdir -p /out
|
|
|
|
for analyzer in ${GOPLS_ANALYZERS}; do
|
|
|
|
mkdir -p internal/cmd/$analyzer
|
|
|
|
cat <<eot > internal/cmd/$analyzer/main.go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/tools/go/analysis/singlechecker"
|
|
|
|
analyzer "golang.org/x/tools/gopls/internal/analysis/$analyzer"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() { singlechecker.Main(analyzer.Analyzer) }
|
|
|
|
eot
|
|
|
|
echo "Analyzing with ${analyzer}..."
|
|
|
|
go build -o /out/$analyzer ./internal/cmd/$analyzer
|
|
|
|
done
|
|
|
|
EOF
|
|
|
|
|
|
|
|
FROM golang-base AS gopls-analyze
|
|
|
|
COPY --link --from=xx / /
|
|
|
|
ARG GOPLS_ANALYZERS
|
|
|
|
ARG TARGETNAME
|
|
|
|
ARG TARGETPLATFORM
|
|
|
|
WORKDIR /go/src/github.com/docker/buildx
|
|
|
|
RUN --mount=target=. \
|
|
|
|
--mount=target=/root/.cache,type=cache,id=lint-cache-${TARGETNAME}-${TARGETPLATFORM} \
|
|
|
|
--mount=target=/gopls-analyzers,from=gopls,source=/out <<EOF
|
|
|
|
set -ex
|
|
|
|
xx-go --wrap
|
|
|
|
for analyzer in ${GOPLS_ANALYZERS}; do
|
|
|
|
go vet -vettool=/gopls-analyzers/$analyzer ./...
|
|
|
|
done
|
|
|
|
EOF
|
|
|
|
|
|
|
|
FROM lint
|