forked from kmanimaran/list-folder-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
47 lines (44 loc) · 1.46 KB
/
action.yml
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
name: 'List folders of path'
description: 'Get a json list of the folder listed in the specified folder'
inputs:
path:
description: 'Folder to list'
required: true
dir_name:
type: boolean
description: 'Whether to include the given path in the folders name or not'
default: 'false'
escape:
type: boolean
description: 'Whether the output JSON should be escaped or not'
default: 'false'
suffix:
description: 'Suffix to add at each folders'
outputs:
folders: # id of output
description: 'A JSON formatted list of folders'
value: ${{ steps.set-folders.outputs.folders }}
runs:
using: 'composite'
steps:
- shell: bash
run: |
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
*) machine="UNKNOWN:${unameOut}"
esac
echo ${machine}
if [ "$machine" == "Mac" ]; then
brew install tree jq
elif [ "$machine" == "Linux" ]; then
sudo apt-get update && sudo apt-get install tree jq -y
fi
- id: set-folders
shell: bash
run: |
cd ${{ inputs.path }}
folders=$(tree -J -d -L 1 | jq -c '.[0].contents | map("${{ inputs.dir_name && inputs.path || '' }}" + .name + "${{ inputs.suffix != '' && inputs.suffix || '' }}")' ${{ inputs.escape && ' | jq -R' || '' }})
echo $folders
echo "folders=$folders" >> $GITHUB_OUTPUT