-
Notifications
You must be signed in to change notification settings - Fork 13
61 lines (50 loc) · 1.93 KB
/
tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.5
- id: last_coverage
name: Get last coverage
run: |
echo "COV=$(go tool cover -func=coverage.out | tail -1 | awk '{ print $3 }' | sed s/%//g)" >> "$GITHUB_OUTPUT"
- id: this_coverage
name: Get current coverage
run: |
go test -coverprofile=coverage.out
echo "COV=$(go tool cover -func=coverage.out | tail -1 | awk '{ print $3 }' | sed s/%//g)" >> "$GITHUB_OUTPUT"
- name: Function Coverage
run: go tool cover -func=coverage.out
- id: coverage_dropped
name: Check if coverage dropped
run: |
cov_drop=$(echo ${{steps.last_coverage.outputs.COV}}'>'${{steps.this_coverage.outputs.COV}} | bc -l)
echo "Has it dropped? $cov_drop"
echo "DROP=$cov_drop" >> "$GITHUB_OUTPUT"
- name: If coverage has dropped
if: ${{ steps.coverage_dropped.outputs.DROP == '1' }}
run: |
echo "Coverage has dropped from ${{ steps.last_coverage.outputs.COV }}% to ${{ steps.this_coverage.outputs.COV }}%"
exit 1
- name: If coverage has not dropped
if: ${{ steps.coverage_dropped.outputs.DROP == '0' }}
run: |
echo -e "Previous coverage: ${{ steps.last_coverage.outputs.COV }}\nCurrent coverage: ${{ steps.this_coverage.outputs.COV }}"
- name: Get coverage badge
run: |
total=${{ steps.this_coverage.outputs.COV }}
curl "https://img.shields.io/badge/coverage-$total%25-green" > coverage.svg
- name: Add coverage info
uses: EndBug/[email protected]
with:
add: "coverage.svg coverage.out"
message: "Update coverage.svg and coverage.out"