-
Notifications
You must be signed in to change notification settings - Fork 2
/
find_public_apps.sh
52 lines (43 loc) · 1.62 KB
/
find_public_apps.sh
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
#!/bin/bash
# Check if the current branch is 'main'
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" == "main" ]; then
# Compare the latest commit with its previous commit
changed_items=$(git diff --name-only HEAD HEAD~1)
else
# Fetch the main branch
git fetch origin main:main
# Compare the current branch with the main branch
changed_items=$(git diff --name-only HEAD main)
fi
# Initialize an empty string to hold the names of changed top-level directories
changed_dirs=""
# Loop through each item and process
for item in $changed_items; do
# Extract the top-level directory name
top_dir=$(echo $item | cut -d'/' -f1)
# Check if it's a directory, not hidden, and does not start with 'teaser-'
if [[ -d $top_dir ]] && [[ ! $top_dir =~ ^\..* ]] && [[ ! $top_dir =~ ^teaser-.* ]]; then
# Add to the list if not already present
if [[ ! $changed_dirs =~ $top_dir ]]; then
changed_dirs+="$top_dir "
fi
fi
done
# Sort and remove duplicate entries
changed_dirs=$(echo $changed_dirs | tr ' ' '\n' | sort -u)
# Filter out directories listed in .deployignore, if the file exists
if [ -f ".deployignore" ]; then
for ignore in $(cat .deployignore); do
changed_dirs=$(echo "$changed_dirs" | grep -v "^$ignore$")
done
fi
# Convert to JSON format and write to environment file
json_output="{\"app_name\": ["
for dir in $changed_dirs; do
json_output+="\"$dir\","
done
json_output=$(echo "$json_output" | sed 's/,$//') # Remove trailing comma
json_output+="]}"
# Write to GitHub environment file
echo "MATRIX_JSON=$json_output" >> $GITHUB_ENV