Skip to content

Commit 6e24957

Browse files
committed
feat: improving performance
1 parent a3b5a2d commit 6e24957

47 files changed

Lines changed: 34888 additions & 917 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Accessibility Testing
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main]
8+
schedule:
9+
# Run daily at 2 AM UTC
10+
- cron: "0 2 * * *"
11+
12+
jobs:
13+
accessibility-test:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: "18"
24+
25+
- name: Install dependencies
26+
run: |
27+
npm install -g @axe-core/cli
28+
npm install -g pa11y
29+
npm install -g lighthouse
30+
31+
- name: Start web server
32+
run: |
33+
cd web_demo
34+
python -m http.server 8000 &
35+
sleep 5
36+
37+
- name: Run axe-core accessibility tests
38+
run: |
39+
axe http://localhost:8000 --exit
40+
continue-on-error: true
41+
42+
- name: Run pa11y accessibility tests
43+
run: |
44+
pa11y --standard WCAG2AA http://localhost:8000
45+
continue-on-error: true
46+
47+
- name: Run Lighthouse accessibility audit
48+
run: |
49+
lighthouse http://localhost:8000 --only-categories=accessibility --output=json --output-path=./lighthouse-accessibility.json
50+
continue-on-error: true
51+
52+
- name: Run custom accessibility validator
53+
run: |
54+
node -e "
55+
const puppeteer = require('puppeteer');
56+
(async () => {
57+
const browser = await puppeteer.launch();
58+
const page = await browser.newPage();
59+
await page.goto('http://localhost:8000');
60+
61+
// Run custom accessibility validation
62+
const results = await page.evaluate(() => {
63+
if (window.accessibilityValidator) {
64+
return window.accessibilityValidator.getReport();
65+
}
66+
return { error: 'Accessibility validator not found' };
67+
});
68+
69+
console.log('Accessibility Report:', JSON.stringify(results, null, 2));
70+
71+
if (results.errors > 0) {
72+
console.error('Accessibility errors found:', results.errors);
73+
process.exit(1);
74+
}
75+
76+
await browser.close();
77+
})();
78+
"
79+
continue-on-error: true
80+
81+
- name: Upload accessibility reports
82+
uses: actions/upload-artifact@v3
83+
if: always()
84+
with:
85+
name: accessibility-reports
86+
path: |
87+
lighthouse-accessibility.json
88+
pa11y-results.json
89+
90+
- name: Comment on PR with accessibility results
91+
if: github.event_name == 'pull_request'
92+
uses: actions/github-script@v7
93+
with:
94+
script: |
95+
const fs = require('fs');
96+
97+
let comment = '## 🔍 Accessibility Test Results\n\n';
98+
99+
try {
100+
const lighthouse = JSON.parse(fs.readFileSync('lighthouse-accessibility.json', 'utf8'));
101+
const score = Math.round(lighthouse.categories.accessibility.score * 100);
102+
comment += `### Lighthouse Accessibility Score: ${score}/100\n\n`;
103+
104+
if (score < 90) {
105+
comment += '⚠️ **Warning**: Accessibility score is below 90. Please review and fix accessibility issues.\n\n';
106+
} else {
107+
comment += '✅ **Good**: Accessibility score meets the target of 90+.\n\n';
108+
}
109+
} catch (error) {
110+
comment += '❌ **Error**: Could not load Lighthouse accessibility results.\n\n';
111+
}
112+
113+
comment += '### Next Steps\n';
114+
comment += '- Review the accessibility reports in the artifacts\n';
115+
comment += '- Fix any critical accessibility issues\n';
116+
comment += '- Test with screen readers and keyboard navigation\n';
117+
comment += '- Ensure color contrast meets WCAG AA standards\n\n';
118+
comment += 'For more information, see our [accessibility guidelines](https://github.com/SentinelOps-CI/understand-first/blob/main/docs/accessibility.md).';
119+
120+
github.rest.issues.createComment({
121+
issue_number: context.issue.number,
122+
owner: context.repo.owner,
123+
repo: context.repo.repo,
124+
body: comment
125+
});
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
name: Understand-First Commenter Service
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, closed]
6+
workflow_dispatch:
7+
inputs:
8+
pr_number:
9+
description: "PR number to analyze"
10+
required: true
11+
type: string
12+
13+
jobs:
14+
commenter-service:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
pull-requests: write
19+
checks: write
20+
actions: read
21+
statuses: write
22+
issues: write
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Set up Python
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: "3.11"
34+
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install typer rich aiohttp asyncpg pydantic requests
39+
40+
- name: Run Understand-First Commenter
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
PR_NUMBER: ${{ github.event.number || github.event.inputs.pr_number }}
44+
run: |
45+
python -c "
46+
import os
47+
import json
48+
import requests
49+
from datetime import datetime
50+
51+
# GitHub API setup
52+
token = os.environ['GITHUB_TOKEN']
53+
pr_number = os.environ['PR_NUMBER']
54+
repo = os.environ['GITHUB_REPOSITORY']
55+
56+
headers = {
57+
'Authorization': f'token {token}',
58+
'Accept': 'application/vnd.github.v3+json'
59+
}
60+
61+
# Get PR details
62+
pr_url = f'https://api.github.com/repos/{repo}/pulls/{pr_number}'
63+
pr_response = requests.get(pr_url, headers=headers)
64+
pr_data = pr_response.json()
65+
66+
base_sha = pr_data['base']['sha']
67+
head_sha = pr_data['head']['sha']
68+
69+
print(f'Analyzing PR #{pr_number}: {pr_data[\"title\"]}')
70+
print(f'Base: {base_sha[:8]} -> Head: {head_sha[:8]}')
71+
72+
# Run analysis on both commits
73+
os.system(f'u analyze --output base-analysis.json --format json --commit {base_sha}')
74+
os.system(f'u analyze --output head-analysis.json --format json --commit {head_sha}')
75+
76+
# Generate delta analysis
77+
os.system('u diff base-analysis.json head-analysis.json --output pr-delta.json --format json --policy-check --verbose')
78+
79+
# Generate comment content
80+
os.system('u diff base-analysis.json head-analysis.json --output pr-comment.md --format markdown --policy-check')
81+
82+
# Generate mini-map
83+
os.system('u diff base-analysis.json head-analysis.json --output pr-minimap.svg --format svg')
84+
85+
# Read results
86+
with open('pr-delta.json', 'r') as f:
87+
delta_data = json.load(f)
88+
89+
with open('pr-comment.md', 'r') as f:
90+
comment_content = f.read()
91+
92+
# Read mini-map
93+
with open('pr-minimap.svg', 'r') as f:
94+
minimap_svg = f.read()
95+
96+
# Create enhanced comment
97+
violations = delta_data.get('violations', [])
98+
policy_passed = len(violations) == 0
99+
100+
# Convert SVG to data URL
101+
import base64
102+
minimap_base64 = base64.b64encode(minimap_svg.encode()).decode()
103+
minimap_data_url = f'data:image/svg+xml;base64,{minimap_base64}'
104+
105+
enhanced_comment = f'''
106+
## 🔍 Understand-First PR Analysis
107+
108+
{comment_content}
109+
110+
### 📊 Mini-Map Visualization
111+
<img src=\"{minimap_data_url}\" alt=\"Code Map Delta\" width=\"100%\" />
112+
113+
### ✅ Policy Compliance Checklist
114+
{('✅ **All policies passed!** No violations detected.' if policy_passed else
115+
'\\n'.join([f'❌ **{v[\"rule\"]}**: {v[\"description\"]}' for v in violations]))}
116+
117+
### 📈 Key Metrics
118+
- **Functions Added**: {len(delta_data.get('functions_added', []))}
119+
- **Functions Removed**: {len(delta_data.get('functions_removed', []))}
120+
- **Functions Modified**: {len(delta_data.get('functions_modified', []))}
121+
- **Complexity Change**: {delta_data.get('complexity_change', 0):+d}
122+
- **Side Effects**: {len(delta_data.get('side_effects_added', []))} added, {len(delta_data.get('side_effects_removed', []))} removed
123+
124+
### 🎯 Action Items
125+
{('✅ Ready to merge!' if policy_passed else
126+
'\\n'.join([f'- [ ] Fix: {v[\"description\"]} in `{v[\"function_name\"]}`' for v in violations]))}
127+
128+
---
129+
*Generated by [Understand-First](https://github.com/your-org/understand-first) • [View full analysis]({pr_data[\"html_url\"]}/checks)*
130+
'''
131+
132+
# Post or update comment
133+
comments_url = f'https://api.github.com/repos/{repo}/issues/{pr_number}/comments'
134+
comments_response = requests.get(comments_url, headers=headers)
135+
comments = comments_response.json()
136+
137+
existing_comment = next((c for c in comments if 'Understand-First PR Analysis' in c['body']), None)
138+
139+
if existing_comment:
140+
# Update existing comment
141+
update_url = f'https://api.github.com/repos/{repo}/issues/comments/{existing_comment[\"id\"]}'
142+
requests.patch(update_url, headers=headers, json={'body': enhanced_comment})
143+
print('Updated existing comment')
144+
else:
145+
# Create new comment
146+
requests.post(comments_url, headers=headers, json={'body': enhanced_comment})
147+
print('Created new comment')
148+
149+
# Create Check Run
150+
check_run_data = {
151+
'name': 'Understand-First Analysis',
152+
'head_sha': head_sha,
153+
'status': 'completed',
154+
'conclusion': 'success' if policy_passed else 'failure',
155+
'output': {
156+
'title': '✅ Understand-First Policy Check Passed' if policy_passed else '❌ Understand-First Policy Check Failed',
157+
'summary': 'All code quality policies passed. The PR is safe to merge.' if policy_passed else f'{len(violations)} policy violations detected. Please review before merging.',
158+
'text': '\\n\\n'.join([f'**{v[\"rule\"]}**: {v[\"description\"]}\\n- Function: {v[\"function_name\"]}\\n- Severity: {v[\"severity\"]}\\n- File: {v[\"file_path\"]}:{v[\"line_number\"]}' for v in violations]) if violations else 'No violations found.'
159+
},
160+
'actions': [
161+
{
162+
'label': 'View Full Report',
163+
'description': 'Open detailed analysis report',
164+
'identifier': 'view-report'
165+
},
166+
{
167+
'label': 'Download Artifacts',
168+
'description': 'Download analysis artifacts',
169+
'identifier': 'download-artifacts'
170+
}
171+
]
172+
}
173+
174+
checks_url = f'https://api.github.com/repos/{repo}/check-runs'
175+
requests.post(checks_url, headers=headers, json=check_run_data)
176+
print('Created Check Run')
177+
178+
# Set commit status
179+
status_data = {
180+
'state': 'success' if policy_passed else 'failure',
181+
'description': 'Understand-First: All policies passed' if policy_passed else 'Understand-First: Policy violations detected',
182+
'context': 'understand-first/policy-check'
183+
}
184+
185+
status_url = f'https://api.github.com/repos/{repo}/statuses/{head_sha}'
186+
requests.post(status_url, headers=headers, json=status_data)
187+
print('Set commit status')
188+
189+
print(f'Analysis complete. Policy check: {\"PASSED\" if policy_passed else \"FAILED\"}')
190+
"
191+
192+
- name: Upload analysis artifacts
193+
uses: actions/upload-artifact@v3
194+
with:
195+
name: understand-first-pr-analysis-${{ github.event.number || github.event.inputs.pr_number }}
196+
path: |
197+
base-analysis.json
198+
head-analysis.json
199+
pr-delta.json
200+
pr-comment.md
201+
pr-minimap.svg

0 commit comments

Comments
 (0)