-
Notifications
You must be signed in to change notification settings - Fork 4
180 lines (153 loc) · 5.98 KB
/
Copy pathsentrux-quality-gate.yml
File metadata and controls
180 lines (153 loc) · 5.98 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
name: Sentrux Quality Gate
on:
workflow_dispatch:
concurrency:
group: sentrux-quality-${{ github.ref }}
cancel-in-progress: true
env:
GITEA_URL: https://git.terraphim.cloud
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
jobs:
quality-check:
name: Structural Quality Check
runs-on: [self-hosted, bigbox]
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 1
clean: true
- name: Run Sentrux Check
id: sentrux
run: |
# Run sentrux and capture output
OUTPUT=$(sentrux check . 2>&1)
echo "$OUTPUT"
# Extract quality signal
QUALITY=$(echo "$OUTPUT" | grep "Quality:" | awk '{print $2}')
echo "quality=$QUALITY" >> $GITHUB_OUTPUT
# Count violations
VIOLATIONS=$(echo "$OUTPUT" | grep "violation(s) found" | awk '{print $2}')
echo "violations=$VIOLATIONS" >> $GITHUB_OUTPUT
# Determine status
if echo "$OUTPUT" | grep -q "✗.*violation"; then
echo "status=fail" >> $GITHUB_OUTPUT
else
echo "status=pass" >> $GITHUB_OUTPUT
fi
# Save full output for comment
echo "output<<EOF" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Fetch Baseline (PR only)
if: github.event_name == 'pull_request'
id: baseline
run: |
# Try to get baseline from wiki
BASELINE=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
"$GITEA_URL/api/v1/repos/${{ github.repository }}/wiki/sentrux-baseline" 2>/dev/null | \
python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('content','').strip())" 2>/dev/null || echo "0")
if [ "$BASELINE" = "0" ] || [ -z "$BASELINE" ]; then
echo "baseline=0" >> $GITHUB_OUTPUT
echo "No baseline found"
else
echo "baseline=$BASELINE" >> $GITHUB_OUTPUT
echo "Baseline: $BASELINE"
fi
- name: Calculate Delta (PR only)
if: github.event_name == 'pull_request'
id: delta
run: |
CURRENT=${{ steps.sentrux.outputs.quality }}
BASELINE=${{ steps.baseline.outputs.baseline }}
if [ "$BASELINE" = "0" ] || [ -z "$BASELINE" ]; then
echo "delta=unknown" >> $GITHUB_OUTPUT
echo "degraded=false" >> $GITHUB_OUTPUT
else
DELTA=$((CURRENT - BASELINE))
echo "delta=$DELTA" >> $GITHUB_OUTPUT
if [ $DELTA -lt -100 ]; then
echo "degraded=true" >> $GITHUB_OUTPUT
else
echo "degraded=false" >> $GITHUB_OUTPUT
fi
fi
- name: Save Baseline (main/develop push only)
if: github.event_name == 'push'
run: |
CURRENT=${{ steps.sentrux.outputs.quality }}
REPO="${{ github.repository }}"
# Create or update wiki page with baseline
curl -s -X POST -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"title\":\"sentrux-baseline\",\"content\":\"$CURRENT\",\"message\":\"Update baseline: $CURRENT\"}" \
"$GITEA_URL/api/v1/repos/$REPO/wiki/new" 2>/dev/null || \
curl -s -X POST -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"content\":\"$CURRENT\",\"message\":\"Update baseline: $CURRENT\"}" \
"$GITEA_URL/api/v1/repos/$REPO/wiki/sentrux-baseline" 2>/dev/null || true
echo "Baseline saved: $CURRENT"
- name: Post PR Comment
if: github.event_name == 'pull_request' && always()
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
REPO="${{ github.repository }}"
QUALITY="${{ steps.sentrux.outputs.quality }}"
VIOLATIONS="${{ steps.sentrux.outputs.violations }}"
STATUS="${{ steps.sentrux.outputs.status }}"
DELTA="${{ steps.delta.outputs.delta }}"
DEGRADED="${{ steps.delta.outputs.degraded }}"
# Build comment body
if [ "$STATUS" = "pass" ]; then
STATUS_ICON="✅"
else
STATUS_ICON="❌"
fi
if [ "$DEGRADED" = "true" ]; then
DELTA_ICON="🔴"
elif [ "$DEGRADED" = "false" ] && [ "$DELTA" != "unknown" ]; then
DELTA_ICON="🟢"
else
DELTA_ICON="⚪"
fi
COMMENT="## Sentrux Quality Gate $STATUS_ICON
**Quality Signal:** $QUALITY / 10000
**Violations:** $VIOLATIONS
**Status:** $STATUS
"
if [ "$DELTA" != "unknown" ]; then
COMMENT="${COMMENT}**Delta:** $DELTA_ICON $DELTA points (baseline: $BASELINE)
"
if [ "$DEGRADED" = "true" ]; then
COMMENT="${COMMENT}
🔴 **Quality degraded by more than 100 points!**
"
fi
else
COMMENT="${COMMENT}**Delta:** No baseline available
"
fi
COMMENT="${COMMENT}
<details>
<summary>Full Report</summary>
\`\`\`
${{ steps.sentrux.outputs.output }}
\`\`\`
</details>
"
# Post comment
curl -s -X POST -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"body\":\"$COMMENT\"}" \
"$GITEA_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments" > /dev/null
- name: Fail on Quality Degradation
if: github.event_name == 'pull_request' && steps.delta.outputs.degraded == 'true'
run: |
echo "Quality degraded by more than 100 points. Blocking merge."
exit 1
- name: Fail on Rule Violations
if: steps.sentrux.outputs.status == 'fail'
run: |
echo "Architectural rule violations found. Blocking merge."
exit 1