|
| 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