-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (103 loc) · 4.62 KB
/
Copy pathdrift-detection.yml
File metadata and controls
119 lines (103 loc) · 4.62 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
114
115
116
117
118
119
name: API Drift Detection
on:
schedule:
- cron: '0 8 * * 1-5' # 8am UTC, weekdays
workflow_dispatch:
jobs:
detect-drift:
name: Check for API Drift
runs-on: ubuntu-latest
outputs:
drift_detected: ${{ steps.drift.outputs.has_drift }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
run: npm ci --no-audit --no-fund --ignore-scripts
- name: Run drift detection
id: drift
uses: actions/github-script@v9
with:
script: |
const { execSync } = require('child_process');
let stdout = '';
let exitCode = 0;
try {
stdout = execSync('npm run --silent detect-drift -- --json', {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 120_000,
});
} catch (err) {
exitCode = err.status ?? 1;
stdout = err.stdout ?? '';
const stderr = err.stderr ?? '';
if (stderr) {
core.info(`--- stderr ---\n${stderr}`);
}
}
core.setOutput('exit_code', String(exitCode));
core.info(stdout);
if (exitCode === 0) {
core.setOutput('has_drift', 'false');
return;
}
let report;
try {
report = JSON.parse(stdout);
} catch {
core.warning('Drift report is missing or malformed');
core.setOutput('has_drift', 'false');
return;
}
if (!report.hasDrift) {
core.notice(`No actual drift found (totalDrift=${report.totalDrift}), skipping alert`);
core.setOutput('has_drift', 'false');
return;
}
core.setOutput('has_drift', 'true');
core.setOutput('total', String(report.totalDrift));
core.setOutput('skill_missing', String(report.drift.inSpecNotSkill.length));
core.setOutput('skill_extra', String(report.drift.inSkillNotSpec.length));
core.setOutput('sdk_missing', String(report.drift.inSpecNotSdk.length));
core.setOutput('sdk_extra', String(report.drift.inSdkNotSpec.length));
- name: Alert on drift
if: steps.drift.outputs.has_drift == 'true'
uses: ./.github/actions/slack-post
env:
SLACK_TOKEN: ${{ secrets.SLACK_NOTIF_BOT_TOKEN }}
with:
channel: '#agentic-service-alerts'
header: 'SDK API Drift Detected'
content: |
[
{"type": "section", "text": {"type": "mrkdwn", "text": "*${{ steps.drift.outputs.total }} endpoint(s) out of sync*\n\n*skill.md vs spec:*\n• Missing from skill.md: ${{ steps.drift.outputs.skill_missing }}\n• Extra in skill.md: ${{ steps.drift.outputs.skill_extra }}\n\n*SDK vs spec:*\n• Missing from SDK: ${{ steps.drift.outputs.sdk_missing }}\n• Extra in SDK: ${{ steps.drift.outputs.sdk_extra }}"}},
{"type": "section", "text": {"type": "mrkdwn", "text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View full report>"}}
]
- name: Alert on script error
if: steps.drift.outputs.exit_code != '0' && steps.drift.outputs.has_drift != 'true'
uses: ./.github/actions/slack-post
env:
SLACK_TOKEN: ${{ secrets.SLACK_NOTIF_BOT_TOKEN }}
with:
channel: '#agentic-service-alerts'
header: 'Drift Detection Script Error'
content: '[{"type": "section", "text": {"type": "mrkdwn", "text": "The drift detection script exited with code ${{ steps.drift.outputs.exit_code || ''unknown'' }} but produced no valid drift report. <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View run>"}}]'
- name: Notify on failure
if: failure()
uses: ./.github/actions/slack-post
env:
SLACK_TOKEN: ${{ secrets.SLACK_NOTIF_BOT_TOKEN }}
with:
channel: '#agentic-service-alerts'
header: 'API Drift Detection Failed'
content: '[{"type": "section", "text": {"type": "mrkdwn", "text": "The drift detection workflow failed. <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View run>"}}]'
regenerate:
name: Regenerate Schemas
needs: detect-drift
if: needs.detect-drift.outputs.drift_detected == 'true'
uses: ./.github/workflows/regenerate-schemas.yml
secrets: inherit