|
| 1 | +# ============================================================================= |
| 2 | +# MindX CI Pipeline — Production-grade GitHub Actions |
| 3 | +# ============================================================================= |
| 4 | +# Stages: lint → vet → security → test (race + coverage) → build (matrix) |
| 5 | +# |
| 6 | +# Triggers: |
| 7 | +# - push to main/develop, all PRs |
| 8 | +# - manual dispatch for debugging |
| 9 | +# ============================================================================= |
| 10 | + |
1 | 11 | name: CI |
2 | 12 |
|
3 | 13 | on: |
4 | 14 | push: |
5 | | - branches: [main] |
| 15 | + branches: [main, develop] |
| 16 | + paths-ignore: |
| 17 | + - '**.md' |
| 18 | + - 'docs/**' |
| 19 | + - 'LICENSE' |
| 20 | + - '.all-contributorsrc' |
6 | 21 | pull_request: |
7 | | - branches: [main] |
| 22 | + branches: [main, develop] |
| 23 | + workflow_dispatch: |
| 24 | + |
| 25 | +# Cancel in-progress runs on the same branch/PR |
| 26 | +concurrency: |
| 27 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | +# ========================================================================== |
| 31 | +# Environment defaults |
| 32 | +# ========================================================================== |
| 33 | +env: |
| 34 | + GO_VERSION: '1.26' |
| 35 | + CGO_ENABLED: 0 |
| 36 | + GOLANGCI_LINT_VERSION: v2.9 |
| 37 | + MINDX_WORKSPACE: ${{ github.workspace }}/.test |
8 | 38 |
|
9 | 39 | jobs: |
10 | | - backend: |
| 40 | + # ========================================================================== |
| 41 | + # Stage 1: Lint — golangci-lint with project config |
| 42 | + # ========================================================================== |
| 43 | + lint: |
| 44 | + name: Lint |
11 | 45 | runs-on: ubuntu-latest |
12 | 46 | steps: |
13 | | - - uses: actions/checkout@v4 |
| 47 | + - name: Checkout |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Set up Go |
| 51 | + uses: actions/setup-go@v6 |
| 52 | + with: |
| 53 | + go-version: ${{ env.GO_VERSION }} |
| 54 | + cache: true |
14 | 55 |
|
15 | | - - uses: actions/setup-go@v5 |
| 56 | + - name: golangci-lint |
| 57 | + uses: golangci/golangci-lint-action@v9 |
16 | 58 | with: |
17 | | - go-version-file: go.mod |
| 59 | + version: ${{ env.GOLANGCI_LINT_VERSION }} |
| 60 | + args: --timeout=5m |
18 | 61 |
|
19 | | - - name: Vet |
| 62 | + # ========================================================================== |
| 63 | + # Stage 2: Vet — static analysis |
| 64 | + # ========================================================================== |
| 65 | + vet: |
| 66 | + name: Vet |
| 67 | + runs-on: ubuntu-latest |
| 68 | + steps: |
| 69 | + - name: Checkout |
| 70 | + uses: actions/checkout@v4 |
| 71 | + |
| 72 | + - name: Set up Go |
| 73 | + uses: actions/setup-go@v6 |
| 74 | + with: |
| 75 | + go-version: ${{ env.GO_VERSION }} |
| 76 | + cache: true |
| 77 | + |
| 78 | + - name: Run go vet |
20 | 79 | run: go vet ./... |
21 | 80 |
|
| 81 | + # ========================================================================== |
| 82 | + # Stage 3: Security — vulnerability check |
| 83 | + # ========================================================================== |
| 84 | + security: |
| 85 | + name: Security |
| 86 | + runs-on: ubuntu-latest |
| 87 | + steps: |
| 88 | + - name: Checkout |
| 89 | + uses: actions/checkout@v4 |
| 90 | + |
| 91 | + - name: Set up Go |
| 92 | + uses: actions/setup-go@v6 |
| 93 | + with: |
| 94 | + go-version: ${{ env.GO_VERSION }} |
| 95 | + cache: true |
| 96 | + |
| 97 | + - name: Install govulncheck |
| 98 | + run: go install golang.org/x/vuln/cmd/govulncheck@latest |
| 99 | + |
| 100 | + - name: Run govulncheck |
| 101 | + run: govulncheck ./... |
| 102 | + |
| 103 | + # ========================================================================== |
| 104 | + # Stage 4: Test — race detector + coverage (matrix: OS) |
| 105 | + # ========================================================================== |
| 106 | + test: |
| 107 | + name: Test (${{ matrix.os }}) |
| 108 | + runs-on: ${{ matrix.os }} |
| 109 | + needs: [lint, vet] |
| 110 | + strategy: |
| 111 | + fail-fast: false |
| 112 | + matrix: |
| 113 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 114 | + env: |
| 115 | + CGO_ENABLED: 1 # race detector requires CGO |
| 116 | + steps: |
| 117 | + - name: Checkout |
| 118 | + uses: actions/checkout@v4 |
| 119 | + |
| 120 | + - name: Set up Go |
| 121 | + uses: actions/setup-go@v6 |
| 122 | + with: |
| 123 | + go-version: ${{ env.GO_VERSION }} |
| 124 | + cache: true |
| 125 | + |
22 | 126 | - name: Prepare test workspace |
23 | | - run: cp -r config .test/config |
| 127 | + run: | |
| 128 | + mkdir -p .test |
| 129 | + cp -r config .test/config 2>/dev/null || true |
24 | 130 | shell: bash |
25 | 131 |
|
26 | | - - name: Test |
27 | | - run: go test ./... |
| 132 | + - name: Run tests with race detector & coverage |
| 133 | + run: | |
| 134 | + go test \ |
| 135 | + -race \ |
| 136 | + -coverprofile=coverage.out \ |
| 137 | + -covermode=atomic \ |
| 138 | + -timeout=10m \ |
| 139 | + -v ./... 2>&1 | tee test-output.txt |
28 | 140 | env: |
29 | | - MINDX_WORKSPACE: ${{ github.workspace }}/.test |
| 141 | + MINDX_WORKSPACE: ${{ env.MINDX_WORKSPACE }} |
30 | 142 |
|
31 | | - frontend: |
32 | | - runs-on: ubuntu-latest |
33 | | - defaults: |
34 | | - run: |
35 | | - working-directory: dashboard |
| 143 | + - name: Display coverage summary |
| 144 | + if: runner.os != 'Windows' |
| 145 | + run: go tool cover -func=coverage.out | tail -1 |
| 146 | + |
| 147 | + - name: Upload coverage artifact |
| 148 | + if: matrix.os == 'ubuntu-latest' |
| 149 | + uses: actions/upload-artifact@v4 |
| 150 | + with: |
| 151 | + name: coverage-report |
| 152 | + path: coverage.out |
| 153 | + retention-days: 7 |
| 154 | + |
| 155 | + - name: Upload test output |
| 156 | + if: always() |
| 157 | + uses: actions/upload-artifact@v4 |
| 158 | + with: |
| 159 | + name: test-output-${{ matrix.os }} |
| 160 | + path: test-output.txt |
| 161 | + retention-days: 7 |
| 162 | + |
| 163 | + # ========================================================================== |
| 164 | + # Stage 5: Build verification (matrix: OS + Arch) |
| 165 | + # ========================================================================== |
| 166 | + build: |
| 167 | + name: Build (${{ matrix.goos }}/${{ matrix.goarch }}) |
| 168 | + runs-on: ${{ matrix.runner }} |
| 169 | + needs: [test] |
| 170 | + strategy: |
| 171 | + fail-fast: false |
| 172 | + matrix: |
| 173 | + include: |
| 174 | + - goos: linux |
| 175 | + goarch: amd64 |
| 176 | + runner: ubuntu-latest |
| 177 | + - goos: linux |
| 178 | + goarch: arm64 |
| 179 | + runner: ubuntu-latest |
| 180 | + - goos: darwin |
| 181 | + goarch: amd64 |
| 182 | + runner: ubuntu-latest |
| 183 | + - goos: darwin |
| 184 | + goarch: arm64 |
| 185 | + runner: ubuntu-latest |
| 186 | + - goos: windows |
| 187 | + goarch: amd64 |
| 188 | + runner: ubuntu-latest |
| 189 | + env: |
| 190 | + CGO_ENABLED: 0 |
36 | 191 | steps: |
37 | | - - uses: actions/checkout@v4 |
| 192 | + - name: Checkout |
| 193 | + uses: actions/checkout@v4 |
38 | 194 |
|
39 | | - - uses: actions/setup-node@v4 |
| 195 | + - name: Set up Go |
| 196 | + uses: actions/setup-go@v6 |
40 | 197 | with: |
41 | | - node-version: 20 |
42 | | - cache: npm |
43 | | - cache-dependency-path: dashboard/package-lock.json |
| 198 | + go-version: ${{ env.GO_VERSION }} |
| 199 | + cache: true |
| 200 | + |
| 201 | + - name: Get version info |
| 202 | + id: version |
| 203 | + run: | |
| 204 | + echo "version=$(git describe --tags --abbrev=0 2>/dev/null || echo 'dev')" >> "$GITHUB_OUTPUT" |
| 205 | + echo "commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" |
| 206 | + echo "build_time=$(date -u '+%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT" |
| 207 | +
|
| 208 | + - name: Build |
| 209 | + env: |
| 210 | + GOOS: ${{ matrix.goos }} |
| 211 | + GOARCH: ${{ matrix.goarch }} |
| 212 | + run: | |
| 213 | + BINARY_NAME=mindx |
| 214 | + VERSION=${{ steps.version.outputs.version }} |
| 215 | + COMMIT=${{ steps.version.outputs.commit }} |
| 216 | + BUILD_TIME=${{ steps.version.outputs.build_time }} |
| 217 | + SUFFIX="" |
| 218 | + [ "${{ matrix.goos }}" = "windows" ] && SUFFIX=".exe" |
| 219 | +
|
| 220 | + go build \ |
| 221 | + -trimpath \ |
| 222 | + -ldflags="-s -w \ |
| 223 | + -X github.com/DotNetAge/mindx/cmd.Version=${VERSION#v} \ |
| 224 | + -X github.com/DotNetAge/mindx/cmd.Commit=${COMMIT} \ |
| 225 | + -X github.com/DotNetAge/mindx/cmd.BuildTime=${BUILD_TIME}" \ |
| 226 | + -o dist/${BINARY_NAME}-${{ matrix.goos }}-${{ matrix.goarch }}${SUFFIX} \ |
| 227 | + . |
44 | 228 |
|
45 | | - - run: npm ci |
46 | | - - run: npm run lint |
47 | | - - run: npx tsc --noEmit |
48 | | - - run: npm run test |
| 229 | + ls -lh dist/ |
| 230 | +
|
| 231 | + - name: Upload build artifact |
| 232 | + uses: actions/upload-artifact@v4 |
| 233 | + with: |
| 234 | + name: mindx-${{ matrix.goos }}-${{ matrix.goarch }} |
| 235 | + path: dist/ |
| 236 | + retention-days: 7 |
0 commit comments