diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 321e765..3419f57 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,6 +15,8 @@ jobs: run: make lint - name: Run unit tests run: make unit-test + - name: Get unit test coverage + run: make unit-test-coverage - name: Build Linux binary run: make PLATFORM=linux/amd64 - name: Build Windows binary diff --git a/Dockerfile b/Dockerfile index c22710f..9a0b24f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax = docker/dockerfile:1-experimental -FROM --platform=${BUILDPLATFORM} golang:1.14.3-alpine AS base +FROM --platform=${BUILDPLATFORM} golang:1.15.0-alpine AS base WORKDIR /src ENV CGO_ENABLED=0 COPY go.* . @@ -16,7 +16,7 @@ RUN --mount=target=. \ FROM base AS unit-test RUN --mount=target=. \ --mount=type=cache,target=/root/.cache/go-build \ - go test -v . + mkdir /out && go test -v -coverprofile=/out/cover.out ./... FROM golangci/golangci-lint:v1.27-alpine AS lint-base @@ -27,6 +27,9 @@ RUN --mount=target=. \ --mount=type=cache,target=/root/.cache/golangci-lint \ golangci-lint run --timeout 10m0s ./... +FROM scratch AS unit-test-coverage +COPY --from=unit-test /out/cover.out /cover.out + FROM scratch AS bin-unix COPY --from=build /out/example / diff --git a/Makefile b/Makefile index 9ea71d8..3b52188 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,12 @@ bin/example: unit-test: @docker build . --target unit-test +.PHONY: unit-test-coverage +unit-test-coverage: + @docker build . --target unit-test-coverage \ + --output coverage/ + cat coverage/cover.out + .PHONY: lint lint: @docker build . --target lint