forked from SynkraAI/aiox-core
-
Notifications
You must be signed in to change notification settings - Fork 0
226 lines (195 loc) · 7.42 KB
/
Copy pathpr-automation.yml
File metadata and controls
226 lines (195 loc) · 7.42 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
name: PR Automation
# Story 6.1: Simplified to metrics-only (validation moved to ci.yml)
# Purpose: Coverage reporting, quality summary, and metrics recording
on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
concurrency:
group: pr-automation-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
checks: write
env:
NODE_VERSION: '20'
jobs:
# ============================================================================
# COVERAGE EXTRACTION & REPORTING
# ============================================================================
coverage-report:
name: Coverage Report
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
coverage-summary: ${{ steps.coverage.outputs.summary }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests with coverage
run: npm run test:coverage
continue-on-error: true
- name: Extract coverage summary
id: coverage
run: |
if [ -f coverage/coverage-summary.json ]; then
LINES=$(jq '.total.lines.pct' coverage/coverage-summary.json)
STATEMENTS=$(jq '.total.statements.pct' coverage/coverage-summary.json)
BRANCHES=$(jq '.total.branches.pct' coverage/coverage-summary.json)
FUNCTIONS=$(jq '.total.functions.pct' coverage/coverage-summary.json)
echo "summary=Lines: ${LINES}% | Statements: ${STATEMENTS}% | Branches: ${BRANCHES}% | Functions: ${FUNCTIONS}%" >> $GITHUB_OUTPUT
else
echo "summary=Coverage report not available" >> $GITHUB_OUTPUT
fi
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v6
with:
files: ./coverage/lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
# ============================================================================
# PR COMMENTS (Coverage + Quality Summary)
# ============================================================================
post-comments:
name: Post PR Comments
runs-on: ubuntu-latest
needs: [coverage-report]
if: always()
steps:
- name: Post coverage comment
uses: actions/github-script@v9
with:
script: |
const coverageSummary = '${{ needs.coverage-report.outputs.coverage-summary }}' || 'Coverage data not available';
const body = `## 📊 Coverage Report
${coverageSummary}
> 📈 Full coverage report available in [Codecov](https://codecov.io/gh/${{ github.repository }}/pull/${{ github.event.pull_request.number }})
---
*Generated by PR Automation (Story 6.1)*
`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📊 Coverage Report')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
# ============================================================================
# CODERABBIT STATUS CHECK
# ============================================================================
coderabbit-check:
name: CodeRabbit Status
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Verify CodeRabbit config exists
uses: actions/checkout@v6
with:
sparse-checkout: .coderabbit.yaml
sparse-checkout-cone-mode: false
- name: Validate config
run: |
echo "🐰 CodeRabbit Integration Status"
echo "================================"
if [ -f ".coderabbit.yaml" ]; then
echo "✅ CodeRabbit configuration found"
else
echo "⚠️ CodeRabbit configuration not found"
fi
echo ""
echo "Note: CodeRabbit reviews are handled by the GitHub App"
# ============================================================================
# METRICS RECORDING (Story 3.11c)
# ============================================================================
record-metrics:
name: Record Quality Metrics
runs-on: ubuntu-latest
needs: [coverage-report]
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Record PR metrics
env:
COVERAGE_RESULT: ${{ needs.coverage-report.result }}
PR_NUMBER: ${{ github.event.pull_request.number }}
BRANCH_NAME: ${{ github.head_ref }}
AUTHOR: ${{ github.actor }}
run: |
node -e "
const { recordPRReviewMetrics } = require('./.aiox-core/quality/metrics-hook');
(async () => {
const passed = process.env.COVERAGE_RESULT === 'success';
await recordPRReviewMetrics({
passed,
durationMs: 180000,
findingsCount: 0,
metadata: {
prNumber: parseInt(process.env.PR_NUMBER, 10),
branchName: process.env.BRANCH_NAME,
author: process.env.AUTHOR,
coverageResult: process.env.COVERAGE_RESULT
}
});
console.log('✅ PR metrics recorded');
})().catch(err => {
console.warn('⚠️ Failed to record metrics:', err.message);
process.exit(0);
});
"
- name: Commit metrics update
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Check if metrics file exists and is not gitignored
if [ -f .aiox/data/quality-metrics.json ]; then
if git check-ignore -q .aiox/data/quality-metrics.json 2>/dev/null; then
echo "ℹ️ Metrics file is gitignored - skipping commit"
else
git add .aiox/data/quality-metrics.json
fi
fi
if ! git diff --staged --quiet; then
git commit -m "chore(metrics): update quality metrics [skip ci]"
git push || echo "Push skipped (may conflict with parallel runs)"
else
echo "ℹ️ No metrics changes to commit"
fi