-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupdate-dependabot.sh
executable file
·56 lines (45 loc) · 1.46 KB
/
update-dependabot.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
53
54
55
56
#!/bin/bash -e
# Directory containing composite actions
actions_dir='.github/actions'
# Dependabot source config file
master_config='.github/dependabot.template.yml'
# Dependabot target config file
dependabot_config='.github/dependabot.yml'
# Temp file for new Dependabot config section
temp_config='temp_dependabot.yml'
# Function to generate Dependabot config section for a composite action
generate_dependabot_section() {
local action_dir=$1
cat <<END
- package-ecosystem: "github-actions"
directory: "/${action_dir}"
schedule:
interval: "weekly"
groups:
catch-all:
patterns:
- "*"
END
}
# Check if Dependabot config exists
if [ ! -f "$master_config" ]; then
echo "$master_config config not found."
exit 1
fi
# Ensure yq is installed
if ! command -v yq &> /dev/null; then
echo "yq is not installed. Please install it to continue."
exit 1
fi
# Start building the new config section
echo "version: 2" > "$temp_config"
echo "updates:" >> "$temp_config"
# Loop through composite actions and append to temp config
for action_filename in $(find "$actions_dir" -mindepth 2 -type f -name action.yml | env -i LC_COLLATE=C sort -n); do
action_dir=$(dirname $action_filename)
generate_dependabot_section "$action_dir" >> "$temp_config"
done
# Merge new section with existing Dependabot config using yq
yq eval-all '. as $item ireduce ({}; . *+ $item)' $master_config $temp_config > "$dependabot_config"
# Clean up
rm "$temp_config"