|
| 1 | +name: Daily Health Check |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Runs every day at 9 AM UTC |
| 6 | + - cron: '0 9 1 * *' # 1st day of every month at 9 AM UTC |
| 7 | + workflow_dispatch: # Allow manual trigger for testing |
| 8 | + |
| 9 | +jobs: |
| 10 | + health-check: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Node.js |
| 18 | + uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version: '22' |
| 21 | + cache: 'npm' |
| 22 | + |
| 23 | + - name: Install dependencies |
| 24 | + run: npm ci |
| 25 | + |
| 26 | + - name: Run tests |
| 27 | + id: tests |
| 28 | + run: npm test -- --passWithNoTests --watchAll=false |
| 29 | + continue-on-error: true |
| 30 | + |
| 31 | + - name: Check build |
| 32 | + id: build |
| 33 | + run: npm run build |
| 34 | + continue-on-error: true |
| 35 | + env: |
| 36 | + CI: false |
| 37 | + |
| 38 | + - name: Verify build output |
| 39 | + run: | |
| 40 | + if [ ! -d "build" ]; then |
| 41 | + echo "Build directory not found!" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + BUILD_SIZE=$(du -sh build | cut -f1) |
| 45 | + echo "Build successful! Size: $BUILD_SIZE" |
| 46 | + echo "BUILD_SIZE=$BUILD_SIZE" >> $GITHUB_ENV |
| 47 | + |
| 48 | + - name: Check dependencies for security issues |
| 49 | + run: npm audit --audit-level=high || echo "Security vulnerabilities found" |
| 50 | + continue-on-error: true |
| 51 | + |
| 52 | + - name: Display summary |
| 53 | + run: | |
| 54 | + echo "## Health Check Summary" |
| 55 | + echo "Tests: ${{ steps.tests.outcome }}" |
| 56 | + echo "Build: ${{ steps.build.outcome }}" |
| 57 | + echo "Build Size: $BUILD_SIZE" |
| 58 | + |
| 59 | + - name: Create issue on failure |
| 60 | + if: failure() |
| 61 | + uses: actions/github-script@v7 |
| 62 | + with: |
| 63 | + script: | |
| 64 | + const date = new Date().toISOString().split('T')[0]; |
| 65 | + const runUrl = context.payload.repository.html_url + '/actions/runs/' + context.runId; |
| 66 | + |
| 67 | + const title = 'Health Check Failed - ' + date; |
| 68 | + const body = '# Health Check Failure Report\n\n' + |
| 69 | + '**Date:** ' + date + '\n' + |
| 70 | + '**Workflow:** Daily Health Check\n' + |
| 71 | + '**Status:** Failed\n\n' + |
| 72 | + '## Details\n\n' + |
| 73 | + 'The automated health check has detected issues with the repository.\n\n' + |
| 74 | + '### Failed Steps:\n' + |
| 75 | + '- Tests: ${{ steps.tests.outcome }}\n' + |
| 76 | + '- Build: ${{ steps.build.outcome }}\n\n' + |
| 77 | + '### Action Required:\n' + |
| 78 | + 'Please investigate and fix the issues.\n\n' + |
| 79 | + '[View workflow run](' + runUrl + ')\n\n' + |
| 80 | + '---\n' + |
| 81 | + '*Automated by GitHub Actions*'; |
| 82 | + |
| 83 | + github.rest.issues.create({ |
| 84 | + owner: context.repo.owner, |
| 85 | + repo: context.repo.repo, |
| 86 | + title: title, |
| 87 | + body: body, |
| 88 | + labels: ['bug', 'automated', 'health-check'] |
| 89 | + }); |
0 commit comments