-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_modified_branch_files
More file actions
executable file
·54 lines (47 loc) · 1.59 KB
/
test_modified_branch_files
File metadata and controls
executable file
·54 lines (47 loc) · 1.59 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
#!/usr/bin/env bash
# Default base branch
base_branch="main"
opts=()
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--base)
base_branch="$2"
shift 2
;;
*)
opts+=("$1")
shift
;;
esac
done
# Get current branch name
current_branch=$(git rev-parse --abbrev-ref HEAD)
# Get modified files based on whether we're on the base branch
if [[ "$current_branch" == "$base_branch" ]]; then
# On base branch: get uncommitted changes
file_paths=$(git diff --name-only HEAD | grep -E '\.exs?$' | grep -v "mix.exs" | grep -v "config/")
else
# On feature branch: compare with base branch
file_paths=$({ git diff --name-only "$base_branch"...HEAD; git diff --name-only HEAD; } | sort -u | grep -E '\.exs?$' | grep -v "mix.exs" | grep -v "config/")
fi
# Initialize array to store transformed paths
transformed_paths=()
# Process the file paths
for path in $file_paths; do
if [[ $path == lib/* ]]; then
# Replace 'lib/' with 'test/' and change '.ex' to '_test.exs'
transformed_path=$(echo "$path" | sed -E 's|^lib/|test/|; s|\.ex$|_test.exs|')
transformed_paths+=("$transformed_path")
elif [[ $path == *_test.exs ]]; then
# Only include files that end with _test.exs
transformed_paths+=("$path")
fi
done
# Output the mix test command if there are test files
if [[ ${#transformed_paths[@]} -gt 0 ]]; then
echo "mix test ${opts[*]} ${transformed_paths[*]}"
mix test "${opts[@]}" "${transformed_paths[@]}"
else
echo "No test files ending with _test.exs found."
fi