Repository navigation
103 lines (87 loc) · 3.32 KB
/
Copy pathtest.yml
File metadata and controls
103 lines (87 loc) · 3.32 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
# Minimum test coverage percentage required to pass CI.
# Current: ~50%. Target: gradually increase to 55 -> 60 -> 70.
env:
COVERAGE_THRESHOLD: 50
# No job here writes to the repo, so the default token stays read-only.
permissions:
contents: read
jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: ['1.26.11']
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Go
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version: ${{ matrix.go }}
- name: Download dependencies
run: go mod download
- name: Verify code compiles
shell: bash
run: go build ./...
# Other packages still use Unix-only locks and third-party code that
# does not build for js/wasm. pkg/output is the library a browser
# build imports, so keep that target compiling (issue #831).
- name: Verify pkg/output builds for js/wasm
shell: bash
run: GOOS=js GOARCH=wasm go build ./pkg/output/...
- name: Run go vet
shell: bash
run: go vet ./...
# The race detector and coverage instrumentation run on ubuntu only: they
# roughly triple the test time, and the race reports and the coverage
# threshold do not depend on the OS. macOS and Windows still run every
# test, for the platform-specific code paths.
- name: Run tests
shell: bash
run: |
pkgs=$(go list ./... | grep -v ./pkg/proto/livedebugger)
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
go test -race -coverprofile=coverage.txt -covermode=atomic $pkgs
else
go test $pkgs
fi
- name: Enforce coverage threshold
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
COVERAGE=$(go tool cover -func=coverage.txt | grep total | awk '{print $3}' | sed 's/%//')
echo "Total coverage: ${COVERAGE}%"
echo "Threshold: ${COVERAGE_THRESHOLD}%"
if [ -z "$COVERAGE" ]; then
echo "::error::Could not determine coverage percentage"
exit 1
fi
# Compare as integers (truncate decimals) to avoid bc dependency
COVERAGE_INT=${COVERAGE%.*}
if [ "$COVERAGE_INT" -lt "$COVERAGE_THRESHOLD" ]; then
echo "::error::Coverage ${COVERAGE}% is below the ${COVERAGE_THRESHOLD}% threshold"
exit 1
fi
echo "Coverage ${COVERAGE}% meets the ${COVERAGE_THRESHOLD}% threshold"
- name: Generate coverage report
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
echo "### Coverage Report" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
go tool cover -func=coverage.txt | tail -20 >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
files: ./coverage.txt
fail_ci_if_error: false