|
| 1 | +name: Check Current Data Health |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 3 * * 1' |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: check-current-data-health |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + issues: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + check-data-health: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v7 |
| 23 | + |
| 24 | + - name: Setup Node.js |
| 25 | + uses: actions/setup-node@v7 |
| 26 | + with: |
| 27 | + node-version: '22' |
| 28 | + cache: 'npm' |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: npm ci |
| 32 | + |
| 33 | + - name: Check current data health |
| 34 | + id: data-health |
| 35 | + continue-on-error: true |
| 36 | + run: | |
| 37 | + npx tsx scripts/validate/data-health.ts \ |
| 38 | + --as-of="$(TZ=Asia/Shanghai date +%F)" \ |
| 39 | + --fail-on=error \ |
| 40 | + --fail-on-code=stale-verification,future-verification-date \ |
| 41 | + 2>&1 | tee data-health-current.log |
| 42 | +
|
| 43 | + - name: Report stale or invalid data |
| 44 | + if: steps.data-health.outcome == 'failure' |
| 45 | + uses: actions/github-script@v8 |
| 46 | + with: |
| 47 | + script: | |
| 48 | + const fs = require('node:fs'); |
| 49 | + const title = 'Current manifest data requires review'; |
| 50 | + const output = fs.readFileSync('data-health-current.log', 'utf8').slice(-6000); |
| 51 | + const body = `## Current Data Health Check Failed |
| 52 | +
|
| 53 | + The scheduled check evaluates freshness against today's date in Asia/Shanghai without |
| 54 | + rewriting the committed snapshot. |
| 55 | +
|
| 56 | + **Check run:** [View details](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 57 | +
|
| 58 | + \`\`\`text |
| 59 | + ${output} |
| 60 | + \`\`\``; |
| 61 | +
|
| 62 | + const issues = await github.paginate(github.rest.issues.listForRepo, { |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + state: 'open', |
| 66 | + labels: 'automated', |
| 67 | + per_page: 100 |
| 68 | + }); |
| 69 | + const existingIssue = issues.find(issue => issue.title === title); |
| 70 | +
|
| 71 | + if (!existingIssue) { |
| 72 | + await github.rest.issues.create({ |
| 73 | + owner: context.repo.owner, |
| 74 | + repo: context.repo.repo, |
| 75 | + title, |
| 76 | + body, |
| 77 | + labels: ['automated', 'maintenance'] |
| 78 | + }); |
| 79 | + } else { |
| 80 | + await github.rest.issues.update({ |
| 81 | + owner: context.repo.owner, |
| 82 | + repo: context.repo.repo, |
| 83 | + issue_number: existingIssue.number, |
| 84 | + body |
| 85 | + }); |
| 86 | + } |
| 87 | +
|
| 88 | + - name: Close resolved data-health issues |
| 89 | + if: steps.data-health.outcome == 'success' |
| 90 | + uses: actions/github-script@v8 |
| 91 | + with: |
| 92 | + script: | |
| 93 | + const issues = await github.paginate(github.rest.issues.listForRepo, { |
| 94 | + owner: context.repo.owner, |
| 95 | + repo: context.repo.repo, |
| 96 | + state: 'open', |
| 97 | + labels: 'automated', |
| 98 | + per_page: 100 |
| 99 | + }); |
| 100 | +
|
| 101 | + for (const issue of issues.filter(issue => issue.title === 'Current manifest data requires review')) { |
| 102 | + await github.rest.issues.createComment({ |
| 103 | + owner: context.repo.owner, |
| 104 | + repo: context.repo.repo, |
| 105 | + issue_number: issue.number, |
| 106 | + body: `Current-date data health passed in ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}.` |
| 107 | + }); |
| 108 | + await github.rest.issues.update({ |
| 109 | + owner: context.repo.owner, |
| 110 | + repo: context.repo.repo, |
| 111 | + issue_number: issue.number, |
| 112 | + state: 'closed', |
| 113 | + state_reason: 'completed' |
| 114 | + }); |
| 115 | + } |
| 116 | +
|
| 117 | + - name: Fail after reporting |
| 118 | + if: steps.data-health.outcome == 'failure' |
| 119 | + run: exit 1 |
0 commit comments