File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,18 @@ FROM gobase AS base
3030ARG TARGETPLATFORM
3131RUN xx-apk add musl-dev gcc libsecret-dev pass
3232
33+ FROM base AS test
34+ RUN --mount=type=bind,target=. \
35+ --mount=type=cache,target=/root/.cache \
36+ --mount=type=cache,target=/go/pkg/mod <<EOT
37+ set -e
38+ xx-go test -short -v -coverprofile=/tmp/coverage.txt -covermode=atomic ./...
39+ xx-go tool cover -func=/tmp/coverage.txt
40+ EOT
41+
42+ FROM scratch AS test-coverage
43+ COPY --from=test /tmp/coverage.txt /coverage.txt
44+
3345FROM base AS build-linux
3446ARG TARGETOS
3547ARG TARGETARCH
Original file line number Diff line number Diff line change 11variable "GO_VERSION" {
22 default = " 1.16.7"
33}
4+
5+ # Defines the output folder
46variable "DESTDIR" {
5- default = " ./bin"
7+ default = " "
8+ }
9+ function "bindir" {
10+ params = [defaultdir ]
11+ result = DESTDIR != " " ? DESTDIR : " ./bin/${ defaultdir } "
612}
713
814target "_common" {
@@ -15,10 +21,16 @@ group "default" {
1521 targets = [" binaries" ]
1622}
1723
24+ target "test" {
25+ inherits = [" _common" ]
26+ target = " test-coverage"
27+ output = [bindir (" coverage" )]
28+ }
29+
1830target "binaries" {
1931 inherits = [" _common" ]
2032 target = " binaries"
21- output = [DESTDIR ]
33+ output = [bindir ( " build " ) ]
2234 platforms = [
2335 " darwin/amd64" ,
2436 " darwin/arm64" ,
You can’t perform that action at this time.
0 commit comments