|
| 1 | +name: "Comprehensive Test Review with Playwright" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + pull_request: |
| 9 | + types: [opened, synchronize, reopened] |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + pull-requests: write |
| 15 | + checks: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + test-review-and-execution: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + browser: [chromium, firefox, webkit] |
| 23 | + mode: [headed, headless] |
| 24 | + steps: |
| 25 | + - name: Checkout code |
| 26 | + uses: actions/checkout@main |
| 27 | + |
| 28 | + - name: Setup Node.js |
| 29 | + uses: actions/setup-node@main |
| 30 | + with: |
| 31 | + node-version: '20' |
| 32 | + cache: 'npm' |
| 33 | + continue-on-error: true |
| 34 | + |
| 35 | + - name: Setup Python |
| 36 | + uses: actions/setup-python@main |
| 37 | + with: |
| 38 | + python-version: '3.11' |
| 39 | + cache: 'pip' |
| 40 | + continue-on-error: true |
| 41 | + |
| 42 | + - name: Install Node.js dependencies |
| 43 | + run: | |
| 44 | + if [ -f "package.json" ]; then |
| 45 | + npm install |
| 46 | + npm install -D @playwright/test playwright |
| 47 | + fi |
| 48 | + continue-on-error: true |
| 49 | + |
| 50 | + - name: Install Python dependencies |
| 51 | + run: | |
| 52 | + if [ -f "requirements.txt" ]; then |
| 53 | + pip install -r requirements.txt |
| 54 | + fi |
| 55 | + pip install pytest playwright pytest-playwright |
| 56 | + continue-on-error: true |
| 57 | + |
| 58 | + - name: Install Playwright browsers |
| 59 | + run: | |
| 60 | + npx playwright install --with-deps ${{ matrix.browser }} || python -m playwright install --with-deps ${{ matrix.browser }} |
| 61 | + continue-on-error: true |
| 62 | + |
| 63 | + - name: Verify Playwright installation |
| 64 | + run: | |
| 65 | + echo "Checking Playwright installation..." |
| 66 | + npx playwright --version || python -m playwright --version || echo "Playwright not installed" |
| 67 | +
|
| 68 | + - name: Run Playwright Tests (Headless) |
| 69 | + if: matrix.mode == 'headless' |
| 70 | + run: | |
| 71 | + if [ -f "playwright.config.ts" ] || [ -f "playwright.config.js" ]; then |
| 72 | + npx playwright test --browser=${{ matrix.browser }} |
| 73 | + elif [ -d "tests" ] && find tests -name "*test*.py" -o -name "*_test.py" | grep -q .; then |
| 74 | + pytest tests/ --browser ${{ matrix.browser }} --headed=false |
| 75 | + else |
| 76 | + echo "No Playwright tests found - this is OK if not a web project" |
| 77 | + fi |
| 78 | + env: |
| 79 | + CI: true |
| 80 | + continue-on-error: true |
| 81 | + |
| 82 | + - name: Run Playwright Tests (Headed) |
| 83 | + if: matrix.mode == 'headed' |
| 84 | + run: | |
| 85 | + if [ -f "playwright.config.ts" ] || [ -f "playwright.config.js" ]; then |
| 86 | + npx playwright test --browser=${{ matrix.browser }} --headed |
| 87 | + elif [ -d "tests" ] && find tests -name "*test*.py" -o -name "*_test.py" | grep -q .; then |
| 88 | + pytest tests/ --browser ${{ matrix.browser }} --headed=true |
| 89 | + else |
| 90 | + echo "No Playwright tests found - this is OK if not a web project" |
| 91 | + fi |
| 92 | + env: |
| 93 | + CI: true |
| 94 | + DISPLAY: :99 |
| 95 | + continue-on-error: true |
| 96 | + |
| 97 | + - name: Upload Playwright Test Results |
| 98 | + uses: actions/upload-artifact@main |
| 99 | + if: always() |
| 100 | + with: |
| 101 | + name: playwright-results-${{ matrix.browser }}-${{ matrix.mode }} |
| 102 | + path: | |
| 103 | + playwright-report/ |
| 104 | + test-results/ |
| 105 | + playwright-traces/ |
| 106 | + retention-days: 30 |
| 107 | + continue-on-error: true |
| 108 | + |
| 109 | + - name: Upload Playwright Screenshots on Failure |
| 110 | + uses: actions/upload-artifact@main |
| 111 | + if: failure() |
| 112 | + with: |
| 113 | + name: playwright-screenshots-${{ matrix.browser }}-${{ matrix.mode }} |
| 114 | + path: | |
| 115 | + screenshots/ |
| 116 | + test-results/**/screenshots/ |
| 117 | + retention-days: 7 |
| 118 | + continue-on-error: true |
| 119 | + |
| 120 | + test-coverage-review: |
| 121 | + runs-on: ubuntu-latest |
| 122 | + needs: test-review-and-execution |
| 123 | + steps: |
| 124 | + - name: Checkout code |
| 125 | + uses: actions/checkout@main |
| 126 | + |
| 127 | + - name: Analyze Test Coverage |
| 128 | + id: coverage |
| 129 | + run: | |
| 130 | + echo "## Test Coverage Analysis" > /tmp/test-analysis.md |
| 131 | + echo "" >> /tmp/test-analysis.md |
| 132 | + |
| 133 | + # Find test files |
| 134 | + echo "### Test Files Found:" >> /tmp/test-analysis.md |
| 135 | + find . -type f \( -name "*test*.js" -o -name "*test*.ts" -o -name "*test*.py" -o -name "*spec*.js" -o -name "*spec*.ts" \) \ |
| 136 | + ! -path "*/node_modules/*" \ |
| 137 | + ! -path "*/dist/*" \ |
| 138 | + ! -path "*/.venv/*" \ |
| 139 | + -exec echo "- {}" \; >> /tmp/test-analysis.md || echo "No test files found" >> /tmp/test-analysis.md |
| 140 | + |
| 141 | + echo "" >> /tmp/test-analysis.md |
| 142 | + echo "### Source Files Without Tests:" >> /tmp/test-analysis.md |
| 143 | + |
| 144 | + # Find source files that might need tests |
| 145 | + for file in $(find . -type f \( -name "*.js" -o -name "*.ts" -o -name "*.py" \) \ |
| 146 | + ! -path "*/node_modules/*" \ |
| 147 | + ! -path "*/dist/*" \ |
| 148 | + ! -path "*/build/*" \ |
| 149 | + ! -path "*/.venv/*" \ |
| 150 | + ! -path "*/vendor/*" \ |
| 151 | + ! -name "*test*" \ |
| 152 | + ! -name "*spec*"); do |
| 153 | + basename=$(basename "$file" | sed 's/\.[^.]*$//') |
| 154 | + |
| 155 | + # Check if corresponding test file exists |
| 156 | + if ! find . -name "*${basename}*test*" -o -name "*${basename}*spec*" 2>/dev/null | grep -q .; then |
| 157 | + echo "- $file (no corresponding test found)" >> /tmp/test-analysis.md |
| 158 | + fi |
| 159 | + done |
| 160 | + |
| 161 | + cat /tmp/test-analysis.md |
| 162 | +
|
| 163 | + - name: GitHub Copilot Test Review |
| 164 | + uses: github/copilot-cli-action@main |
| 165 | + with: |
| 166 | + query: | |
| 167 | + Review the test suite for this repository: |
| 168 | + 1. Verify all web-based functionality has Playwright tests (both headed and headless) |
| 169 | + 2. Identify missing test coverage for critical functionality |
| 170 | + 3. Check test quality and maintainability |
| 171 | + 4. Suggest improvements for test organization |
| 172 | + 5. Verify tests follow best practices (isolation, clarity, proper assertions) |
| 173 | + 6. Check for flaky tests or tests with timing issues |
| 174 | + 7. Ensure tests are running in CI/CD pipeline |
| 175 | + |
| 176 | + For any web tests not using Playwright, recommend migration. |
| 177 | + Provide specific, actionable recommendations with file names. |
| 178 | + env: |
| 179 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 180 | + continue-on-error: true |
| 181 | + |
| 182 | + - name: Create or Update Test Review Issue |
| 183 | + uses: actions/github-script@main |
| 184 | + with: |
| 185 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 186 | + script: | |
| 187 | + const fs = require('fs'); |
| 188 | + const analysis = fs.readFileSync('/tmp/test-analysis.md', 'utf8'); |
| 189 | + |
| 190 | + const date = new Date().toISOString().split('T')[0]; |
| 191 | + const title = `Test Coverage Review - ${date}`; |
| 192 | + |
| 193 | + const body = `# Comprehensive Test Review |
| 194 | + |
| 195 | + This automated review ensures proper test coverage with Playwright for web tests. |
| 196 | + |
| 197 | + ${analysis} |
| 198 | + |
| 199 | + ## Playwright Test Status |
| 200 | + |
| 201 | + ✅ Tests run in multiple browsers: Chromium, Firefox, WebKit |
| 202 | + ✅ Tests run in both headed and headless modes |
| 203 | + |
| 204 | + ## Recommendations |
| 205 | + |
| 206 | + 1. **Add Playwright tests** for all web-based functionality |
| 207 | + 2. **Migrate existing web tests** to Playwright if not already using it |
| 208 | + 3. **Add tests** for source files without coverage |
| 209 | + 4. **Review test quality** and maintainability |
| 210 | + 5. **Fix flaky tests** and timing issues |
| 211 | + 6. **Ensure CI/CD integration** for all tests |
| 212 | + |
| 213 | + ## Action Items |
| 214 | + |
| 215 | + - [ ] Review files without tests and add coverage |
| 216 | + - [ ] Migrate non-Playwright web tests to Playwright |
| 217 | + - [ ] Fix any failing tests |
| 218 | + - [ ] Add documentation for test setup and execution |
| 219 | + |
| 220 | + --- |
| 221 | + *This issue was automatically generated by the Test Review workflow.* |
| 222 | + `; |
| 223 | + |
| 224 | + // Check if similar issue exists |
| 225 | + const issues = await github.rest.issues.listForRepo({ |
| 226 | + owner: context.repo.owner, |
| 227 | + repo: context.repo.repo, |
| 228 | + state: 'open', |
| 229 | + labels: ['test-coverage', 'automated'], |
| 230 | + per_page: 10 |
| 231 | + }); |
| 232 | + |
| 233 | + const recentIssue = issues.data.find(issue => { |
| 234 | + const createdAt = new Date(issue.created_at); |
| 235 | + const daysSinceCreation = (Date.now() - createdAt) / (1000 * 60 * 60 * 24); |
| 236 | + return daysSinceCreation < 7; |
| 237 | + }); |
| 238 | + |
| 239 | + if (recentIssue) { |
| 240 | + console.log(`Recent issue found: #${recentIssue.number}, updating`); |
| 241 | + await github.rest.issues.createComment({ |
| 242 | + owner: context.repo.owner, |
| 243 | + repo: context.repo.repo, |
| 244 | + issue_number: recentIssue.number, |
| 245 | + body: `## Updated Analysis (${date})\n\n${analysis}` |
| 246 | + }); |
| 247 | + } else { |
| 248 | + await github.rest.issues.create({ |
| 249 | + owner: context.repo.owner, |
| 250 | + repo: context.repo.repo, |
| 251 | + title: title, |
| 252 | + body: body, |
| 253 | + labels: ['test-coverage', 'automated', 'playwright', 'needs-review'] |
| 254 | + }); |
| 255 | + } |
0 commit comments