Implement comprehensive code review improvements #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Daily Tests & Auto-Fix | ||
| on: | ||
| schedule: | ||
| # Run every day at 6 AM UTC | ||
| - cron: '0 6 * * *' | ||
| workflow_dispatch: # Allow manual trigger | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| - name: Install dependencies | ||
| run: npm ci | ||
| - name: Run tests | ||
| id: test | ||
| run: | | ||
| npm test -- --json --outputFile=test-results.json 2>&1 | tee test-output.txt || true | ||
| if grep -q "FAIL" test-output.txt; then | ||
| echo "tests_failed=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "tests_failed=false" >> $GITHUB_OUTPUT | ||
| fi | ||
| continue-on-error: true | ||
| - name: Upload test results | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: test-results | ||
| path: | | ||
| test-results.json | ||
| test-output.txt | ||
| - name: Auto-fix with Claude | ||
| if: steps.test.outputs.tests_failed == 'true' | ||
| env: | ||
| ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | ||
| run: | | ||
| npm run fix-tests | ||
| - name: Run tests again after fix | ||
| if: steps.test.outputs.tests_failed == 'true' | ||
| id: retest | ||
| run: | | ||
| npm test 2>&1 | tee retest-output.txt || true | ||
| if grep -q "FAIL" retest-output.txt; then | ||
| echo "still_failing=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "still_failing=false" >> $GITHUB_OUTPUT | ||
| fi | ||
| continue-on-error: true | ||
| - name: Commit fixes | ||
| if: steps.test.outputs.tests_failed == 'true' | ||
| run: | | ||
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
| git config --local user.name "github-actions[bot]" | ||
| git add -A | ||
| if git diff --staged --quiet; then | ||
| echo "No changes to commit" | ||
| else | ||
| git commit -m "fix: Auto-fix broken tests via Claude | ||
| Automated fix triggered by daily test run. | ||
| Co-Authored-By: Claude <noreply@anthropic.com>" | ||
| git push | ||
| fi | ||
| - name: Create issue if tests still failing | ||
| if: steps.retest.outputs.still_failing == 'true' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const testOutput = fs.readFileSync('retest-output.txt', 'utf8'); | ||
| // Extract failing tests | ||
| const failingTests = testOutput.match(/FAIL .+/g) || []; | ||
| await github.rest.issues.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title: `[Auto] Tests failing after auto-fix attempt - ${new Date().toISOString().split('T')[0]}`, | ||
| body: `## Daily Test Run Failed | ||
| The daily test run found failing tests that could not be automatically fixed. | ||
| ### Failing Tests | ||
| \`\`\` | ||
| ${failingTests.join('\n')} | ||
| \`\`\` | ||
| ### Full Output | ||
| <details> | ||
| <summary>Click to expand</summary> | ||
| \`\`\` | ||
| ${testOutput.slice(0, 5000)} | ||
| \`\`\` | ||
| </details> | ||
| ### Action Required | ||
| Please review and fix these tests manually. | ||
| --- | ||
| *This issue was automatically created by the daily test workflow.*`, | ||
| labels: ['bug', 'automated', 'tests'] | ||
| }); | ||