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