Merge pull request #4 from chris-crone/add-coverage

Add test coverage output
This commit is contained in:
Chris Crone
2020-08-12 19:00:28 +02:00
committed by GitHub
3 changed files with 13 additions and 2 deletions

View File

@@ -15,6 +15,8 @@ jobs:
run: make lint run: make lint
- name: Run unit tests - name: Run unit tests
run: make unit-test run: make unit-test
- name: Get unit test coverage
run: make unit-test-coverage
- name: Build Linux binary - name: Build Linux binary
run: make PLATFORM=linux/amd64 run: make PLATFORM=linux/amd64
- name: Build Windows binary - name: Build Windows binary

View File

@@ -1,6 +1,6 @@
# syntax = docker/dockerfile:1-experimental # 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 WORKDIR /src
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0
COPY go.* . COPY go.* .
@@ -16,7 +16,7 @@ RUN --mount=target=. \
FROM base AS unit-test FROM base AS unit-test
RUN --mount=target=. \ RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \ --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 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 \ --mount=type=cache,target=/root/.cache/golangci-lint \
golangci-lint run --timeout 10m0s ./... 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 FROM scratch AS bin-unix
COPY --from=build /out/example / COPY --from=build /out/example /

View File

@@ -13,6 +13,12 @@ bin/example:
unit-test: unit-test:
@docker build . --target 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 .PHONY: lint
lint: lint:
@docker build . --target lint @docker build . --target lint