-
Notifications
You must be signed in to change notification settings - Fork 4
222 lines (185 loc) · 7.04 KB
/
Copy pathpr-check.yml
File metadata and controls
222 lines (185 loc) · 7.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
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
name: PR Build Test
on:
pull_request:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
build-test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'yarn'
- name: Set Yarn version
run: corepack prepare yarn@4.10.3 --activate
- name: Generate cache key
id: cache-key
run: echo "value=${{ hashFiles('**/yarn.lock', '**/vite.config.ts', '**/tsconfig.json') }}" >> $GITHUB_OUTPUT
- name: Cache node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-yarn-${{ steps.cache-key.outputs.value }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Type check
id: type-check
run: yarn tsc --noEmit
- name: Lint check
id: lint
run: |
yarn lint --max-warnings 0 --format json > lint-results.json || {
echo "LINT_FAILED=true" >> $GITHUB_OUTPUT
exit 1
}
- name: Format check
id: format
run: yarn format:check
- name: Run tests
id: test
run: yarn test --run
- name: Build app
id: build
run: yarn build
- name: Build size check
run: |
BUILD_SIZE_KB=$(du -sk build/client | cut -f1)
BUILD_SIZE_MB=$((BUILD_SIZE_KB / 1024))
echo "Build size: ${BUILD_SIZE_MB}MB"
if [ $BUILD_SIZE_MB -gt 10 ]; then
echo "Build size is larger than 10MB: ${BUILD_SIZE_MB}MB"
echo "Consider code splitting or removing unused dependencies"
elif [ $BUILD_SIZE_MB -gt 5 ]; then
echo "Build size is moderate: ${BUILD_SIZE_MB}MB"
else
echo "Build size is optimal: ${BUILD_SIZE_MB}MB"
fi
- name: Upload build artifacts
id: artifact
uses: actions/upload-artifact@v4
with:
name: build-test-files
path: build/client/
retention-days: 1
- name: Comment build results on PR
if: always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let comment = '## PR 검증 결과\n\n';
// TypeScript 체크 결과
const typeCheckStatus = '${{ steps.type-check.outcome }}';
if (typeCheckStatus === 'success') {
comment += '✅ **TypeScript**: 통과\n';
} else {
comment += '❌ **TypeScript**: 실패\n';
}
// Lint 체크 결과
const lintStatus = '${{ steps.lint.outcome }}';
const lintFailed = '${{ steps.lint.outputs.LINT_FAILED }}';
if (lintFailed === 'true') {
comment += '⚠️ **ESLint**: 문제 발견\n';
} else if (lintStatus === 'success') {
comment += '✅ **ESLint**: 통과\n';
} else {
comment += '❌ **ESLint**: 실패\n';
}
// Prettier 체크 결과
const formatStatus = '${{ steps.format.outcome }}';
if (formatStatus === 'success') {
comment += '✅ **Prettier**: 통과\n';
} else {
comment += '❌ **Prettier**: 포맷 필요\n';
}
// 테스트 결과
const testStatus = '${{ steps.test.outcome }}';
if (testStatus === 'success') {
comment += '✅ **Test**: 통과\n';
} else {
comment += '❌ **Test**: 실패\n';
}
// 빌드 결과
const buildStatus = '${{ steps.build.outcome }}';
if (buildStatus === 'success') {
comment += '✅ **Build**: 성공\n';
// 빌드 크기 정보
try {
const stats = fs.statSync('build/client');
if (stats.isDirectory()) {
const { execSync } = require('child_process');
const sizeKB = execSync('du -sk build/client | cut -f1', { encoding: 'utf8' }).trim();
const sizeMB = Math.round(parseInt(sizeKB) / 1024);
if (sizeMB > 10) {
comment += `⚠️ **Build Size**: ${sizeMB}MB (10MB 초과)\n`;
} else if (sizeMB > 5) {
comment += `**Build Size**: ${sizeMB}MB\n`;
} else {
comment += `**Build Size**: ${sizeMB}MB\n`;
}
}
} catch (error) {
comment += '**Build Size**: 측정 불가\n';
}
} else {
comment += '❌ **Build**: 실패\n';
}
// ESLint 상세 결과
if (lintFailed === 'true') {
let lintResults = [];
try {
const data = fs.readFileSync('lint-results.json', 'utf8');
lintResults = JSON.parse(data);
} catch (error) {
console.log('No lint results file found');
}
let errorCount = 0;
let warningCount = 0;
for (const result of lintResults) {
if (result.messages && result.messages.length > 0) {
for (const message of result.messages) {
if (message.severity === 2) errorCount++;
else warningCount++;
}
}
}
if (errorCount > 0 || warningCount > 0) {
comment += `\n### ESLint 상세\n`;
comment += `- Errors: ${errorCount}\n`;
comment += `- Warnings: ${warningCount}\n\n`;
for (const result of lintResults) {
if (result.messages && result.messages.length > 0) {
comment += `**${result.filePath.replace(process.cwd() + '/', '')}**\n`;
for (const message of result.messages.slice(0, 5)) {
const severity = message.severity === 2 ? 'Error' : 'Warning';
comment += `- ${severity} (Line ${message.line}): ${message.message} \`${message.ruleId || 'unknown'}\`\n`;
}
if (result.messages.length > 5) {
comment += `... and ${result.messages.length - 5} more issues\n`;
}
comment += '\n';
}
}
}
}
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});