-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (126 loc) · 5.04 KB
/
code-quality.yml
File metadata and controls
152 lines (126 loc) · 5.04 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
# =============================================================================
# Code Quality & Linting Auto-Fix
# =============================================================================
# Automatically fixes linting issues and creates PRs
# Schedule: Every Friday at 2 PM UTC
# =============================================================================
name: "Code Quality Auto-Fix"
on:
schedule:
- cron: "0 14 * * 5" # Every Friday at 2 PM UTC
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
lint-and-fix:
name: "Lint & Auto-Fix"
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: "Install Dependencies"
run: npm ci
- name: "Run ESLint with Auto-Fix"
id: eslint
continue-on-error: true
run: |
echo "Running ESLint with auto-fix..."
npx eslint . --fix --ext .js,.jsx,.ts,.tsx || true
# Check if any files were modified
if git diff --quiet; then
echo "files_changed=false" >> $GITHUB_OUTPUT
else
echo "files_changed=true" >> $GITHUB_OUTPUT
CHANGED_FILES=$(git diff --name-only | wc -l)
echo "changed_count=$CHANGED_FILES" >> $GITHUB_OUTPUT
fi
- name: "Run Prettier"
if: steps.eslint.outputs.files_changed == 'true' || github.event_name == 'workflow_dispatch'
continue-on-error: true
run: |
if command -v prettier &> /dev/null || npx prettier --version &> /dev/null; then
echo "Running Prettier..."
npx prettier --write "src/**/*.{js,jsx,ts,tsx,css,json}" || true
else
echo "Prettier not configured, skipping..."
fi
- name: "Create Pull Request"
if: steps.eslint.outputs.files_changed == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "style: auto-fix linting issues [bot]"
title: "Code Quality: Auto-Fix Linting Issues"
body: |
## Automated Code Quality Fixes
This PR contains automatically applied linting fixes.
### Summary
- Files modified: ${{ steps.eslint.outputs.changed_count || 'Multiple' }}
- Tool: ESLint with auto-fix
### What was fixed
- Code style inconsistencies
- Auto-fixable ESLint warnings
- Formatting issues (if Prettier is configured)
---
Generated by [Code Quality Workflow](../actions/runs/${{ github.run_id }})
branch: "style/lint-fixes-${{ github.run_number }}"
delete-branch: true
labels: |
code-quality
automated
style
type-check:
name: "TypeScript Check"
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: "Install Dependencies"
run: npm ci
- name: "Run TypeScript Check"
id: typecheck
continue-on-error: true
run: |
echo "Running TypeScript type check..."
npx tsc --noEmit 2>&1 | tee typescript-errors.log || true
ERROR_COUNT=$(grep -c "error TS" typescript-errors.log || echo "0")
echo "error_count=$ERROR_COUNT" >> $GITHUB_OUTPUT
echo "TypeScript errors found: $ERROR_COUNT"
- name: "Create Issue for Type Errors"
if: steps.typecheck.outputs.error_count > 5
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const errors = fs.readFileSync('typescript-errors.log', 'utf8');
const errorCount = '${{ steps.typecheck.outputs.error_count }}';
// Check if similar issue exists
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'typescript,automated'
});
if (issues.data.length === 0) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `TypeScript: ${errorCount} Type Errors Detected`,
body: `## TypeScript Errors\n\nThe automated type check found **${errorCount}** errors.\n\n### Sample Errors\n\`\`\`\n${errors.slice(0, 2000)}\n\`\`\`\n\n---\n> Auto-generated by Code Quality workflow`,
labels: ['typescript', 'automated', 'bug']
});
}