Skip to content

Commit d5eb64c

Browse files
committed
Add coverage to GitHub actions.
1 parent 27da79f commit d5eb64c

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

.github/workflows/coverage.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches: master
6+
pull_request:
7+
branches: master
8+
9+
jobs:
10+
coverage:
11+
runs-on: ubuntu-latest
12+
steps:
13+
14+
- uses: actions/checkout@v2
15+
16+
- name: Set up Go 1.17
17+
uses: actions/setup-go@v1
18+
with:
19+
go-version: 1.17
20+
21+
- name: Coverage
22+
id: coverage
23+
run: |
24+
go test -v -coverprofile=cov.out ./...
25+
go tool cover -html=cov.out -o coverage.html
26+
COV=$(go tool cover -func=cov.out | awk '/total/ { gsub("%", "", $3); print $3 }')
27+
(( $(echo "${COV} > ${MIN_COV}" | bc -l) )) && STATE=success || STATE=failure
28+
echo "::set-output name=COV::${COV}% (Required ${MIN_COV}%)"
29+
echo "::set-output name=STATE::${STATE}"
30+
env:
31+
MIN_COV: 70
32+
33+
- uses: Sibz/github-status-action@v1
34+
with:
35+
authToken: ${{secrets.GITHUB_TOKEN}}
36+
description: '${{steps.coverage.outputs.COV}}'
37+
context: ${{github.jobs.coverage.name}}
38+
state: '${{steps.coverage.outputs.STATE}}'
39+
sha: ${{github.event.pull_request.head.sha || github.sha}}
40+
41+
- uses: actions/upload-artifact@v2
42+
with:
43+
name: coverage
44+
path: coverage.html
45+
retention-days: 7

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313

1414
- uses: actions/checkout@v2
1515

16-
- name: Set up Go 1.15
16+
- name: Set up Go 1.17
1717
uses: actions/setup-go@v1
1818
with:
19-
go-version: 1.15
19+
go-version: 1.17
2020

2121
- name: golangci-lint
2222
uses: golangci/golangci-lint-action@v2

0 commit comments

Comments
 (0)