-
Notifications
You must be signed in to change notification settings - Fork 50
406 lines (348 loc) · 11.9 KB
/
test-action.yml
File metadata and controls
406 lines (348 loc) · 11.9 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
name: Test node-minify Action
on:
push:
branches: [main, develop, feature/github-action-package]
paths:
- "packages/action/**"
- "action.yml"
- ".github/workflows/test-action.yml"
pull_request:
paths:
- "packages/action/**"
- "action.yml"
- ".github/workflows/test-action.yml"
workflow_dispatch:
jobs:
build-action:
name: Build Action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.10"
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build dependencies
run: |
bun run build:deps
bun run --filter '@node-minify/core' build
bun run --filter '@node-minify/benchmark' build
- name: Build action
run: bun run build
working-directory: packages/action
- name: Upload built action
uses: actions/upload-artifact@v4
with:
name: action-dist
path: packages/action/dist/
retention-days: 1
test-js-minification:
name: Test JS Minification
runs-on: ubuntu-latest
needs: build-action
steps:
- uses: actions/checkout@v4
- name: Download built action
uses: actions/download-artifact@v4
with:
name: action-dist
path: packages/action/dist/
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install compressor packages
# Compressors contain native dependencies (esbuild binaries, swc binaries, etc.)
# that cannot be bundled. Users must install the compressor package they need.
# See packages/action/README.md for documentation.
run: |
mkdir -p /tmp/compressors && cd /tmp/compressors
npm init -y
npm install @node-minify/terser @node-minify/esbuild
# Create node_modules and copy packages
mkdir -p $GITHUB_WORKSPACE/node_modules
cp -r /tmp/compressors/node_modules/* $GITHUB_WORKSPACE/node_modules/
- name: Create test file
run: |
mkdir -p test-action
cat > test-action/input.js << 'EOF'
function helloWorld() {
const message = "Hello, World!";
console.log(message);
return message;
}
function unusedFunction() {
return "This function is not used";
}
helloWorld();
EOF
- name: Minify with terser
id: minify-terser
uses: ./
with:
input: "test-action/input.js"
output: "test-action/output.min.js"
compressor: "terser"
auto: 'false'
patterns: ''
output-dir: 'dist'
ignore: ''
dry-run: 'false'
- name: Verify terser outputs
env:
ORIGINAL_SIZE: ${{ steps.minify-terser.outputs.original-size }}
MINIFIED_SIZE: ${{ steps.minify-terser.outputs.minified-size }}
REDUCTION_PERCENT: ${{ steps.minify-terser.outputs.reduction-percent }}
GZIP_SIZE: ${{ steps.minify-terser.outputs.gzip-size }}
TIME_MS: ${{ steps.minify-terser.outputs.time-ms }}
run: |
echo "Original size: $ORIGINAL_SIZE bytes"
echo "Minified size: $MINIFIED_SIZE bytes"
echo "Reduction: $REDUCTION_PERCENT%"
echo "Gzip size: $GZIP_SIZE bytes"
echo "Time: ${TIME_MS}ms"
if [ ! -f "test-action/output.min.js" ]; then
echo "::error::Output file was not created"
exit 1
fi
if [ "$(echo "$REDUCTION_PERCENT > 0" | bc -l)" -ne 1 ]; then
echo "::error::Reduction percentage should be > 0"
exit 1
fi
echo "Output file content:"
cat test-action/output.min.js
- name: Minify with esbuild
id: minify-esbuild
uses: ./
with:
input: "test-action/input.js"
output: "test-action/output.esbuild.js"
compressor: "esbuild"
type: "js"
auto: 'false'
patterns: ''
output-dir: 'dist'
ignore: ''
dry-run: 'false'
- name: Compare results
env:
TERSER_SIZE: ${{ steps.minify-terser.outputs.minified-size }}
TERSER_REDUCTION: ${{ steps.minify-terser.outputs.reduction-percent }}
ESBUILD_SIZE: ${{ steps.minify-esbuild.outputs.minified-size }}
ESBUILD_REDUCTION: ${{ steps.minify-esbuild.outputs.reduction-percent }}
run: |
echo "## Comparison" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Compressor | Minified Size | Reduction |" >> $GITHUB_STEP_SUMMARY
echo "|------------|---------------|-----------|" >> $GITHUB_STEP_SUMMARY
echo "| terser | ${TERSER_SIZE} bytes | ${TERSER_REDUCTION}% |" >> $GITHUB_STEP_SUMMARY
echo "| esbuild | ${ESBUILD_SIZE} bytes | ${ESBUILD_REDUCTION}% |" >> $GITHUB_STEP_SUMMARY
test-css-minification:
name: Test CSS Minification
runs-on: ubuntu-latest
needs: build-action
steps:
- uses: actions/checkout@v4
- name: Download built action
uses: actions/download-artifact@v4
with:
name: action-dist
path: packages/action/dist/
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install compressor packages
# Compressors contain native dependencies that cannot be bundled.
# See packages/action/README.md for documentation.
run: |
mkdir -p /tmp/compressors && cd /tmp/compressors
npm init -y
npm install @node-minify/lightningcss
# Create node_modules and copy packages
mkdir -p $GITHUB_WORKSPACE/node_modules
cp -r /tmp/compressors/node_modules/* $GITHUB_WORKSPACE/node_modules/
- name: Create test CSS file
run: |
mkdir -p test-action
cat > test-action/input.css << 'EOF'
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
margin: 10px;
}
.button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
.button:hover {
background-color: #0056b3;
}
EOF
- name: Minify CSS with lightningcss
id: minify-css
uses: ./
with:
input: "test-action/input.css"
output: "test-action/output.min.css"
compressor: "lightningcss"
type: "css"
auto: 'false'
patterns: ''
output-dir: 'dist'
ignore: ''
dry-run: 'false'
- name: Verify CSS output
run: |
echo "Original: ${{ steps.minify-css.outputs.original-size }} bytes"
echo "Minified: ${{ steps.minify-css.outputs.minified-size }} bytes"
echo "Reduction: ${{ steps.minify-css.outputs.reduction-percent }}%"
if [ "$(echo '${{ steps.minify-css.outputs.reduction-percent }} > 0' | bc -l)" -ne 1 ]; then
echo "::error::CSS reduction percentage should be > 0"
exit 1
fi
cat test-action/output.min.css
test-zero-config:
name: Test Zero Config (Auto Mode)
runs-on: ubuntu-latest
needs: build-action
steps:
- uses: actions/checkout@v4
- name: Download built action
uses: actions/download-artifact@v4
with:
name: action-dist
path: packages/action/dist/
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install compressors
run: |
mkdir -p /tmp/compressors && cd /tmp/compressors
npm init -y
npm install @node-minify/terser @node-minify/lightningcss
mkdir -p $GITHUB_WORKSPACE/node_modules
cp -r /tmp/compressors/node_modules/* $GITHUB_WORKSPACE/node_modules/
- name: Create test files
run: |
mkdir -p src
cat > src/app.js << 'EOF'
function hello() { console.log("hello world"); }
EOF
cat > src/utils.js << 'EOF'
export const add = (a, b) => a + b;
EOF
cat > src/styles.css << 'EOF'
body { margin: 0; padding: 0; }
EOF
- name: Run auto mode
uses: ./
with:
auto: "true"
output-dir: "dist"
- name: Verify outputs
run: |
test -f dist/src/app.js || (echo "dist/src/app.js not found" && exit 1)
test -f dist/src/utils.js || (echo "dist/src/utils.js not found" && exit 1)
test -f dist/src/styles.css || (echo "dist/src/styles.css not found" && exit 1)
echo "All output files created successfully"
test-zero-config-dry-run:
name: Test Zero Config Dry Run
runs-on: ubuntu-latest
needs: build-action
steps:
- uses: actions/checkout@v4
- name: Download built action
uses: actions/download-artifact@v4
with:
name: action-dist
path: packages/action/dist/
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install compressor
run: |
mkdir -p /tmp/compressors && cd /tmp/compressors
npm init -y
npm install @node-minify/terser
mkdir -p $GITHUB_WORKSPACE/node_modules
cp -r /tmp/compressors/node_modules/* $GITHUB_WORKSPACE/node_modules/
- name: Create test file
run: |
mkdir -p src
cat > src/app.js << 'EOF'
function test() { return 42; }
EOF
- name: Run dry-run mode
uses: ./
with:
auto: "true"
dry-run: "true"
output-dir: "dist"
- name: Verify no output created
run: |
test ! -d dist || (echo "dist/ should not exist in dry-run" && exit 1)
echo "Dry-run passed - no output created"
test-zero-config-custom-patterns:
name: Test Zero Config Custom Patterns
runs-on: ubuntu-latest
needs: build-action
steps:
- uses: actions/checkout@v4
- name: Download built action
uses: actions/download-artifact@v4
with:
name: action-dist
path: packages/action/dist/
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install compressor
run: |
mkdir -p /tmp/compressors && cd /tmp/compressors
npm init -y
npm install @node-minify/terser
mkdir -p $GITHUB_WORKSPACE/node_modules
cp -r /tmp/compressors/node_modules/* $GITHUB_WORKSPACE/node_modules/
- name: Create files in custom directory
run: |
mkdir -p custom/path
cat > custom/path/main.js << 'EOF'
console.log("custom location");
EOF
- name: Run with custom patterns
uses: ./
with:
auto: "true"
patterns: "custom/**/*.js"
output-dir: "dist"
- name: Verify custom output
run: |
test -f dist/custom/path/main.js || (echo "dist/custom/path/main.js not found" && exit 1)
echo "Custom patterns worked correctly"
test-summary:
name: Summary
runs-on: ubuntu-latest
needs:
[
test-js-minification,
test-css-minification,
test-zero-config,
test-zero-config-dry-run,
test-zero-config-custom-patterns,
]
steps:
- name: All tests passed
run: echo "All node-minify action tests passed!"