-
Notifications
You must be signed in to change notification settings - Fork 15
177 lines (153 loc) · 4.33 KB
/
build.yml
File metadata and controls
177 lines (153 loc) · 4.33 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
name: Build & Verify Pipeline
on:
push:
branches: [main]
paths-ignore:
- "**.md"
- ".github/ISSUE_TEMPLATE/**"
- ".gitignore"
pull_request:
paths-ignore:
- "**.md"
- ".github/ISSUE_TEMPLATE/**"
- ".gitignore"
permissions:
contents: read
packages: write
id-token: write # Required for SLSA provenance
security-events: write # Required for uploading security results
pull-requests: read
checks: write
env:
GO_VERSION: "1.25.8"
jobs:
# Static analysis and code quality check
verify:
name: Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache: true
check-latest: true
- name: Install dependencies
run: |
go mod download
go mod verify
- name: Check Go mod tidy
run: |
go mod tidy
if ! git diff --quiet go.mod go.sum; then
echo "go.mod or go.sum is not tidy, run 'go mod tidy'"
git diff go.mod go.sum
exit 1
fi
- name: Install golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
args: --timeout=5m
install-mode: binary
skip-pkg-cache: true
skip-build-cache: true
- name: Run linters
run: golangci-lint run
# Security vulnerability scanning and SBOM generation
security:
name: Security Scan
runs-on: ubuntu-latest
needs: verify
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run Go Vulnerability Check
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
- name: Run dependency scan
uses: aquasecurity/trivy-action@v0.35.0
with:
scan-type: "fs"
scan-ref: "."
format: "sarif"
output: "trivy-results.sarif"
severity: "CRITICAL,HIGH,MEDIUM"
timeout: "10m"
- name: Upload security scan results
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-results.sarif"
- name: Generate SBOM
uses: anchore/sbom-action@v0.20.9
with:
format: spdx-json
output-file: sbom.spdx.json
- name: Upload SBOM
uses: actions/upload-artifact@v5
with:
name: sbom
path: sbom.spdx.json
retention-days: 30
# Run unit and integration tests with code coverage
test:
name: Run Tests
runs-on: ubuntu-latest
needs: verify
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run tests
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage
uses: codecov/codecov-action@v5
with:
file: ./coverage.txt
flags: unittests
fail_ci_if_error: false
# Simple build verification (for PRs and non-main branches)
build:
name: Build Verification
runs-on: ubuntu-latest
needs: [verify, security]
# Only run for PRs or pushes to non-main branches
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main')
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Build all packages
run: go build -v ./...
- name: Build examples
run: |
for example in $(find examples -name main.go 2>/dev/null); do
echo "Building $example..."
go build "$example"
done