github-actions-template.yaml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. # GitHub Actions CI/CD Pipeline for Test Execution
  2. # Generated by BMad TEA Agent - Test Architect Module
  3. # Optimized for: Playwright/Cypress, Parallel Sharding, Burn-In Loop
  4. name: Test Pipeline
  5. on:
  6. push:
  7. branches: [main, develop]
  8. pull_request:
  9. branches: [main, develop]
  10. schedule:
  11. # Weekly burn-in on Sundays at 2 AM UTC
  12. - cron: "0 2 * * 0"
  13. concurrency:
  14. group: ${{ github.workflow }}-${{ github.ref }}
  15. cancel-in-progress: true
  16. jobs:
  17. # Lint stage - Code quality checks
  18. lint:
  19. name: Lint
  20. runs-on: ubuntu-latest
  21. timeout-minutes: 5
  22. steps:
  23. - uses: actions/checkout@v4
  24. - name: Determine Node version
  25. id: node-version
  26. run: |
  27. if [ -f .nvmrc ]; then
  28. echo "value=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
  29. echo "Using Node from .nvmrc"
  30. else
  31. echo "value=24" >> "$GITHUB_OUTPUT"
  32. echo "Using default Node 24 (current LTS)"
  33. fi
  34. - name: Setup Node.js
  35. uses: actions/setup-node@v4
  36. with:
  37. node-version: ${{ steps.node-version.outputs.value }}
  38. cache: "npm"
  39. - name: Install dependencies
  40. run: npm ci
  41. - name: Run linter
  42. run: npm run lint
  43. # Test stage - Parallel execution with sharding
  44. test:
  45. name: Test (Shard ${{ matrix.shard }})
  46. runs-on: ubuntu-latest
  47. timeout-minutes: 30
  48. needs: lint
  49. strategy:
  50. fail-fast: false
  51. matrix:
  52. shard: [1, 2, 3, 4]
  53. steps:
  54. - uses: actions/checkout@v4
  55. - name: Determine Node version
  56. id: node-version
  57. run: |
  58. if [ -f .nvmrc ]; then
  59. echo "value=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
  60. echo "Using Node from .nvmrc"
  61. else
  62. echo "value=22" >> "$GITHUB_OUTPUT"
  63. echo "Using default Node 22 (current LTS)"
  64. fi
  65. - name: Setup Node.js
  66. uses: actions/setup-node@v4
  67. with:
  68. node-version: ${{ steps.node-version.outputs.value }}
  69. cache: "npm"
  70. - name: Cache Playwright browsers
  71. uses: actions/cache@v4
  72. with:
  73. path: ~/.cache/ms-playwright
  74. key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
  75. restore-keys: |
  76. ${{ runner.os }}-playwright-
  77. - name: Install dependencies
  78. run: npm ci
  79. - name: Install Playwright browsers
  80. run: npx playwright install --with-deps chromium
  81. - name: Run tests (shard ${{ matrix.shard }}/4)
  82. run: npm run test:e2e -- --shard=${{ matrix.shard }}/4
  83. - name: Upload test results
  84. if: failure()
  85. uses: actions/upload-artifact@v4
  86. with:
  87. name: test-results-${{ matrix.shard }}
  88. path: |
  89. test-results/
  90. playwright-report/
  91. retention-days: 30
  92. # Burn-in stage - Flaky test detection
  93. burn-in:
  94. name: Burn-In (Flaky Detection)
  95. runs-on: ubuntu-latest
  96. timeout-minutes: 60
  97. needs: test
  98. # Only run burn-in on PRs to main/develop or on schedule
  99. if: github.event_name == 'pull_request' || github.event_name == 'schedule'
  100. steps:
  101. - uses: actions/checkout@v4
  102. - name: Determine Node version
  103. id: node-version
  104. run: |
  105. if [ -f .nvmrc ]; then
  106. echo "value=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
  107. echo "Using Node from .nvmrc"
  108. else
  109. echo "value=22" >> "$GITHUB_OUTPUT"
  110. echo "Using default Node 22 (current LTS)"
  111. fi
  112. - name: Setup Node.js
  113. uses: actions/setup-node@v4
  114. with:
  115. node-version: ${{ steps.node-version.outputs.value }}
  116. cache: "npm"
  117. - name: Cache Playwright browsers
  118. uses: actions/cache@v4
  119. with:
  120. path: ~/.cache/ms-playwright
  121. key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
  122. - name: Install dependencies
  123. run: npm ci
  124. - name: Install Playwright browsers
  125. run: npx playwright install --with-deps chromium
  126. - name: Run burn-in loop (10 iterations)
  127. run: |
  128. echo "🔥 Starting burn-in loop - detecting flaky tests"
  129. for i in {1..10}; do
  130. echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
  131. echo "🔥 Burn-in iteration $i/10"
  132. echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
  133. npm run test:e2e || exit 1
  134. done
  135. echo "✅ Burn-in complete - no flaky tests detected"
  136. - name: Upload burn-in failure artifacts
  137. if: failure()
  138. uses: actions/upload-artifact@v4
  139. with:
  140. name: burn-in-failures
  141. path: |
  142. test-results/
  143. playwright-report/
  144. retention-days: 30
  145. # Report stage - Aggregate and publish results
  146. report:
  147. name: Test Report
  148. runs-on: ubuntu-latest
  149. needs: [test, burn-in]
  150. if: always()
  151. steps:
  152. - name: Download all artifacts
  153. uses: actions/download-artifact@v4
  154. with:
  155. path: artifacts
  156. - name: Generate summary
  157. run: |
  158. echo "## Test Execution Summary" >> $GITHUB_STEP_SUMMARY
  159. echo "" >> $GITHUB_STEP_SUMMARY
  160. echo "- **Status**: ${{ needs.test.result }}" >> $GITHUB_STEP_SUMMARY
  161. echo "- **Burn-in**: ${{ needs.burn-in.result }}" >> $GITHUB_STEP_SUMMARY
  162. echo "- **Shards**: 4" >> $GITHUB_STEP_SUMMARY
  163. echo "" >> $GITHUB_STEP_SUMMARY
  164. if [ "${{ needs.burn-in.result }}" == "failure" ]; then
  165. echo "⚠️ **Flaky tests detected** - Review burn-in artifacts" >> $GITHUB_STEP_SUMMARY
  166. fi