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.4.0" - 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!"