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