-
Notifications
You must be signed in to change notification settings - Fork 20
188 lines (160 loc) · 4.77 KB
/
Copy pathpr-checks.yml
File metadata and controls
188 lines (160 loc) · 4.77 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: PR Checks
on:
pull_request:
branches:
- main
- dev
push:
branches:
- main
- dev
workflow_dispatch:
permissions:
contents: read
pull-requests: read
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.24']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache: true
- name: Verify dependencies
run: go mod verify
- name: Build for current platform
run: make build
- name: Build for all supported platforms
run: make build-all
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache: true
- name: Run tests
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Generate coverage report
run: go tool cover -html=coverage.out -o coverage.html
- name: Upload coverage to artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
coverage.out
coverage.html
- name: Check test coverage
run: |
coverage=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
echo "Total test coverage: ${coverage}%"
# Set minimum coverage threshold (can be adjusted)
threshold=30
if (( $(echo "$coverage < $threshold" | bc -l) )); then
echo "::warning::Test coverage ${coverage}% is below threshold ${threshold}%"
echo "Please consider adding more tests to improve coverage."
else
echo "✅ Test coverage ${coverage}% meets threshold ${threshold}%"
fi
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: latest
args: --timeout=5m
security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache: true
- name: Run Gosec Security Scanner
run: |
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec -fmt=sarif -out=results.sarif -no-fail ./...
# Remove invalid fixes from SARIF to prevent upload errors
jq 'del(.runs[].results[].fixes)' results.sarif > results-clean.sarif
mv results-clean.sarif results.sarif
continue-on-error: true
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: results.sarif
category: gosec
code-quality:
name: Code Quality Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache: true
- name: Check go fmt
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "❌ Go code is not formatted. Please run 'make fmt' or 'gofmt -s -w .'"
echo ""
echo "Unformatted files:"
gofmt -s -l .
exit 1
fi
echo "✅ All files are properly formatted"
- name: Check goimports
run: |
go install golang.org/x/tools/cmd/goimports@latest
if [ "$(goimports -l . | wc -l)" -gt 0 ]; then
echo "❌ Go imports are not properly formatted. Please run 'goimports -w .'"
echo ""
echo "Files with incorrect imports:"
goimports -l .
exit 1
fi
echo "✅ All imports are properly formatted"
- name: Check go vet
run: go vet ./...
- name: Check for common mistakes with staticcheck
uses: dominikh/staticcheck-action@v1
with:
version: "latest"
install-go: false
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v4
with:
fail-on-severity: moderate