|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + lint: |
| 14 | + name: Lint |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + - uses: actions/setup-go@v5 |
| 19 | + with: |
| 20 | + go-version-file: 'go.mod' |
| 21 | + - name: golangci-lint |
| 22 | + uses: golangci/golangci-lint-action@v7 |
| 23 | + with: |
| 24 | + version: v2.10 |
| 25 | + args: --timeout=5m |
| 26 | + |
| 27 | + test: |
| 28 | + name: Test (${{ matrix.os }}) |
| 29 | + runs-on: ${{ matrix.os }} |
| 30 | + strategy: |
| 31 | + matrix: |
| 32 | + os: [ubuntu-latest, macos-latest] |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + - uses: actions/setup-go@v5 |
| 36 | + with: |
| 37 | + go-version-file: 'go.mod' |
| 38 | + - name: Run tests with race detector |
| 39 | + shell: bash |
| 40 | + run: go test -race -coverprofile=coverage.out -covermode=atomic ./... |
| 41 | + - name: Check coverage on critical packages |
| 42 | + continue-on-error: true |
| 43 | + if: matrix.os == 'ubuntu-latest' |
| 44 | + run: | |
| 45 | + # Extract coverage for critical packages and enforce 80% threshold |
| 46 | + CRITICAL_PKGS=( |
| 47 | + "github.com/Sentinel-Gate/Sentinelgate/internal/adapter/outbound/state" |
| 48 | + "github.com/Sentinel-Gate/Sentinelgate/internal/domain/proxy" |
| 49 | + "github.com/Sentinel-Gate/Sentinelgate/internal/service" |
| 50 | + "github.com/Sentinel-Gate/Sentinelgate/internal/adapter/inbound/admin" |
| 51 | + "github.com/Sentinel-Gate/Sentinelgate/internal/adapter/outbound/cel" |
| 52 | + ) |
| 53 | +
|
| 54 | + FAIL=0 |
| 55 | + for pkg in "${CRITICAL_PKGS[@]}"; do |
| 56 | + COV=$(go tool cover -func=coverage.out | grep "^${pkg}/" | tail -1 | awk '{print $NF}' | tr -d '%') |
| 57 | + if [ -z "$COV" ]; then |
| 58 | + echo "WARNING: No coverage data for $pkg" |
| 59 | + continue |
| 60 | + fi |
| 61 | + echo "$pkg: ${COV}%" |
| 62 | + COV_INT=${COV%.*} |
| 63 | + if [ "$COV_INT" -lt 50 ]; then |
| 64 | + echo "FAIL: $pkg coverage ${COV}% is below 50% threshold" |
| 65 | + FAIL=1 |
| 66 | + fi |
| 67 | + done |
| 68 | +
|
| 69 | + echo "" |
| 70 | + echo "Overall coverage:" |
| 71 | + go tool cover -func=coverage.out | tail -1 |
| 72 | +
|
| 73 | + if [ "$FAIL" -eq 1 ]; then |
| 74 | + echo "::error::Coverage below 50% on one or more critical packages" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + - name: Upload coverage report |
| 78 | + if: matrix.os == 'ubuntu-latest' |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: coverage-report |
| 82 | + path: coverage.out |
| 83 | + |
| 84 | + build: |
| 85 | + name: Build |
| 86 | + runs-on: ubuntu-latest |
| 87 | + strategy: |
| 88 | + matrix: |
| 89 | + include: |
| 90 | + - goos: linux |
| 91 | + goarch: amd64 |
| 92 | + - goos: linux |
| 93 | + goarch: arm64 |
| 94 | + - goos: darwin |
| 95 | + goarch: amd64 |
| 96 | + - goos: darwin |
| 97 | + goarch: arm64 |
| 98 | + - goos: windows |
| 99 | + goarch: amd64 |
| 100 | + steps: |
| 101 | + - uses: actions/checkout@v4 |
| 102 | + - uses: actions/setup-go@v5 |
| 103 | + with: |
| 104 | + go-version-file: 'go.mod' |
| 105 | + - name: Build binary |
| 106 | + env: |
| 107 | + GOOS: ${{ matrix.goos }} |
| 108 | + GOARCH: ${{ matrix.goarch }} |
| 109 | + run: | |
| 110 | + go build -ldflags="-s -w" -o sentinel-gate-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/sentinel-gate |
| 111 | + - name: Upload binary |
| 112 | + uses: actions/upload-artifact@v4 |
| 113 | + with: |
| 114 | + name: sentinel-gate-${{ matrix.goos }}-${{ matrix.goarch }} |
| 115 | + path: sentinel-gate-${{ matrix.goos }}-${{ matrix.goarch }} |
| 116 | + |
| 117 | + smoke: |
| 118 | + name: Smoke Test |
| 119 | + runs-on: ubuntu-latest |
| 120 | + needs: [build] |
| 121 | + steps: |
| 122 | + - uses: actions/checkout@v4 |
| 123 | + - uses: actions/setup-go@v5 |
| 124 | + with: |
| 125 | + go-version-file: 'go.mod' |
| 126 | + - name: Install dependencies |
| 127 | + run: sudo apt-get update && sudo apt-get install -y jq |
| 128 | + - name: Run smoke tests |
| 129 | + continue-on-error: true |
| 130 | + run: bash scripts/smoke.sh |
| 131 | + |
| 132 | + security: |
| 133 | + name: Security Scan |
| 134 | + runs-on: ubuntu-latest |
| 135 | + steps: |
| 136 | + - uses: actions/checkout@v4 |
| 137 | + with: |
| 138 | + fetch-depth: 0 # gitleaks needs full history |
| 139 | + - uses: actions/setup-go@v5 |
| 140 | + with: |
| 141 | + go-version-file: 'go.mod' |
| 142 | + |
| 143 | + # Dependency vulnerability scanning |
| 144 | + - name: Install govulncheck |
| 145 | + run: go install golang.org/x/vuln/cmd/govulncheck@latest |
| 146 | + - name: govulncheck — dependency CVEs |
| 147 | + run: govulncheck ./... |
| 148 | + |
| 149 | + # SAST — security bugs in Go code |
| 150 | + - name: Install gosec |
| 151 | + run: go install github.com/securego/gosec/v2/cmd/gosec@latest |
| 152 | + - name: gosec — Go security analysis |
| 153 | + run: gosec -exclude-generated -exclude=G115,G118,G124,G204,G301,G304,G703 -severity medium ./... |
| 154 | + |
| 155 | + # Secret scanning — leaked credentials in git history |
| 156 | + - name: gitleaks — secret detection |
| 157 | + uses: gitleaks/gitleaks-action@v2 |
| 158 | + env: |
| 159 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 160 | + |
| 161 | + fuzz: |
| 162 | + name: Fuzz Tests |
| 163 | + runs-on: ubuntu-latest |
| 164 | + steps: |
| 165 | + - uses: actions/checkout@v4 |
| 166 | + - uses: actions/setup-go@v5 |
| 167 | + with: |
| 168 | + go-version-file: 'go.mod' |
| 169 | + - name: Fuzz MCP message parser (30s) |
| 170 | + run: go test -fuzz=FuzzDecodeMessage -fuzztime=30s ./pkg/mcp/ |
| 171 | + - name: Fuzz JSON-RPC validation (30s) |
| 172 | + run: go test -fuzz=FuzzMessageValidator -fuzztime=30s ./internal/domain/validation/ |
0 commit comments