-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (83 loc) · 2.65 KB
/
Copy pathtest.yml
File metadata and controls
99 lines (83 loc) · 2.65 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
name: Test Suite
on:
push:
pull_request:
permissions:
contents: read
checks: write
pull-requests: write
jobs:
format:
name: Check Formatting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.26.x'
cache: true
- name: Check Go formatting
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "The following files are not formatted correctly:"
echo "$unformatted"
echo ""
echo "Please run 'gofmt -w .' to format your code"
exit 1
fi
echo "All Go files are properly formatted"
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.26.x'
cache: true
- name: Download dependencies
run: go mod download
- name: Install go-junit-report
run: go install github.com/jstemmer/go-junit-report/v2@latest
- name: Run tests with coverage
run: |
go test ./... -v -race -coverprofile=coverage.out -covermode=atomic 2>&1 | tee test-output.txt || true
cat test-output.txt | go-junit-report -set-exit-code > test-results.xml
- name: Generate coverage report
run: |
echo "## Test Coverage Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
go tool cover -func=coverage.out | tail -n 1 | awk '{print "**Total Coverage: " $3 "**"}' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Coverage by Package" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Package | Coverage |" >> $GITHUB_STEP_SUMMARY
echo "|---------|----------|" >> $GITHUB_STEP_SUMMARY
go tool cover -func=coverage.out | grep -v "total:" | awk '{print "| " $1 " | " $3 " |"}' | sort -u >> $GITHUB_STEP_SUMMARY
- name: Test Report
uses: dorny/test-reporter@v3
if: always()
with:
name: Go Test Results
path: test-results.xml
reporter: 'java-junit'
fail-on-error: true
fail-on-empty: true
- name: Upload coverage to GitHub
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: coverage.out
- name: Check test results
run: |
if grep -q 'failures="[1-9]' test-results.xml || grep -q 'errors="[1-9]' test-results.xml; then
echo "Some tests failed"
exit 1
else
echo "All tests passed"
fi