Skip to content

Commit

Permalink
Feature: Added Maxdepth Input Variable (#10)
Browse files Browse the repository at this point in the history
* Added 'maxdepth' to Action's Inputs

* Updated README to include latest Input
  • Loading branch information
nizarmah authored Jul 25, 2020
1 parent 39cc9ce commit 10c596e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Minifies JS and CSS files with Babel-Minify and CleanCSS
| -- | -- | -- | -- |
| directory | Directory that contains the files you want to minify. | false | . ( current directory ) |
| output | Directory that contains the minified files. | false | same as directory |
| maxdepth | Descend at most levels (a non-negative integer) levels of directories below the starting-points. | false | "" (empty) |

> With the addition of `maxdepth`, the action traverses by default into all subdirectories in a specified directory.
>
> ##### [Follow this example if you want to minify the files in the first level of a certain directory.](#specifying-maxdepth)
### Example

Expand All @@ -30,6 +35,27 @@ steps:
branch: ${{ github.ref }}
```

##### Specifying Maxdepth

```
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so auto-minify job can access it
- uses: actions/checkout@v2
- name: Auto Minify
uses: nizarmah/auto-minify@master
with:
maxdepth: 1
# 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/[email protected]
with:
commit_message: "Github Action: Auto Minified JS and CSS files"
branch: ${{ github.ref }}
```

##### Specifying output directory

```
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
description: "Directory that contains the minified files. Defaults to same directory"
required: false
default: ""
maxdepth:
description: "Descend at most levels (a non-negative integer) levels of directories below the starting-points."
required: false
default: ""

runs:
using: "docker"
Expand Down
17 changes: 15 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,26 @@ find_files () {
1- js | css (supported file extension)
find all files of certain type inside in_dir
- `-maxdepth` helps us specify only specified scope
- `find` returns the relative path, which is needed
- `*` acts as a recursive operator
Piped into grep to get all non minified files
optional parameters:
- `-maxdepth`
Clear all optional parameter keys in case the values are empty
So, when appended to the command parameters, no error is caused
'
find $in_dir -maxdepth 1 -type f -name "*.$1" | grep -v ".min.$1$"

MAXDEPTH_KEY="-maxdepth"
MAXDEPTH_VAL=$INPUT_MAXDEPTH

if [ -z $MAXDEPTH_VAL ]; then
MAXDEPTH_KEY=""
fi

find $in_dir ${MAXDEPTH_KEY} ${MAXDEPTH_VAL} -type f -name "*.$1" | grep -v ".min.$1$"
}

exec_minify_cmd () {
Expand Down

0 comments on commit 10c596e

Please sign in to comment.