Skip to content

Commit fe1cd4d

Browse files
committed
Add a script for running through some basic repository setup
Add a repository_setup.sh script that automates a couple of setup steps for setup of new rust-vmm repositories. It also supports updating the configuration of already created repositories by comparing the repository's configuration to the defaults in rust-vmm-ci and giving the option to update. Currently, the script supports dependabot setup and .platform file generation. It does not deal with the coverage files, since I am still hoping to switch us over to codecov.io in the future, at which point that will all changes completely anyway. Signed-off-by: Patrick Roy <[email protected]>
1 parent 0b1cb86 commit fe1cd4d

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

repository_setup.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#/bin/bash
2+
3+
set -euo pipefail
4+
5+
cat <<EOF
6+
Welcome to the rust-vmm interactive repository setup!
7+
8+
This script will guide you through initializing basic components of a fresh
9+
rust-vmm repository, or alternatively lets you update the configuration of an
10+
existing repository (for example, if since the first setup of a repository,
11+
rust-vmm-ci has added new features that you would like to use).
12+
13+
EOF
14+
15+
RUST_VMM_CI=$(dirname ${BASH_SOURCE[0]})
16+
17+
SUPPORTED_PLATFORMS=("x86_64" "aarch64" "riscv64")
18+
PLATFORMS_FILE=".platform"
19+
20+
DEPENDABOT_SCHEDULES=("weekly" "monthly")
21+
DEPENDABOT_FILE=".github/dependabot.yml"
22+
23+
confirm() {
24+
read -p "$1 [Y/n] " -n 1 -r
25+
26+
if [ ! -z $REPLY ]; then
27+
echo # move to new line unless user confirmed with just 'enter'
28+
else
29+
return 0
30+
fi
31+
[[ $REPLY =~ ^[Yy]$ ]]
32+
}
33+
34+
setup_platforms_file() {
35+
touch $PLATFORMS_FILE
36+
echo "Please select the hardware plaforms for which you would like to enable CI support:"
37+
for platform in "${SUPPORTED_PLATFORMS[@]}"; do
38+
question="Enable support for $platform?"
39+
if confirm "$question"; then
40+
echo $platform >> $PLATFORMS_FILE
41+
fi
42+
done
43+
}
44+
45+
setup_dependabot_config() {
46+
mkdir -p $(dirname $DEPENDABOT_FILE)
47+
48+
cat <<EOF
49+
Dependabot allow you to automatically receive PRs for bumping your cargo
50+
dependencies, as well as for updating the rust-vmm-ci submodule. You can choose
51+
to run dependabot on different schedules: ${DEPENDABOT_SCHEDULES[@]}.
52+
53+
Which schedule would you like to enable? (say 'n' to disable dependabot)
54+
EOF
55+
56+
select opt in "${DEPENDABOT_SCHEDULES[@]}"
57+
do
58+
selected_config=$RUST_VMM_CI/dependabot-$opt.yml
59+
60+
if [ -f $selected_config ]; then
61+
cp $selected_config $DEPENDABOT_FILE
62+
echo "Configured for $opt schedule"
63+
else
64+
echo "Not setting up dependabot"
65+
fi
66+
break
67+
done
68+
}
69+
70+
if [ -f $PLATFORMS_FILE ]; then
71+
current_platforms=$(tr '\n' ' ' < $PLATFORMS_FILE)
72+
question="This repository already has a $PLATFORMS_FILE file setup. Do you want to regenerate it? Current supported platforms are: $current_platforms"
73+
74+
if confirm "$question"; then
75+
rm $PLATFORMS_FILE
76+
setup_platforms_file
77+
fi
78+
else
79+
setup_platforms_file
80+
fi
81+
82+
echo
83+
84+
if [ -f "$DEPENDABOT_FILE" ]; then
85+
well_defined=0
86+
for schedule in "${DEPENDABOT_SCHEDULES[@]}"; do
87+
if cmp --silent $RUST_VMM_CI/dependabot-$schedule.yml $DEPENDABOT_FILE; then
88+
echo -n "Dependabot is already setup for the $schedule schedule. "
89+
well_defined=1
90+
fi
91+
done
92+
if [ $well_defined -eq 0 ]; then
93+
echo -n "Dependabot is already configured, although configuration does not match any rust-vmm-ci provided ones. "
94+
fi
95+
if confirm "Would you like to reconfigure dependabot?"; then
96+
rm $DEPENDABOT_FILE
97+
setup_dependabot_config
98+
fi
99+
else
100+
setup_dependabot_config
101+
fi

0 commit comments

Comments
 (0)