amseltools/Earthfile

91 lines
1.9 KiB
Plaintext

VERSION 0.7
ARG --global GO_VERSION=1.20.3
ARG --global GOLANGCILINT_VERSION=1.51.2
ARG --global GORELEASER_VERSION=1.17.0
ARG --global GOTESTSUM_VERSION=1.9.0
FROM golang:$GO_VERSION-alpine3.16
WORKDIR /amseltools
SAVE_CODE:
COMMAND
SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum
SAVE ARTIFACT *.go AS LOCAL .
ci:
BUILD +lint
BUILD +test
BUILD +build
code:
COPY go.mod go.sum ./
COPY *.go ./
COPY --dir vendor ./
COPY --dir internal ./
SAVE ARTIFACT . code
install-deps:
FROM +base
RUN set -ex \
&& apk add --no-cache \
build-base \
coreutils \
git
RUN go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANGCILINT_VERSION
RUN go install -v github.com/goreleaser/goreleaser@v$GORELEASER_VERSION
RUN go install -v gotest.tools/gotestsum@v$GOTESTSUM_VERSION
RUN go install -v golang.org/x/tools/cmd/stringer@latest
SAVE ARTIFACT /go/bin gobin
SAVE ARTIFACT /lib lib
SAVE ARTIFACT /usr usr
deps:
COPY +install-deps/gobin /go/bin
COPY +install-deps/lib /lib
COPY +install-deps/usr /usr
generate:
FROM +deps
COPY +code/code .
RUN go generate ./...
DO +SAVE_CODE
test:
FROM +deps
COPY +code/code ./
RUN gotestsum \
--junitfile report.xml \
--format standard-verbose \
-- \
-race \
-cover -coverprofile=coverage.out \
-failfast \
./... \
-timeout=120m
SAVE ARTIFACT report.xml AS LOCAL report.xml
SAVE ARTIFACT coverage.out AS LOCAL coverage.out
lint:
FROM +deps
COPY +code/code ./
RUN golangci-lint run
tidy:
RUN apk add --no-cache git
COPY +code/code ./
RUN go mod tidy
RUN go mod vendor
SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum
SAVE ARTIFACT vendor AS LOCAL vendor
build:
FROM +deps
COPY . .
RUN goreleaser build --snapshot --clean
release:
FROM +deps
COPY . .
RUN --secret GITEA_TOKEN goreleaser release --clean