forked from robaone/initialize-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_file_list_for_projects.sh
More file actions
executable file
·101 lines (85 loc) · 2.32 KB
/
parse_file_list_for_projects.sh
File metadata and controls
executable file
·101 lines (85 loc) · 2.32 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# This script takes a list of files and returns the project names for those files
# Example:
# echo "GithubWebhook/README.md" | parse_file_list_for_projects.sh
# GithubWebhook
INPUT="$(cat)"
if [ "$INPUT" == "" ]; then
echo "You must provide a list of files"
exit 1
fi
SCRIPT_DIR=$(cd $(dirname $0); pwd)
if [ "$BUILD_DEPENDS_PATH" == "" ]; then
BUILD_DEPENDS_PATH="$SCRIPT_DIR/build_depends_project_list.sh"
fi
if [ ! -d "$PROJECT_ROOT" ]; then
exit 0
fi
# for each line get the first folder name
if [ "$PROJECT_ROOT" == "." ]; then
FOLDERS="$(echo "$INPUT" | sed 's/\// /g' | awk '{print $1}' | sort | uniq)"
else
FOLDERS="$(echo "$INPUT" | grep ''$PROJECT_ROOT'[/]' | sed 's/\// /g' | awk '{print $1 "/" $2}' | sort | uniq)"
fi
# get list of folders triggered by dependencies
if [ "$PROJECT_ROOT" == "." ]; then
DEPENDS_FOLDERS="$(echo "$INPUT" | $BUILD_DEPENDS_PATH | awk '{print $1}')"
else
DEPENDS_FOLDERS="$(echo "$INPUT" | $BUILD_DEPENDS_PATH | awk '{print "$PROJECT_ROOT/" $1}')"
fi
# combine with FOLDERS and remove duplicates
FOLDERS="$(echo "$FOLDERS $DEPENDS_FOLDERS" | tr ' ' '\n' | sort -u)"
# get list of folders that don't exist
# for each folder in FOLDERS
# if folder doesn't exist
# add to list
function folder_exists() {
local FOLDER=$1
if [ "$FOLDER_EXISTS_CMD" != "" ]; then
$FOLDER_EXISTS_CMD "$FOLDER"
return $?
else
if [ -d "$FOLDER" ]; then
echo 1
else
echo 0
fi
fi
}
if [ "$FOLDERS_THAT_DONT_EXIST" == "" ]; then
for FOLDER in $FOLDERS
do
if [ "$(folder_exists "$FOLDER")" == "0" ]; then
FOLDERS_THAT_DONT_EXIST="$FOLDERS_THAT_DONT_EXIST $FOLDER"
fi
done
fi
if [ "$PROJECT_ROOT" == "." ]; then
IGNORE_LIST="$IGNORE_LIST .github"
fi
IGNORE_LIST="$IGNORE_LIST $FOLDERS_THAT_DONT_EXIST"
function folder_is_in_list() {
local FOLDER=$1
local LIST="$2"
for IGNORE in $LIST
do
if [ "$FOLDER" == "$IGNORE" ]; then
echo 0
fi
done
echo 1
}
NEW_FOLDERS=""
for FOLDER in $FOLDERS
do
if [ "$(folder_is_in_list "$FOLDER" "$IGNORE_LIST")" == "1" ]; then
NEW_FOLDERS="$NEW_FOLDERS $FOLDER"
fi
done
# replace space with return character
if [ "$PROJECT_ROOT" == "." ]; then
FOLDERS=$(echo $NEW_FOLDERS | sed 's/ /\n/g')
else
FOLDERS=$(echo $NEW_FOLDERS | sed 's/ /\n/g' | sed 's/^'$PROJECT_ROOT'\///g')
fi
echo "$FOLDERS"