amseltools/Earthfile

91 lines
1.9 KiB
Plaintext
Raw Normal View History

2023-03-29 15:26:21 +02:00
VERSION 0.7
2023-04-05 10:15:05 +02:00
ARG --global GO_VERSION=1.20.3
2023-03-29 15:26:21 +02:00
ARG --global GOLANGCILINT_VERSION=1.51.2
2023-04-11 10:22:59 +02:00
ARG --global GORELEASER_VERSION=1.17.0
2023-03-29 15:26:21 +02:00
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
2023-03-30 09:36:08 +02:00
BUILD +build
2023-03-29 15:26:21 +02:00
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
2023-03-30 09:36:08 +02:00
build:
FROM +deps
COPY . .
RUN goreleaser build --snapshot --clean
release:
FROM +deps
COPY . .
2023-03-30 12:36:17 +02:00
RUN --secret GITEA_TOKEN goreleaser release --clean