Skip to content

Commit

Permalink
Merge pull request #4 from nizarmah/fail_onerror
Browse files Browse the repository at this point in the history
Feature: Action Fail on Minifying File Error
  • Loading branch information
nizarmah authored Apr 21, 2020
2 parents 2a41de2 + 4a6b5fd commit 1fd7b78
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ steps:
- uses: actions/checkout@v2
- name: Auto Minify
uses: nizarmah/auto-minify@v1.3
uses: nizarmah/auto-minify
# Auto commits minified files to the repository
# Ignore it if you don't want to commit the files to the repository
Expand All @@ -38,14 +38,14 @@ steps:
- uses: actions/checkout@v2
- name: Auto Minify
uses: nizarmah/auto-minify@v1.3
uses: nizarmah/auto-minify
with:
directory: 'js'
# Auto commits minified files to the repository
# Ignore it if you don't want to commit the files to the repository
- name: Auto committing minified files
uses: stefanzweifel/git-auto-commit-action@v3.0.0
uses: stefanzweifel/git-auto-commit-action
with:
repository: 'js'
commit_message: "Github Action: Auto Minified JS and CSS files"
Expand All @@ -62,15 +62,15 @@ steps:
- uses: actions/checkout@v2
- name: Auto Minify
uses: nizarmah/auto-minify@v1.3
uses: nizarmah/auto-minify
with:
directory: 'js'
output: 'mini_js'
# Auto commits minified files to the repository
# Ignore it if you don't want to commit the files to the repository
- name: Auto committing minified files
uses: stefanzweifel/git-auto-commit-action@v3.0.0
uses: stefanzweifel/git-auto-commit-action
with:
repository: 'mini_js'
commit_message: "Github Action: Auto Minified JS and CSS files"
Expand Down
56 changes: 46 additions & 10 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,44 @@ find_files () {
find $in_dir -maxdepth 1 -type f -name "*.$1" | grep -v ".min.$1$"
}

exec_minify_cmd () {
: '
arguments:
1- input file
2- output file
returns the command needed to minify the file
depending on what type the file is (its extension)
'
file=$1
out=$2

if [[ $file == *.js ]]; then
npx uglifyjs $file --compress --mangle --output $out
elif [[ $file == *.css ]]; then
npx cleancss -o $out $file
fi
}

minify_file () {
: '
arguments:
1- input file
checks the file type (whether css or js)
then creates the output file of that file
then minifies the file with a specific command
then checks if the command returned an error
if it did, program exits with that error code
'
file=$( readlink -m $1 )
out=$( output_name $file )

echo "Minify : $file -> $out"

exec_minify_cmd $file $out
}

cd /app/

dir="/github/workspace"
Expand All @@ -62,22 +100,20 @@ if [ ! -z $INPUT_OUTPUT ]; then
out_dir="$dir/$INPUT_OUTPUT"
fi

# create output directories if they don't exist
mkdir -p $out_dir
if [ -n "$out_dir" ]; then
# create output directories if they don't exist
mkdir -p $out_dir
fi

js_files=$( find_files 'js' )
css_files=$( find_files 'css' )

for file in $js_files; do
out=$( output_name $file )
set -e

echo "Minify : JS : $file -> $out"
npx uglifyjs $file --compress --mangle --output $out
for file in $js_files; do
minify_file $file
done

for file in $css_files; do
out=$( output_name $file )

echo "Minify : CSS : $file -> $out"
npx cleancss -o $out $file
minify_file $file
done

0 comments on commit 1fd7b78

Please sign in to comment.