Skip to content

Commit 09260d1

Browse files
authored
Merge pull request #18 from hao1939/dev
Add comprehensive testing workflow for PR checks
2 parents 0292785 + cec30db commit 09260d1

30 files changed

Lines changed: 631 additions & 89 deletions

.github/workflows/pr-checks.yml

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
name: PR Checks
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- dev
8+
push:
9+
branches:
10+
- main
11+
- dev
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
pull-requests: read
17+
18+
jobs:
19+
build:
20+
name: Build
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
go-version: ['1.24']
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Go
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version: ${{ matrix.go-version }}
33+
cache: true
34+
35+
- name: Verify dependencies
36+
run: go mod verify
37+
38+
- name: Build for current platform
39+
run: make build
40+
41+
- name: Build for all supported platforms
42+
run: make build-all
43+
44+
test:
45+
name: Test
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout code
49+
uses: actions/checkout@v4
50+
51+
- name: Set up Go
52+
uses: actions/setup-go@v5
53+
with:
54+
go-version: '1.24'
55+
cache: true
56+
57+
- name: Run tests
58+
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
59+
60+
- name: Generate coverage report
61+
run: go tool cover -html=coverage.out -o coverage.html
62+
63+
- name: Upload coverage to artifacts
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: coverage-report
67+
path: |
68+
coverage.out
69+
coverage.html
70+
71+
- name: Check test coverage
72+
run: |
73+
coverage=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
74+
echo "Total test coverage: ${coverage}%"
75+
# Set minimum coverage threshold (can be adjusted)
76+
threshold=30
77+
if (( $(echo "$coverage < $threshold" | bc -l) )); then
78+
echo "::warning::Test coverage ${coverage}% is below threshold ${threshold}%"
79+
echo "Please consider adding more tests to improve coverage."
80+
else
81+
echo "✅ Test coverage ${coverage}% meets threshold ${threshold}%"
82+
fi
83+
84+
lint:
85+
name: Lint
86+
runs-on: ubuntu-latest
87+
steps:
88+
- name: Checkout code
89+
uses: actions/checkout@v4
90+
91+
- name: Set up Go
92+
uses: actions/setup-go@v5
93+
with:
94+
go-version: '1.24'
95+
cache: true
96+
97+
- name: Run golangci-lint
98+
uses: golangci/golangci-lint-action@v9
99+
with:
100+
version: latest
101+
args: --timeout=5m
102+
103+
security:
104+
name: Security Scan
105+
runs-on: ubuntu-latest
106+
steps:
107+
- name: Checkout code
108+
uses: actions/checkout@v4
109+
110+
- name: Set up Go
111+
uses: actions/setup-go@v5
112+
with:
113+
go-version: '1.24'
114+
cache: true
115+
116+
- name: Run Gosec Security Scanner
117+
run: |
118+
go install github.com/securego/gosec/v2/cmd/gosec@latest
119+
gosec -fmt=sarif -out=results.sarif -no-fail ./...
120+
# Remove invalid fixes from SARIF to prevent upload errors
121+
jq 'del(.runs[].results[].fixes)' results.sarif > results-clean.sarif
122+
mv results-clean.sarif results.sarif
123+
continue-on-error: true
124+
125+
- name: Upload SARIF file
126+
uses: github/codeql-action/upload-sarif@v4
127+
if: always()
128+
with:
129+
sarif_file: results.sarif
130+
category: gosec
131+
132+
code-quality:
133+
name: Code Quality Checks
134+
runs-on: ubuntu-latest
135+
steps:
136+
- name: Checkout code
137+
uses: actions/checkout@v4
138+
139+
- name: Set up Go
140+
uses: actions/setup-go@v5
141+
with:
142+
go-version: '1.24'
143+
cache: true
144+
145+
- name: Check go fmt
146+
run: |
147+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
148+
echo "❌ Go code is not formatted. Please run 'make fmt' or 'gofmt -s -w .'"
149+
echo ""
150+
echo "Unformatted files:"
151+
gofmt -s -l .
152+
exit 1
153+
fi
154+
echo "✅ All files are properly formatted"
155+
156+
- name: Check goimports
157+
run: |
158+
go install golang.org/x/tools/cmd/goimports@latest
159+
if [ "$(goimports -l . | wc -l)" -gt 0 ]; then
160+
echo "❌ Go imports are not properly formatted. Please run 'goimports -w .'"
161+
echo ""
162+
echo "Files with incorrect imports:"
163+
goimports -l .
164+
exit 1
165+
fi
166+
echo "✅ All imports are properly formatted"
167+
168+
- name: Check go vet
169+
run: go vet ./...
170+
171+
- name: Check for common mistakes with staticcheck
172+
uses: dominikh/staticcheck-action@v1
173+
with:
174+
version: "latest"
175+
install-go: false
176+
177+
dependency-review:
178+
name: Dependency Review
179+
runs-on: ubuntu-latest
180+
if: github.event_name == 'pull_request'
181+
steps:
182+
- name: Checkout code
183+
uses: actions/checkout@v4
184+
185+
- name: Dependency Review
186+
uses: actions/dependency-review-action@v4
187+
with:
188+
fail-on-severity: moderate

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ jobs:
3434
fetch-depth: 0
3535

3636
- name: Set up Go
37-
uses: actions/setup-go@v4
37+
uses: actions/setup-go@v5
3838
with:
39-
go-version: '1.23'
39+
go-version: '1.24'
4040

4141
- name: Get version
4242
id: version

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ aks-flex-node
1212
# Output of the go coverage tool, specifically when used with LiteIDE
1313
*.out
1414

15+
# Test coverage reports
16+
coverage.out
17+
coverage.html
18+
coverage.xml
19+
1520
# Go workspace file
1621
go.work
1722

.golangci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: '2'
2+
3+
run:
4+
timeout: 5m
5+
6+
linters:
7+
default: none
8+
enable:
9+
- errcheck
10+
- govet
11+
- ineffassign
12+
- staticcheck
13+
- unused
14+
settings:
15+
errcheck:
16+
check-type-assertions: true
17+
check-blank: false # Allow _ = for intentionally ignored errors in defer
18+
exclusions:
19+
rules:
20+
# Exclude some linters from running on test files
21+
- path: _test\.go
22+
linters:
23+
- errcheck

Makefile

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,69 @@ package-all: package-linux-amd64 package-linux-arm64
4545
@echo "Packaged all supported platforms"
4646
@ls -la *.tar.gz
4747

48+
# Testing and quality checks
4849
.PHONY: test
4950
test:
50-
@go test ./...
51+
@echo "Running tests..."
52+
@go test -v ./...
53+
54+
.PHONY: test-coverage
55+
test-coverage:
56+
@echo "Running tests with coverage..."
57+
@go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
58+
@go tool cover -html=coverage.out -o coverage.html
59+
@echo "Coverage report generated: coverage.html"
60+
61+
.PHONY: test-race
62+
test-race:
63+
@echo "Running tests with race detector..."
64+
@go test -race ./...
65+
66+
.PHONY: lint
67+
lint:
68+
@echo "Running golangci-lint..."
69+
@which golangci-lint > /dev/null || (echo "golangci-lint not installed. Install from https://golangci-lint.run/usage/install/" && exit 1)
70+
@golangci-lint run --timeout=5m
71+
72+
.PHONY: fmt
73+
fmt:
74+
@echo "Formatting code..."
75+
@gofmt -s -w .
76+
@echo "Code formatted"
77+
78+
.PHONY: fmt-imports
79+
fmt-imports:
80+
@echo "Formatting imports..."
81+
@which goimports > /dev/null || (echo "goimports not installed. Installing..." && go install golang.org/x/tools/cmd/goimports@latest)
82+
@goimports -w .
83+
@echo "Imports formatted"
84+
85+
.PHONY: fmt-all
86+
fmt-all: fmt fmt-imports
87+
@echo "All formatting complete"
88+
89+
.PHONY: vet
90+
vet:
91+
@echo "Running go vet..."
92+
@go vet ./...
93+
94+
.PHONY: check
95+
check: fmt-all vet lint test
96+
@echo "All checks passed!"
97+
98+
.PHONY: verify
99+
verify:
100+
@echo "Verifying dependencies..."
101+
@go mod verify
102+
@go mod tidy
51103

52104
.PHONY: clean
53105
clean:
54106
@echo "Cleaning build artifacts..."
55107
@go clean
56108
@rm -f aks-flex-node-*
57109
@rm -f *.tar.gz
110+
@rm -f coverage.out coverage.html
58111

59112
.PHONY: update-build-metadata
60113
update-build-metadata:
@@ -68,15 +121,30 @@ help:
68121
@echo "AKS Flex Node Makefile"
69122
@echo "======================"
70123
@echo ""
71-
@echo "Targets:"
124+
@echo "Build Targets:"
72125
@echo " build Build for current platform"
73126
@echo " build-linux-amd64 Build for Linux AMD64"
74127
@echo " build-linux-arm64 Build for Linux ARM64"
75128
@echo " build-all Build for all supported platforms"
129+
@echo ""
130+
@echo "Package Targets:"
76131
@echo " package-linux-amd64 Package Linux AMD64 binary"
77132
@echo " package-linux-arm64 Package Linux ARM64 binary"
78133
@echo " package-all Package all supported platforms"
134+
@echo ""
135+
@echo "Test & Quality Targets:"
79136
@echo " test Run tests"
137+
@echo " test-coverage Run tests with coverage report"
138+
@echo " test-race Run tests with race detector"
139+
@echo " lint Run golangci-lint"
140+
@echo " fmt Format code with gofmt"
141+
@echo " fmt-imports Format imports with goimports"
142+
@echo " fmt-all Format code and imports"
143+
@echo " vet Run go vet"
144+
@echo " check Run fmt-all, vet, lint, and test"
145+
@echo " verify Verify and tidy dependencies"
146+
@echo ""
147+
@echo "Other Targets:"
80148
@echo " clean Clean build artifacts"
81149
@echo " update-build-metadata Show build metadata"
82150
@echo " help Show this help message"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ For a complete list of build targets, run `make help`.
233233
- **Production:** 50GB+ free space
234234
- **Network:** Internet connectivity to Azure endpoints
235235
- **Privileges:** Root/sudo access required
236-
- **Build Dependencies:** Go 1.23+ (if building from source)
236+
- **Build Dependencies:** Go 1.24+ (if building from source)
237237

238238
### Storage Breakdown
239239
- **Base components:** ~3GB (Arc agent, runc, containerd, Kubernetes binaries, CNI plugins)

0 commit comments

Comments
 (0)