-
Notifications
You must be signed in to change notification settings - Fork 125
211 lines (176 loc) · 6.3 KB
/
frontend-ci.yml
File metadata and controls
211 lines (176 loc) · 6.3 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
name: Frontend CI
# Trigger: PR to main/develop branches, only when frontend files change
on:
pull_request:
branches:
- main
- develop
paths:
- 'himarket-web/himarket-frontend/**'
- 'himarket-web/himarket-admin/**'
- '.github/workflows/frontend-ci.yml'
# Avoid duplicate runs: new commits to the same PR will cancel previous runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Limit workflow permissions (security best practice)
permissions:
contents: read
pull-requests: write
checks: write
jobs:
# Detect which parts of the codebase changed
changes:
name: Detect Changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
frontend: ${{ steps.filter.outputs.frontend }}
admin: ${{ steps.filter.outputs.admin }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for file changes
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
frontend:
- 'himarket-web/himarket-frontend/**'
admin:
- 'himarket-web/himarket-admin/**'
# Frontend Build Check
himarket-frontend-build:
name: Frontend - Build Check
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.frontend == 'true'
defaults:
run:
working-directory: himarket-web/himarket-frontend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# cache: 'npm' # Disabled: no package-lock.json in repo
# cache-dependency-path: himarket-web/himarket-frontend/package-lock.json
- name: Install dependencies
run: npm install --legacy-peer-deps # Using legacy-peer-deps to handle React 19 compatibility
- name: Build project
run: npm run build
env:
NODE_ENV: production
- name: Verify build artifacts
run: |
if [ ! -d "dist" ]; then
echo "❌ Build failed: dist directory does not exist"
exit 1
fi
if [ ! -f "dist/index.html" ]; then
echo "❌ Build failed: dist/index.html does not exist"
exit 1
fi
echo "✅ Build artifacts verified"
- name: Upload build artifacts
if: success()
uses: actions/upload-artifact@v4
with:
name: himarket-frontend-build
path: himarket-web/himarket-frontend/dist/
retention-days: 7
# Admin Build Check
himarket-admin-build:
name: Admin - Build Check
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.admin == 'true'
defaults:
run:
working-directory: himarket-web/himarket-admin
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# cache: 'npm' # Disabled: no package-lock.json in repo
# cache-dependency-path: himarket-web/himarket-admin/package-lock.json
- name: Install dependencies
run: npm install --legacy-peer-deps # Using legacy-peer-deps to handle React 19 compatibility
- name: Build project
run: npm run build
env:
NODE_ENV: production
- name: Verify build artifacts
run: |
if [ ! -d "dist" ]; then
echo "❌ Build failed: dist directory does not exist"
exit 1
fi
if [ ! -f "dist/index.html" ]; then
echo "❌ Build failed: dist/index.html does not exist"
exit 1
fi
echo "✅ Build artifacts verified"
- name: Upload build artifacts
if: success()
uses: actions/upload-artifact@v4
with:
name: himarket-admin-build
path: himarket-web/himarket-admin/dist/
retention-days: 7
# Summary of all check results
frontend-ci-summary:
name: Frontend CI Summary
runs-on: ubuntu-latest
needs: [changes, himarket-frontend-build, himarket-admin-build]
if: always()
steps:
- name: Check all task status
uses: actions/github-script@v7
with:
script: |
const jobs = [
{ name: 'Frontend - Build Check', status: '${{ needs.himarket-frontend-build.result }}' },
{ name: 'Admin - Build Check', status: '${{ needs.himarket-admin-build.result }}' }
];
let summary = '## 🏗️ Frontend CI Check Summary\n\n';
let allPassed = true;
let hasSkipped = false;
jobs.forEach(job => {
if (job.status === 'success') {
summary += `✅ **${job.name}**: Passed\n`;
} else if (job.status === 'skipped') {
summary += `⏭️ **${job.name}**: Skipped (no related changes)\n`;
hasSkipped = true;
} else if (job.status === 'failure') {
summary += `❌ **${job.name}**: Failed\n`;
allPassed = false;
} else {
summary += `⚠️ **${job.name}**: ${job.status}\n`;
allPassed = false;
}
});
summary += '\n---\n\n';
if (allPassed) {
summary += '🎉 **All required checks passed!** Your PR builds successfully.\n\n';
summary += '💡 **Note:** Code quality checks (ESLint, TypeScript) run in a separate workflow.\n';
} else {
summary += '⚠️ **Some required checks failed**. Please fix the build errors.\n';
if (hasSkipped) {
summary += '\n📝 _Note: Some checks were skipped because no related files were changed._\n';
}
}
await core.summary
.addRaw(summary)
.write();
console.log(summary);
// Fail the workflow if any check failed, regardless of skipped jobs
if (!allPassed) {
core.setFailed('Some frontend CI checks failed');
}