|
| 1 | +name: "node-minify" |
| 2 | +description: "Minify JavaScript, CSS, and HTML files with detailed reporting" |
| 3 | +author: "srod" |
| 4 | +branding: |
| 5 | + icon: "minimize-2" |
| 6 | + color: "green" |
| 7 | + |
| 8 | +inputs: |
| 9 | + input: |
| 10 | + description: "Files to minify (glob pattern or path)" |
| 11 | + required: true |
| 12 | + compressor: |
| 13 | + description: | |
| 14 | + Compressor to use. |
| 15 | + Recommended: terser, esbuild, swc (fast, no Java). |
| 16 | + Note: 'gcc' and 'yui' require Java (pre-installed on GitHub runners). |
| 17 | + required: false |
| 18 | + default: "terser" |
| 19 | + output: |
| 20 | + description: "Output file path" |
| 21 | + required: true |
| 22 | + type: |
| 23 | + description: "File type: js or css (required for esbuild, lightningcss, yui)" |
| 24 | + required: false |
| 25 | + options: |
| 26 | + description: "Compressor-specific options (JSON string)" |
| 27 | + required: false |
| 28 | + default: "{}" |
| 29 | + report-summary: |
| 30 | + description: "Add results to job summary" |
| 31 | + required: false |
| 32 | + default: "true" |
| 33 | + include-gzip: |
| 34 | + description: "Include gzip sizes in report" |
| 35 | + required: false |
| 36 | + default: "true" |
| 37 | + java-version: |
| 38 | + description: "Java version for gcc/yui compressors (optional)" |
| 39 | + required: false |
| 40 | + |
| 41 | +outputs: |
| 42 | + original-size: |
| 43 | + description: "Original file size in bytes" |
| 44 | + value: ${{ steps.minify.outputs.original-size }} |
| 45 | + original-size-formatted: |
| 46 | + description: "Original file size formatted (e.g., 45.2 kB)" |
| 47 | + value: ${{ steps.minify.outputs.original-size-formatted }} |
| 48 | + minified-size: |
| 49 | + description: "Minified file size in bytes" |
| 50 | + value: ${{ steps.minify.outputs.minified-size }} |
| 51 | + minified-size-formatted: |
| 52 | + description: "Minified file size formatted (e.g., 12.3 kB)" |
| 53 | + value: ${{ steps.minify.outputs.minified-size-formatted }} |
| 54 | + reduction-percent: |
| 55 | + description: "Size reduction percentage" |
| 56 | + value: ${{ steps.minify.outputs.reduction-percent }} |
| 57 | + gzip-size: |
| 58 | + description: "Gzipped size in bytes" |
| 59 | + value: ${{ steps.minify.outputs.gzip-size }} |
| 60 | + gzip-size-formatted: |
| 61 | + description: "Gzipped size formatted" |
| 62 | + value: ${{ steps.minify.outputs.gzip-size-formatted }} |
| 63 | + time-ms: |
| 64 | + description: "Compression time in milliseconds" |
| 65 | + value: ${{ steps.minify.outputs.time-ms }} |
| 66 | + |
| 67 | +runs: |
| 68 | + using: "composite" |
| 69 | + steps: |
| 70 | + # Setup Java for gcc/yui compressors (auto-setup with default if java-version not specified) |
| 71 | + - name: Setup Java (for gcc/yui) |
| 72 | + if: contains(fromJSON('["gcc", "google-closure-compiler", "yui"]'), inputs.compressor) |
| 73 | + uses: actions/setup-java@v4 |
| 74 | + with: |
| 75 | + distribution: "temurin" |
| 76 | + java-version: ${{ inputs.java-version || '17' }} |
| 77 | + |
| 78 | + # Warn about deprecated yui compressor |
| 79 | + - name: Deprecation warning (yui) |
| 80 | + if: inputs.compressor == 'yui' |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + echo "::warning::YUI Compressor was deprecated by Yahoo in 2013. Consider using 'terser' for JS or 'lightningcss' for CSS." |
| 84 | +
|
| 85 | + - name: Setup Bun |
| 86 | + uses: oven-sh/setup-bun@v2 |
| 87 | + with: |
| 88 | + bun-version: "1.3.5" |
| 89 | + |
| 90 | + - name: Install dependencies |
| 91 | + shell: bash |
| 92 | + env: |
| 93 | + ACTION_PATH: ${{ github.action_path }} |
| 94 | + COMPRESSOR: ${{ inputs.compressor }} |
| 95 | + run: | |
| 96 | + TEMP_DIR="${RUNNER_TEMP}/node-minify-action" |
| 97 | + mkdir -p "$TEMP_DIR" |
| 98 | + cd "$TEMP_DIR" |
| 99 | + bun init -y |
| 100 | + bun add @node-minify/core @node-minify/utils "@node-minify/${COMPRESSOR}" |
| 101 | + cp "$ACTION_PATH/minify.ts" "$TEMP_DIR/" |
| 102 | + echo "NODE_MINIFY_ACTION_DIR=$TEMP_DIR" >> $GITHUB_ENV |
| 103 | +
|
| 104 | + - name: Run minification |
| 105 | + id: minify |
| 106 | + shell: bash |
| 107 | + env: |
| 108 | + INPUT_FILE: ${{ inputs.input }} |
| 109 | + OUTPUT_FILE: ${{ inputs.output }} |
| 110 | + COMPRESSOR: ${{ inputs.compressor }} |
| 111 | + FILE_TYPE: ${{ inputs.type }} |
| 112 | + OPTIONS: ${{ inputs.options }} |
| 113 | + INCLUDE_GZIP: ${{ inputs.include-gzip }} |
| 114 | + WORKSPACE_DIR: ${{ github.workspace }} |
| 115 | + run: | |
| 116 | + cd "$NODE_MINIFY_ACTION_DIR" |
| 117 | + bun run minify.ts |
| 118 | +
|
| 119 | + - name: Generate job summary |
| 120 | + if: inputs.report-summary == 'true' |
| 121 | + shell: bash |
| 122 | + run: | |
| 123 | + cat >> $GITHUB_STEP_SUMMARY << EOF |
| 124 | + ## 📦 node-minify Results |
| 125 | +
|
| 126 | + | Metric | Value | |
| 127 | + |--------|-------| |
| 128 | + | **Input** | \`${{ inputs.input }}\` | |
| 129 | + | **Output** | \`${{ inputs.output }}\` | |
| 130 | + | **Compressor** | ${{ inputs.compressor }} | |
| 131 | + | **Original Size** | ${{ steps.minify.outputs.original-size-formatted }} | |
| 132 | + | **Minified Size** | ${{ steps.minify.outputs.minified-size-formatted }} | |
| 133 | + | **Reduction** | ${{ steps.minify.outputs.reduction-percent }}% | |
| 134 | + | **Gzip Size** | ${{ steps.minify.outputs.gzip-size-formatted }} | |
| 135 | + | **Time** | ${{ steps.minify.outputs.time-ms }}ms | |
| 136 | +
|
| 137 | + EOF |
0 commit comments