|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, development] |
| 6 | + paths: |
| 7 | + - 'src/**' |
| 8 | + - 'tests/**' |
| 9 | + - 'examples/**' |
| 10 | + - 'package.json' |
| 11 | + - 'bun.lock' |
| 12 | + - 'tsconfig.json' |
| 13 | + - '*.ts' |
| 14 | + - '.github/**' |
| 15 | + pull_request: |
| 16 | + branches: [main, development] |
| 17 | + paths: |
| 18 | + - 'src/**' |
| 19 | + - 'tests/**' |
| 20 | + - 'examples/**' |
| 21 | + - 'package.json' |
| 22 | + - 'bun.lock' |
| 23 | + - 'tsconfig.json' |
| 24 | + - '*.ts' |
| 25 | + workflow_dispatch: |
| 26 | + |
| 27 | +concurrency: |
| 28 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 29 | + cancel-in-progress: true |
| 30 | + |
| 31 | +env: |
| 32 | + BUN_VERSION: '1.2.21' |
| 33 | + |
| 34 | +jobs: |
| 35 | + setup: |
| 36 | + name: 🔧 Setup & Dependencies |
| 37 | + runs-on: ubuntu-latest |
| 38 | + outputs: |
| 39 | + cache-key: ${{ steps.cache-key.outputs.key }} |
| 40 | + steps: |
| 41 | + - name: 📥 Checkout code |
| 42 | + uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - name: 🐰 Setup Bun |
| 45 | + uses: oven-sh/setup-bun@v2 |
| 46 | + with: |
| 47 | + bun-version: ${{ env.BUN_VERSION }} |
| 48 | + |
| 49 | + - name: 🔑 Generate cache key |
| 50 | + id: cache-key |
| 51 | + run: echo "key=bun-${{ hashFiles('**/bun.lock', '**/package.json') }}" >> $GITHUB_OUTPUT |
| 52 | + |
| 53 | + - name: 💾 Cache dependencies |
| 54 | + uses: actions/cache@v4 |
| 55 | + id: cache-deps |
| 56 | + with: |
| 57 | + path: | |
| 58 | + ~/.bun/install/cache |
| 59 | + node_modules |
| 60 | + examples/*/node_modules |
| 61 | + key: ${{ steps.cache-key.outputs.key }} |
| 62 | + restore-keys: | |
| 63 | + bun- |
| 64 | +
|
| 65 | + - name: 📦 Install dependencies |
| 66 | + if: steps.cache-deps.outputs.cache-hit != 'true' |
| 67 | + run: bun install --frozen-lockfile |
| 68 | + |
| 69 | + - name: 📦 Install example dependencies |
| 70 | + if: steps.cache-deps.outputs.cache-hit != 'true' |
| 71 | + run: | |
| 72 | + cd examples/graphql-server && bun install --frozen-lockfile |
| 73 | + cd ../type-graphql && bun install --frozen-lockfile |
| 74 | + cd ../advanced-graphql && bun install --frozen-lockfile |
| 75 | +
|
| 76 | + typecheck: |
| 77 | + name: 🔍 Type Check & Lint |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: setup |
| 80 | + steps: |
| 81 | + - name: 📥 Checkout code |
| 82 | + uses: actions/checkout@v4 |
| 83 | + |
| 84 | + - name: 🐰 Setup Bun |
| 85 | + uses: oven-sh/setup-bun@v2 |
| 86 | + with: |
| 87 | + bun-version: ${{ env.BUN_VERSION }} |
| 88 | + |
| 89 | + - name: 💾 Restore dependencies |
| 90 | + uses: actions/cache@v4 |
| 91 | + with: |
| 92 | + path: | |
| 93 | + ~/.bun/install/cache |
| 94 | + node_modules |
| 95 | + examples/*/node_modules |
| 96 | + key: ${{ needs.setup.outputs.cache-key }} |
| 97 | + |
| 98 | + - name: 🔍 Type check |
| 99 | + run: bunx tsc --noEmit |
| 100 | + |
| 101 | + - name: 🧹 Lint check |
| 102 | + run: | |
| 103 | + if [ -f "eslint.config.js" ] || [ -f ".eslintrc.json" ] || [ -f ".eslintrc.js" ]; then |
| 104 | + bunx eslint src/ tests/ --ext .ts --max-warnings 0 |
| 105 | + else |
| 106 | + echo "No ESLint configuration found, skipping lint check" |
| 107 | + fi |
| 108 | +
|
| 109 | + unit-tests: |
| 110 | + name: 🧪 Unit & Integration Tests |
| 111 | + runs-on: ubuntu-latest |
| 112 | + needs: setup |
| 113 | + steps: |
| 114 | + - name: 📥 Checkout code |
| 115 | + uses: actions/checkout@v4 |
| 116 | + |
| 117 | + - name: 🐰 Setup Bun |
| 118 | + uses: oven-sh/setup-bun@v2 |
| 119 | + with: |
| 120 | + bun-version: ${{ env.BUN_VERSION }} |
| 121 | + |
| 122 | + - name: 💾 Restore dependencies |
| 123 | + uses: actions/cache@v4 |
| 124 | + with: |
| 125 | + path: | |
| 126 | + ~/.bun/install/cache |
| 127 | + node_modules |
| 128 | + examples/*/node_modules |
| 129 | + key: ${{ needs.setup.outputs.cache-key }} |
| 130 | + |
| 131 | + - name: 🧪 Run unit tests with coverage |
| 132 | + run: bun run test:coverage |
| 133 | + |
| 134 | + - name: 📊 Generate coverage summary |
| 135 | + run: | |
| 136 | + echo "## 🧪 Test Coverage Report" >> $GITHUB_STEP_SUMMARY |
| 137 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 138 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 139 | + bun run test:coverage | grep -A 20 "File.*% Funcs.*% Lines" || echo "Coverage report format changed" |
| 140 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 141 | +
|
| 142 | + - name: 📈 Upload coverage (if available) |
| 143 | + uses: codecov/codecov-action@v4 |
| 144 | + with: |
| 145 | + fail_ci_if_error: false |
| 146 | + continue-on-error: true |
| 147 | + |
| 148 | + - name: 💾 Archive test results |
| 149 | + if: always() |
| 150 | + uses: actions/upload-artifact@v4 |
| 151 | + with: |
| 152 | + name: unit-test-results |
| 153 | + path: | |
| 154 | + coverage/ |
| 155 | + test-results.xml |
| 156 | + .coverage |
| 157 | + retention-days: 7 |
| 158 | + continue-on-error: true |
| 159 | + |
| 160 | + e2e-tests: |
| 161 | + name: 🚀 End-to-End Tests |
| 162 | + runs-on: ubuntu-latest |
| 163 | + needs: [setup, typecheck] |
| 164 | + timeout-minutes: 15 |
| 165 | + steps: |
| 166 | + - name: 📥 Checkout code |
| 167 | + uses: actions/checkout@v4 |
| 168 | + |
| 169 | + - name: 🐰 Setup Bun |
| 170 | + uses: oven-sh/setup-bun@v2 |
| 171 | + with: |
| 172 | + bun-version: ${{ env.BUN_VERSION }} |
| 173 | + |
| 174 | + - name: 💾 Restore dependencies |
| 175 | + uses: actions/cache@v4 |
| 176 | + with: |
| 177 | + path: | |
| 178 | + ~/.bun/install/cache |
| 179 | + node_modules |
| 180 | + examples/*/node_modules |
| 181 | + key: ${{ needs.setup.outputs.cache-key }} |
| 182 | + |
| 183 | + - name: 🏗️ Build project |
| 184 | + run: bun run build |
| 185 | + |
| 186 | + - name: 📊 Cache build artifacts |
| 187 | + uses: actions/cache@v4 |
| 188 | + with: |
| 189 | + path: | |
| 190 | + dist/ |
| 191 | + examples/*/dist/ |
| 192 | + examples/*/prisma/ |
| 193 | + key: build-${{ github.sha }} |
| 194 | + |
| 195 | + - name: ⚡ Generate examples |
| 196 | + run: bun run generate:all |
| 197 | + |
| 198 | + - name: 🧪 Run E2E tests |
| 199 | + run: bun run test:examples |
| 200 | + |
| 201 | + - name: 💾 Archive E2E results |
| 202 | + if: always() |
| 203 | + uses: actions/upload-artifact@v4 |
| 204 | + with: |
| 205 | + name: e2e-test-results |
| 206 | + path: | |
| 207 | + examples/*/tests/ |
| 208 | + examples/*/*.test.ts |
| 209 | + examples/*/schema.graphql |
| 210 | + retention-days: 7 |
| 211 | + |
| 212 | + performance-tests: |
| 213 | + name: ⚡ Performance Tests |
| 214 | + runs-on: ubuntu-latest |
| 215 | + needs: [setup, unit-tests] |
| 216 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 217 | + steps: |
| 218 | + - name: 📥 Checkout code |
| 219 | + uses: actions/checkout@v4 |
| 220 | + |
| 221 | + - name: 🐰 Setup Bun |
| 222 | + uses: oven-sh/setup-bun@v2 |
| 223 | + with: |
| 224 | + bun-version: ${{ env.BUN_VERSION }} |
| 225 | + |
| 226 | + - name: 💾 Restore dependencies |
| 227 | + uses: actions/cache@v4 |
| 228 | + with: |
| 229 | + path: | |
| 230 | + ~/.bun/install/cache |
| 231 | + node_modules |
| 232 | + examples/*/node_modules |
| 233 | + key: ${{ needs.setup.outputs.cache-key }} |
| 234 | + |
| 235 | + - name: ⚡ Run performance tests |
| 236 | + run: bun test tests/performance/ |
| 237 | + |
| 238 | + security-scan: |
| 239 | + name: 🔒 Security Scan |
| 240 | + runs-on: ubuntu-latest |
| 241 | + needs: setup |
| 242 | + steps: |
| 243 | + - name: 📥 Checkout code |
| 244 | + uses: actions/checkout@v4 |
| 245 | + |
| 246 | + - name: 🔒 Run security audit |
| 247 | + run: | |
| 248 | + bun audit --audit-level moderate || true |
| 249 | +
|
| 250 | + build-validation: |
| 251 | + name: 📦 Build Validation |
| 252 | + runs-on: ubuntu-latest |
| 253 | + needs: [setup, typecheck] |
| 254 | + steps: |
| 255 | + - name: 📥 Checkout code |
| 256 | + uses: actions/checkout@v4 |
| 257 | + |
| 258 | + - name: 🐰 Setup Bun |
| 259 | + uses: oven-sh/setup-bun@v2 |
| 260 | + with: |
| 261 | + bun-version: ${{ env.BUN_VERSION }} |
| 262 | + |
| 263 | + - name: 💾 Restore dependencies |
| 264 | + uses: actions/cache@v4 |
| 265 | + with: |
| 266 | + path: | |
| 267 | + ~/.bun/install/cache |
| 268 | + node_modules |
| 269 | + examples/*/node_modules |
| 270 | + key: ${{ needs.setup.outputs.cache-key }} |
| 271 | + |
| 272 | + - name: 🏗️ Test build process |
| 273 | + run: | |
| 274 | + bun run build |
| 275 | +
|
| 276 | + - name: ✅ Verify build output |
| 277 | + run: | |
| 278 | + [ -d "dist" ] || (echo "dist directory not found!" && exit 1) |
| 279 | + [ -f "dist/index.js" ] || (echo "Main entry file not found!" && exit 1) |
| 280 | + [ -f "dist/package.json" ] || (echo "Package.json not found in dist!" && exit 1) |
| 281 | + echo "✅ Build validation successful" |
| 282 | +
|
| 283 | + - name: 💾 Archive build artifacts |
| 284 | + uses: actions/upload-artifact@v4 |
| 285 | + with: |
| 286 | + name: build-artifacts |
| 287 | + path: dist/ |
| 288 | + retention-days: 7 |
| 289 | + |
| 290 | + test-summary: |
| 291 | + name: 📋 Test Summary |
| 292 | + runs-on: ubuntu-latest |
| 293 | + needs: [typecheck, unit-tests, e2e-tests, build-validation] |
| 294 | + if: always() |
| 295 | + steps: |
| 296 | + - name: 📋 Generate summary |
| 297 | + run: | |
| 298 | + echo "## 🧪 Test Results Summary" >> $GITHUB_STEP_SUMMARY |
| 299 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 300 | + echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY |
| 301 | + echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY |
| 302 | + echo "| Type Check & Lint | ${{ needs.typecheck.result == 'success' && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY |
| 303 | + echo "| Unit Tests | ${{ needs.unit-tests.result == 'success' && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY |
| 304 | + echo "| E2E Tests | ${{ needs.e2e-tests.result == 'success' && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY |
| 305 | + echo "| Build Validation | ${{ needs.build-validation.result == 'success' && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY |
| 306 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 307 | + echo "### 📊 Coverage & Artifacts" >> $GITHUB_STEP_SUMMARY |
| 308 | + echo "- Coverage reports available in artifacts" >> $GITHUB_STEP_SUMMARY |
| 309 | + echo "- Test results archived for 7 days" >> $GITHUB_STEP_SUMMARY |
| 310 | +
|
| 311 | + - name: ❌ Fail if critical jobs failed |
| 312 | + if: | |
| 313 | + needs.typecheck.result == 'failure' || |
| 314 | + needs.unit-tests.result == 'failure' || |
| 315 | + needs.e2e-tests.result == 'failure' || |
| 316 | + needs.build-validation.result == 'failure' |
| 317 | + run: | |
| 318 | + echo "❌ Critical jobs failed. Please check the logs above." |
| 319 | + exit 1 |
0 commit comments