Skip to content

Commit ffdec77

Browse files
feat: fix project path (#8)
* feat: 🎸 download a release * feat: 🎸 support root project path * feat: 🎸 update script version
1 parent 247ef3c commit ffdec77

3 files changed

Lines changed: 78 additions & 14 deletions

File tree

‎action.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ outputs:
2222

2323
runs:
2424
using: "composite"
25+
env:
26+
SCRIPT_VERSION: "0.4.0"
2527
steps:
2628
- name: Cancel Previous Runs
2729
if: ${{ github.ref != 'refs/heads/develop' && github.ref != 'refs/heads/main' }}
@@ -63,4 +65,4 @@ runs:
6365
echo "$matrixStringifiedObject"
6466
echo "matrix=$matrixStringifiedObject" >> $GITHUB_OUTPUT
6567
env:
66-
PROJECT_ROOT: ${{ inputs.project-root }}
68+
PROJECT_ROOT: ${{ inputs.project-root }}

‎scripts/parse_file_list_for_projects.sh‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ if [ "$INPUT" == "" ]; then
1313
exit 1
1414
fi
1515

16-
if [ "$PROJECT_ROOT" == "" ]; then
17-
PROJECT_ROOT=.
16+
if [ "$GIT_CMD" == "" ]; then
17+
GIT_CMD=$(which git)
18+
fi
19+
20+
if [ "$PROJECT_ROOT" == "" ] || [ "$PROJECT_ROOT" == "." ]; then
21+
repository_root=$($GIT_CMD rev-parse --show-toplevel)
22+
PROJECT_ROOT=$repository_root
23+
USE_ROOT=true
1824
fi
1925

2026
SCRIPT_DIR=$(cd $(dirname $0); pwd)
@@ -38,22 +44,30 @@ function folder_exists() {
3844
}
3945

4046
function git_root() {
41-
git rev-parse --show-toplevel
47+
$GIT_CMD rev-parse --show-toplevel
4248
}
4349

44-
if [ "$(folder_exists "$(git_root)/$PROJECT_ROOT")" == "0" ]; then
50+
if [ "$USE_ROOT" != "true" ] && [ "$(folder_exists "$(git_root)/$PROJECT_ROOT")" == "0" ]; then
4551
exit 0
4652
fi
4753

4854
# for each line get the first folder name
49-
if [ "$PROJECT_ROOT" == "." ]; then
50-
FOLDERS="$(echo "$INPUT" | sed 's/\// /g' | awk '{print $1}' | sort | uniq)"
55+
if [ "$USE_ROOT" == "true" ]; then
56+
BASE_NAMES="$(echo "$INPUT" | sed 's/\// /g' | awk '{print $1}' | sort | uniq)"
57+
# remove files from the FOLDERS list
58+
for NAME in $BASE_NAMES
59+
do
60+
# check if the name is a folder
61+
if [ "$(folder_exists "$NAME")" != "0" ]; then
62+
FOLDERS="$FOLDERS $NAME"
63+
fi
64+
done
5165
else
5266
FOLDERS="$(echo "$INPUT" | grep ''$PROJECT_ROOT'[/]' | sed 's/\// /g' | awk '{print $1 "/" $2}' | sort | uniq)"
5367
fi
5468

5569
# get list of folders triggered by dependencies
56-
if [ "$PROJECT_ROOT" == "." ]; then
70+
if [ "$USE_ROOT" == "true" ]; then
5771
DEPENDS_FOLDERS="$(echo "$INPUT" | $BUILD_DEPENDS_PATH | awk '{print $1}')"
5872
else
5973
DEPENDS_FOLDERS="$(echo "$INPUT" | $BUILD_DEPENDS_PATH | awk '{print "'$PROJECT_ROOT'/" $1}')"
@@ -71,7 +85,7 @@ if [ "$FOLDERS_THAT_DONT_EXIST" == "" ]; then
7185
done
7286
fi
7387

74-
if [ "$PROJECT_ROOT" == "." ]; then
88+
if [ "$USE_ROOT" == "true" ]; then
7589
IGNORE_LIST="$IGNORE_LIST .github"
7690
fi
7791
IGNORE_LIST="$IGNORE_LIST $FOLDERS_THAT_DONT_EXIST"
@@ -97,7 +111,7 @@ do
97111
done
98112

99113
# replace space with return character
100-
if [ "$PROJECT_ROOT" == "." ]; then
114+
if [ "$USE_ROOT" == "true" ]; then
101115
FOLDERS=$(echo $NEW_FOLDERS | sed 's/ /\n/g')
102116
else
103117
FOLDERS=$(echo $NEW_FOLDERS | sed 's/ /\n/g' | sed 's/^'$PROJECT_ROOT'\///g')

‎scripts/tests/parse_file_list_for_projects_test.sh‎

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@ function assert_equals {
1919
fi
2020
}
2121

22-
function beforeEach {
23-
export MOCK_ARGUMENT_FILE="$(mktemp)"
24-
export MOCK_TRACKING_FILE="$(mktemp)"
22+
function beforeAll {
2523
export FOLDER_EXISTS_CMD=$SCRIPT_DIR/mock_cmd.sh
2624
export BUILD_DEPENDS_PATH=$SCRIPT_DIR/mock_cmd.sh
25+
export GIT_CMD=$SCRIPT_DIR/mock_cmd.sh
2726
export PROJECT_ROOT=projects
2827
}
2928

29+
function beforeEach {
30+
export MOCK_ARGUMENT_FILE="$(mktemp)"
31+
export MOCK_TRACKING_FILE="$(mktemp)"
32+
}
33+
3034
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
3135

36+
beforeAll
37+
3238
echo Scenario: No Files
3339
beforeEach
3440

@@ -60,7 +66,8 @@ README.md"
6066
EXPECTED_RESULT="GithubWebhook
6167
Other"
6268
export MOCK_RESPONSES='[
63-
{"name":"project root folder exists"},
69+
{"name":"repository root","stdout":"/home/git/repo"},
70+
{"name":"project root folder exists","stdout":"1"},
6471
{"name":"dependency folders"},
6572
{"name":"folder 1 exists"},
6673
{"name":"folder 2 exists"}
@@ -90,6 +97,7 @@ EXPECTED_RESULT="GithubWebhook
9097
Other
9198
project-with-dependency"
9299
export MOCK_RESPONSES='[
100+
{"name":"repository root","stdout":"/home/git/repo"},
93101
{"name":"project root folder exists"},
94102
{"name":"dependency folders","stdout":"project-with-dependency"},
95103
{"name":"folder 1 exists"},
@@ -103,5 +111,45 @@ ACTUAL_RESULT="$(echo "$INPUT" | $CMD)"
103111

104112
# THEN
105113

114+
assert_equals "0" "$?"
115+
assert_equals "$EXPECTED_RESULT" "$ACTUAL_RESULT"
116+
117+
echo Scenario: Project files with dependencies where project root is .
118+
beforeEach
119+
120+
# GIVEN
121+
122+
export PROJECT_ROOT="."
123+
INPUT=".github/workflows/git-flow.yml
124+
GithubWebhook/README.md
125+
GithubWebhook/src/index.ts
126+
Other/README.md
127+
docs/adr/0001-architecture-decision-record.md
128+
README.md"
129+
EXPECTED_RESULT="GithubWebhook
130+
Other
131+
docs
132+
project-with-dependency"
133+
export MOCK_RESPONSES='[
134+
{"name":"repository root","stdout":"/home/git/repo"},
135+
{"name":"folder 1 exists"},
136+
{"name":"folder 2 exists"},
137+
{"name":"folder 3 exists"},
138+
{"name":"README.md is not a folder","stdout":"0"},
139+
{"name":"folder 4 exists"},
140+
{"name":"dependency folders","stdout":"project-with-dependency"},
141+
{"name":"folder 1 exists"},
142+
{"name":"folder 2 exists"},
143+
{"name":"folder 3 exists"},
144+
{"name":"folder 4 exists"},
145+
{"name":"folder 5 exists"}
146+
]'
147+
148+
# WHEN
149+
150+
ACTUAL_RESULT="$(echo "$INPUT" | $CMD)"
151+
152+
# THEN
153+
106154
assert_equals "0" "$?"
107155
assert_equals "$EXPECTED_RESULT" "$ACTUAL_RESULT"

0 commit comments

Comments
 (0)