|
| 1 | +name: Test Suite |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + node-version: [18.x] |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Setup Node.js ${{ matrix.node-version }} |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: ${{ matrix.node-version }} |
| 25 | + |
| 26 | + - name: Install pnpm |
| 27 | + uses: pnpm/action-setup@v4 |
| 28 | + with: |
| 29 | + version: 8.6.11 |
| 30 | + run_install: false |
| 31 | + |
| 32 | + - name: Get pnpm store directory |
| 33 | + shell: bash |
| 34 | + run: | |
| 35 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 36 | +
|
| 37 | + - name: Setup pnpm cache |
| 38 | + uses: actions/cache@v4 |
| 39 | + with: |
| 40 | + path: ${{ env.STORE_PATH }} |
| 41 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 42 | + restore-keys: | |
| 43 | + ${{ runner.os }}-pnpm-store- |
| 44 | +
|
| 45 | + - name: Install dependencies |
| 46 | + run: pnpm install --frozen-lockfile |
| 47 | + |
| 48 | + - name: Run linter |
| 49 | + run: pnpm lint |
| 50 | + |
| 51 | + - name: Run backend unit tests |
| 52 | + run: pnpm test:backend |
| 53 | + |
| 54 | + - name: Run frontend unit tests |
| 55 | + run: pnpm test:frontend |
| 56 | + continue-on-error: true # Allow to continue if frontend tests fail initially |
| 57 | + |
| 58 | + - name: Run E2E tests |
| 59 | + run: pnpm test:e2e |
| 60 | + continue-on-error: true # Allow to continue if E2E tests fail initially |
| 61 | + |
| 62 | + - name: Generate coverage report |
| 63 | + run: pnpm test:coverage |
| 64 | + |
| 65 | + - name: Upload coverage to Codecov |
| 66 | + uses: codecov/codecov-action@v4 |
| 67 | + with: |
| 68 | + files: ./coverage/lcov.info |
| 69 | + fail_ci_if_error: false |
| 70 | + verbose: true |
| 71 | + |
| 72 | + - name: Upload coverage to Coveralls |
| 73 | + uses: coverallsapp/github-action@v2 |
| 74 | + with: |
| 75 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + path-to-lcov: ./coverage/lcov.info |
| 77 | + continue-on-error: true |
| 78 | + |
| 79 | + - name: Verify coverage thresholds |
| 80 | + run: | |
| 81 | + echo "Checking coverage thresholds..." |
| 82 | + if [ -f coverage/coverage-summary.json ]; then |
| 83 | + LINES=$(cat coverage/coverage-summary.json | jq '.total.lines.pct') |
| 84 | + FUNCTIONS=$(cat coverage/coverage-summary.json | jq '.total.functions.pct') |
| 85 | + BRANCHES=$(cat coverage/coverage-summary.json | jq '.total.branches.pct') |
| 86 | + STATEMENTS=$(cat coverage/coverage-summary.json | jq '.total.statements.pct') |
| 87 | +
|
| 88 | + echo "Coverage Summary:" |
| 89 | + echo " Lines: $LINES%" |
| 90 | + echo " Functions: $FUNCTIONS%" |
| 91 | + echo " Branches: $BRANCHES%" |
| 92 | + echo " Statements: $STATEMENTS%" |
| 93 | +
|
| 94 | + # For now, just report coverage without failing |
| 95 | + # Uncomment below to enforce 100% coverage |
| 96 | + # if (( $(echo "$LINES < 100" | bc -l) )); then |
| 97 | + # echo "❌ Line coverage is below 100%: $LINES%" |
| 98 | + # exit 1 |
| 99 | + # fi |
| 100 | + else |
| 101 | + echo "⚠️ Coverage summary not found" |
| 102 | + fi |
| 103 | +
|
| 104 | + - name: Comment coverage on PR |
| 105 | + if: github.event_name == 'pull_request' |
| 106 | + |
| 107 | + with: |
| 108 | + lcov-file: ./coverage/lcov.info |
| 109 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 110 | + continue-on-error: true |
| 111 | + |
| 112 | + - name: Upload test results |
| 113 | + if: always() |
| 114 | + uses: actions/upload-artifact@v4 |
| 115 | + with: |
| 116 | + name: test-results |
| 117 | + path: | |
| 118 | + coverage/ |
| 119 | + **/*.log |
| 120 | +
|
| 121 | + - name: Test Summary |
| 122 | + if: always() |
| 123 | + run: | |
| 124 | + echo "## Test Results Summary" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 126 | + if [ -f coverage/coverage-summary.json ]; then |
| 127 | + echo "### Coverage:" >> $GITHUB_STEP_SUMMARY |
| 128 | + echo "| Metric | Coverage |" >> $GITHUB_STEP_SUMMARY |
| 129 | + echo "|--------|----------|" >> $GITHUB_STEP_SUMMARY |
| 130 | + echo "| Lines | $(cat coverage/coverage-summary.json | jq -r '.total.lines.pct')% |" >> $GITHUB_STEP_SUMMARY |
| 131 | + echo "| Functions | $(cat coverage/coverage-summary.json | jq -r '.total.functions.pct')% |" >> $GITHUB_STEP_SUMMARY |
| 132 | + echo "| Branches | $(cat coverage/coverage-summary.json | jq -r '.total.branches.pct')% |" >> $GITHUB_STEP_SUMMARY |
| 133 | + echo "| Statements | $(cat coverage/coverage-summary.json | jq -r '.total.statements.pct')% |" >> $GITHUB_STEP_SUMMARY |
| 134 | + fi |
| 135 | +
|
| 136 | + build: |
| 137 | + runs-on: ubuntu-latest |
| 138 | + needs: test |
| 139 | + |
| 140 | + steps: |
| 141 | + - name: Checkout code |
| 142 | + uses: actions/checkout@v4 |
| 143 | + |
| 144 | + - name: Setup Node.js |
| 145 | + uses: actions/setup-node@v4 |
| 146 | + with: |
| 147 | + node-version: 18.x |
| 148 | + |
| 149 | + - name: Install pnpm |
| 150 | + uses: pnpm/action-setup@v4 |
| 151 | + with: |
| 152 | + version: 8.6.11 |
| 153 | + |
| 154 | + - name: Install dependencies |
| 155 | + run: pnpm install --frozen-lockfile |
| 156 | + |
| 157 | + - name: Build project |
| 158 | + run: pnpm build |
| 159 | + |
| 160 | + - name: Upload build artifacts |
| 161 | + uses: actions/upload-artifact@v4 |
| 162 | + with: |
| 163 | + name: dist |
| 164 | + path: dist/ |
| 165 | + retention-days: 7 |
0 commit comments