-
Notifications
You must be signed in to change notification settings - Fork 51
116 lines (99 loc) · 3.34 KB
/
postmortem-check.yml
File metadata and controls
116 lines (99 loc) · 3.34 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
name: Postmortem Check
on:
pull_request:
branches: [main, feature]
paths:
- 'app/**'
- 'api/**'
- 'tools/**'
- 'public/**'
push:
branches: [main]
paths:
- 'app/**'
- 'api/**'
- 'tools/**'
- 'public/**'
jobs:
postmortem-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install pyyaml
- name: Check for postmortem matches
id: check
run: |
# Determine base ref
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE_REF="${{ github.event.pull_request.base.sha }}"
else
BASE_REF="HEAD~1"
fi
# Check if postmortem directory exists
if [ ! -d "postmortem" ]; then
echo "No postmortem directory found. Skipping check."
exit 0
fi
# Run check (warn mode, don't block)
python tools/postmortem_check.py \
--base "$BASE_REF" \
--mode warn \
--threshold 0.7 \
--output text 2>&1 | tee postmortem_output.txt
# Save output for PR comment
echo "has_matches=false" >> $GITHUB_OUTPUT
if grep -q "\[BLOCK\]\|\[WARN\]" postmortem_output.txt; then
echo "has_matches=true" >> $GITHUB_OUTPUT
fi
continue-on-error: true
- name: Comment on PR
if: github.event_name == 'pull_request' && steps.check.outputs.has_matches == 'true'
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const output = fs.readFileSync('postmortem_output.txt', 'utf8');
const body = `## Postmortem Alert
This PR may touch code related to past incidents. Please review:
\`\`\`
${output.substring(0, 3000)}
\`\`\`
Run locally with:
\`\`\`bash
python tools/postmortem_check.py --base ${{ github.event.pull_request.base.sha }}
\`\`\`
`;
// Check if we already commented
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(c =>
c.user.login === 'github-actions[bot]' &&
c.body.includes('Postmortem Alert')
);
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}