1+ name : Build & Verify Pipeline
2+
3+ on :
4+ push :
5+ branches : [ master ]
6+ paths-ignore :
7+ - " **.MD"
8+ - " .gitignore"
9+ pull_request :
10+ paths-ignore :
11+ - " **.MD"
12+ - " .gitignore"
13+
14+ permissions :
15+ contents : read
16+ packages : write
17+ id-token : write
18+ security-events : write
19+ pull-requests : read
20+ checks : write
21+
22+ env :
23+ GO_VERSION : " 1.24.4"
24+ REGISTRY : ghcr.io
25+
26+ jobs :
27+ # Static analysis and code quality check
28+ verify :
29+ name : Code Quality
30+ runs-on : ubuntu-latest
31+ steps :
32+ - name : Checkout code
33+ uses : actions/checkout@v4
34+ with :
35+ fetch-depth : 0
36+ persist-credentials : false
37+
38+ - name : Set up Go
39+ uses : actions/setup-go@v5
40+ with :
41+ go-version : ${{ env.GO_VERSION }}
42+ cache : true
43+ check-latest : true
44+
45+ - name : Install dependencies
46+ run : |
47+ go mod download
48+ go mod verify
49+
50+ - name : Check Go mod tidy
51+ run : |
52+ go mod tidy
53+ if ! git diff --quiet go.mod go.sum; then
54+ echo "go.mod or go.sum is not tidy, run 'go mod tidy'"
55+ git diff go.mod go.sum
56+ exit 1
57+ fi
58+
59+ - name : Run golangci-lint
60+ uses : golangci/golangci-lint-action@v7
61+ with :
62+ version : v2.0
63+ args : --timeout=5m
64+ only-new-issues : true
65+ install-mode : binary
66+ skip-cache : false
67+ skip-pkg-cache : true
68+ skip-build-cache : true
69+
70+ - name : Check formatting
71+ run : |
72+ if [ -n "$(gofmt -l .)" ]; then
73+ echo "The following files are not formatted properly:"
74+ gofmt -l .
75+ exit 1
76+ fi
77+
78+ # Security vulnerability scanning and SBOM generation
79+ security :
80+ name : Security Scan
81+ runs-on : ubuntu-latest
82+ needs : verify
83+ steps :
84+ - name : Checkout code
85+ uses : actions/checkout@v4
86+ with :
87+ persist-credentials : false
88+
89+ - name : Set up Go
90+ uses : actions/setup-go@v5
91+ with :
92+ go-version : ${{ env.GO_VERSION }}
93+ cache : true
94+
95+ - name : Run Go Vulnerability Check
96+ run : |
97+ go install golang.org/x/vuln/cmd/govulncheck@latest
98+ govulncheck ./...
99+
100+ - name : Run dependency scan
101+ uses : aquasecurity/trivy-action@master
102+ with :
103+ scan-type : " fs"
104+ scan-ref : " ."
105+ format : " sarif"
106+ output : " trivy-results.sarif"
107+ severity : " CRITICAL,HIGH,MEDIUM"
108+ ignore-unfixed : true
109+ timeout : " 10m"
110+
111+ - name : Upload security scan results
112+ uses : github/codeql-action/upload-sarif@v3
113+ if : always()
114+ with :
115+ sarif_file : " trivy-results.sarif"
116+
117+ - name : Generate SBOM
118+ uses : CycloneDX/gh-gomod-generate-sbom@v2
119+ with :
120+ version : v1
121+ args : mod -licenses -json -output bom.json
122+
123+ - name : Upload SBOM
124+ uses : actions/upload-artifact@v4
125+ with :
126+ name : sbom
127+ path : bom.json
128+ retention-days : 30
129+
130+ # Run unit and integration tests with code coverage
131+ test :
132+ name : Run Tests
133+ runs-on : ubuntu-latest
134+ needs : verify
135+ steps :
136+ - name : Checkout code
137+ uses : actions/checkout@v4
138+ with :
139+ persist-credentials : false
140+
141+ - name : Set up Go
142+ uses : actions/setup-go@v5
143+ with :
144+ go-version : ${{ env.GO_VERSION }}
145+ cache : true
146+
147+ - name : Run tests
148+ run : go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
149+
150+ - name : Upload coverage
151+ uses : codecov/codecov-action@v5
152+ with :
153+ file : ./coverage.txt
154+ flags : unittests
155+ fail_ci_if_error : false
156+
157+ # Simple build verification (for PRs and non-main branches)
158+ build :
159+ name : Build Verification
160+ runs-on : ubuntu-latest
161+ needs : [ verify, security ]
162+ # Only run for PRs or pushes to non-main branches
163+ if : github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main')
164+ steps :
165+ - name : Checkout code
166+ uses : actions/checkout@v4
167+ with :
168+ persist-credentials : false
169+
170+ - name : Set up Go
171+ uses : actions/setup-go@v5
172+ with :
173+ go-version : ${{ env.GO_VERSION }}
174+ cache : true
175+
176+ - name : Build
177+ run : go build -v ./...
0 commit comments