-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (48 loc) · 1.43 KB
/
test.yml
File metadata and controls
56 lines (48 loc) · 1.43 KB
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
name: Test
on:
pull_request:
push:
branches:
- main
permissions:
contents: read
jobs:
go-test:
runs-on: ubuntu-latest
env:
COVERAGE_MIN: "25.0"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
- id: coverage
name: Run go test with coverage
run: |
set -euo pipefail
go test ./... -covermode=atomic -coverprofile=coverage.out
go tool cover -func=coverage.out | tee coverage.txt
total="$(awk '/^total:/ {print $3}' coverage.txt)"
echo "total=${total}" >> "${GITHUB_OUTPUT}"
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-${{ github.sha }}
path: |
coverage.out
coverage.txt
if-no-files-found: error
- name: Publish test summary
run: |
echo "Total Go coverage: ${{ steps.coverage.outputs.total }}" >> "${GITHUB_STEP_SUMMARY}"
- name: Enforce minimum coverage
run: |
set -euo pipefail
total="${{ steps.coverage.outputs.total }}"
pct="${total%\%}"
min="${COVERAGE_MIN}"
awk -v pct="${pct}" -v min="${min}" 'BEGIN { exit !(pct+0 >= min+0) }' || {
echo "coverage gate failed: total=${total}, required>=${min}%"
exit 1
}