|
| 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 |
0 commit comments