-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget_plugin_slug.sh
More file actions
74 lines (60 loc) · 1.93 KB
/
Copy pathget_plugin_slug.sh
File metadata and controls
74 lines (60 loc) · 1.93 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
#!/usr/bin/env bash
set -e
BASE_SHA="$1"
HEAD_SHA="$2"
git fetch --prune --unshallow 2>/dev/null || git fetch --prune
# Get changed files in plugins subdirectories
if [ "$BASE_SHA" = "release" ] || [ "$BASE_SHA" = "main" ]; then
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/[^/]\+/' || true)
else
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" | grep '^plugins/[^/]\+/' || true)
fi
if [ -z "$CHANGED_FILES" ]; then
echo "No plugin files changed"
exit 1
fi
# Extract plugin names from both old and new paths
PLUGINS=()
for file in $CHANGED_FILES; do
plugin=$(echo $file | cut -d/ -f2)
PLUGINS+=("$plugin")
done
# Get unique plugin names
UNIQUE_PLUGINS=($(printf '%s\n' "${PLUGINS[@]}" | sort -u))
# Find all valid plugins that have changes
VALID_PLUGINS=()
for plugin in "${UNIQUE_PLUGINS[@]}"; do
if [ -d "plugins/$plugin" ]; then
count=$(printf '%s\n' "${PLUGINS[@]}" | grep -c "^$plugin$")
VALID_PLUGINS+=("$plugin")
echo "Found plugin with $count changes: $plugin"
fi
done
# Output all valid plugins as JSON array for matrix strategy
if [ ${#VALID_PLUGINS[@]} -gt 0 ]; then
# Simple, reliable JSON array generation
PLUGINS_JSON="["
for i in "${!VALID_PLUGINS[@]}"; do
if [ $i -eq 0 ]; then
PLUGINS_JSON="$PLUGINS_JSON\"${VALID_PLUGINS[i]}\""
else
PLUGINS_JSON="$PLUGINS_JSON,\"${VALID_PLUGINS[i]}\""
fi
done
PLUGINS_JSON="$PLUGINS_JSON]"
echo "plugins=$PLUGINS_JSON" >> "$GITHUB_OUTPUT"
echo "has-plugins=true" >> "$GITHUB_OUTPUT"
# For backward compatibility, set slug to first plugin
PLUGIN_SLUG="${VALID_PLUGINS[0]}"
else
echo "plugins=[]" >> "$GITHUB_OUTPUT"
echo "has-plugins=false" >> "$GITHUB_OUTPUT"
PLUGIN_SLUG=""
fi
if [ -z "$PLUGIN_SLUG" ]; then
echo "No valid plugin directory found"
exit 1
fi
echo "slug=$PLUGIN_SLUG" >> "$GITHUB_OUTPUT"
echo "Changed files: $CHANGED_FILES"
echo "Detected plugin(s): ${UNIQUE_PLUGINS[*]}"