|
| 1 | +name: Stash Test Suite |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop, 'feat/**' ] |
| 6 | + paths: |
| 7 | + - 'apps/cli/src/stash/**' |
| 8 | + - 'apps/cli/src/commands/stash.ts' |
| 9 | + - 'apps/cli/__tests__/**' |
| 10 | + - '.github/workflows/stash-tests.yml' |
| 11 | + pull_request: |
| 12 | + branches: [ main, develop ] |
| 13 | + paths: |
| 14 | + - 'apps/cli/src/stash/**' |
| 15 | + - 'apps/cli/src/commands/stash.ts' |
| 16 | + - 'apps/cli/__tests__/**' |
| 17 | + |
| 18 | +jobs: |
| 19 | + test: |
| 20 | + runs-on: ${{ matrix.os }} |
| 21 | + |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + os: [ubuntu-latest, macos-latest] |
| 25 | + node-version: [18.x, 20.x, 22.x] |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout code |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Setup Node.js ${{ matrix.node-version }} |
| 32 | + uses: actions/setup-node@v4 |
| 33 | + with: |
| 34 | + node-version: ${{ matrix.node-version }} |
| 35 | + cache: 'npm' |
| 36 | + cache-dependency-path: 'apps/cli/package-lock.json' |
| 37 | + |
| 38 | + - name: Install dependencies |
| 39 | + run: | |
| 40 | + cd apps/cli |
| 41 | + npm ci |
| 42 | + |
| 43 | + - name: Run Stash Tests |
| 44 | + run: | |
| 45 | + cd apps/cli |
| 46 | + bash __tests__/scripts/run-all-tests.sh |
| 47 | + env: |
| 48 | + CI: true |
| 49 | + |
| 50 | + - name: Generate Test Report |
| 51 | + if: always() |
| 52 | + run: | |
| 53 | + cd apps/cli |
| 54 | + npm run test:coverage -- --coverageReporters=json-summary |
| 55 | + |
| 56 | + - name: Upload Test Results |
| 57 | + if: always() |
| 58 | + uses: actions/upload-artifact@v4 |
| 59 | + with: |
| 60 | + name: test-results-${{ matrix.os }}-node${{ matrix.node-version }} |
| 61 | + path: | |
| 62 | + apps/cli/coverage/ |
| 63 | + apps/cli/test-reports/ |
| 64 | + retention-days: 30 |
| 65 | + |
| 66 | + - name: Comment PR with Results |
| 67 | + if: github.event_name == 'pull_request' && always() |
| 68 | + uses: actions/github-script@v7 |
| 69 | + with: |
| 70 | + script: | |
| 71 | + const fs = require('fs'); |
| 72 | + |
| 73 | + let comment = `## 🧪 Stash Test Results\n\n`; |
| 74 | + comment += `**OS**: ${{ matrix.os }}\n`; |
| 75 | + comment += `**Node**: ${{ matrix.node-version }}\n\n`; |
| 76 | + |
| 77 | + try { |
| 78 | + const coverage = JSON.parse( |
| 79 | + fs.readFileSync('apps/cli/coverage/coverage-summary.json', 'utf8') |
| 80 | + ); |
| 81 | + |
| 82 | + const total = coverage.total; |
| 83 | + comment += `### Coverage\n\n`; |
| 84 | + comment += `- **Lines**: ${total.lines.pct}%\n`; |
| 85 | + comment += `- **Statements**: ${total.statements.pct}%\n`; |
| 86 | + comment += `- **Functions**: ${total.functions.pct}%\n`; |
| 87 | + comment += `- **Branches**: ${total.branches.pct}%\n\n`; |
| 88 | + } catch (e) { |
| 89 | + comment += `_Coverage report not available_\n\n`; |
| 90 | + } |
| 91 | + |
| 92 | + comment += `**Status**: ${{ job.status }}\n`; |
| 93 | + |
| 94 | + github.rest.issues.createComment({ |
| 95 | + issue_number: context.issue.number, |
| 96 | + owner: context.repo.owner, |
| 97 | + repo: context.repo.repo, |
| 98 | + body: comment |
| 99 | + }); |
| 100 | + |
| 101 | + coverage: |
| 102 | + runs-on: ubuntu-latest |
| 103 | + needs: test |
| 104 | + |
| 105 | + steps: |
| 106 | + - name: Checkout code |
| 107 | + uses: actions/checkout@v4 |
| 108 | + |
| 109 | + - name: Setup Node.js |
| 110 | + uses: actions/setup-node@v4 |
| 111 | + with: |
| 112 | + node-version: 20.x |
| 113 | + |
| 114 | + - name: Install dependencies |
| 115 | + run: | |
| 116 | + cd apps/cli |
| 117 | + npm ci |
| 118 | + |
| 119 | + - name: Generate Coverage Report |
| 120 | + run: | |
| 121 | + cd apps/cli |
| 122 | + npm run test:coverage |
| 123 | + |
| 124 | + - name: Upload Coverage to Codecov |
| 125 | + uses: codecov/codecov-action@v4 |
| 126 | + with: |
| 127 | + files: apps/cli/coverage/coverage-final.json |
| 128 | + flags: stash-tests |
| 129 | + name: stash-coverage |
| 130 | + fail_ci_if_error: false |
| 131 | + |
0 commit comments