Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 14 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ git submodule add https://github.com/rust-vmm/rust-vmm-ci.git
git commit -s -m "Added rust-vmm-ci as submodule"
```

2. Create the coverage test configuration file named
2. Run the initial setup script for configuring dependabot for automated cargo
and submodule updates, as well as configuring which hardware platforms CI
should be run for:

```bash
# Script has to be run relative to the repository root!
./rust-vmm-ci/setup_repository.sh
```

3. Create the coverage test configuration file named
`coverage_config_ARCH.json` in the root of the repository, where `ARCH` is the
architecture of the machine.
There are two coverage test configuration files, one per each platform.
Expand Down Expand Up @@ -55,14 +64,6 @@ Additionally, the following optional fields are available:
This file is required for the coverage integration so it needs to be added
to the repository as well.

3. Copy one of the two provided dependabot configurations to `.github/dependabot.yml`,
e.g. run `cp rust-vmm-ci/dependabot-{weekly,monthly}.yml .github/dependabot.yml`.
Note that just symlinking the file does not work, as dependabot will not
follow symlinks into submodules. This means that updates to these files made in
rust-vmm-ci will need to be manually consumed for now. We recommend setting up
weekly dependabot updates only if the crate receives multiple contributions a week,
and if you expect to have the bandwidth to address weekly dependency PRs.

4. Create a new pipeline definition in Buildkite. For this step ask one of the
rust-vmm Buildkite [admins](CODEOWNERS) to create one for you. The process is explained
[here](https://github.com/rust-vmm/community/blob/main/docs/setup_new_repo.md#set-up-ci).
Expand Down Expand Up @@ -119,24 +120,7 @@ For most use cases, overriding or extending the configuration is not necessary.
want to do so if, for example, the platform needs a custom device that is not available
on the existing test instances or if we need a specialized hypervisor.

6. Tests will be running on `x86_64` and `aarch64` platforms by default. To change
this, e.g. to enable other experimental platforms like `riscv64`, a `.platform`
file can be included in the repository root. This file documents what platforms
are to be enabled for the repository.

If `.platform` file is provided, it will be strictly observed. In `.platform`
file, each platform are separated by newline character. Currently, we support
`x86_64`, `aarch64` and `riscv64` platforms.

For example, we can enable tests to be run on `riscv64` platform in addition to
`x86_64` and `aarch64` by:
```
x86_64
aarch64
riscv64
```

7. The code owners of the repository will have to setup a WebHook for
6. The code owners of the repository will have to setup a WebHook for
triggering the CI on
[pull request](https://developer.github.com/v3/activity/events/types/#pullrequestevent)
and [push](https://developer.github.com/v3/activity/events/types/#pushevent)
Expand All @@ -148,7 +132,9 @@ The [Buildkite](https://buildkite.com) pipeline is the definition of tests to
be run as part of the CI. It includes steps for running unit tests and linters
(including coding style checks), and computing the coverage.

Currently the tests can run on Linux `x86_64` and `aarch64` hosts.
Currently the tests can run on Linux `x86_64`, `aarch64` and `riscv64`
(virtualized inside QEMU) hosts. Which hosts tests should be ran for is
determined by the `.platform` file in the repository root.

Example of step that checks the build:

Expand Down
21 changes: 21 additions & 0 deletions publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish to crates.io

on:
push:
tags: ['v*'] # Triggers when pushing version tags

jobs:
publish:
runs-on: ubuntu-latest
# environment: release # Optional: for enhanced security
permissions:
id-token: write # Required for OIDC token exchange
steps:
- uses: actions/checkout@v4
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- run: |
cd .
cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
144 changes: 144 additions & 0 deletions repository_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#/bin/bash

set -euo pipefail

cat <<EOF
Welcome to the rust-vmm interactive repository setup!

This script will guide you through initializing basic components of a fresh
rust-vmm repository, or alternatively lets you update the configuration of an
existing repository (for example, if since the first setup of a repository,
rust-vmm-ci has added new features that you would like to use).

EOF

RUST_VMM_CI=$(dirname ${BASH_SOURCE[0]})

SUPPORTED_PLATFORMS=("x86_64" "aarch64" "riscv64")
PLATFORMS_FILE=".platform"

DEPENDABOT_SCHEDULES=("weekly" "monthly")
DEPENDABOT_FILE=".github/dependabot.yml"

confirm() {
read -p "$1 [Y/n] " -n 1 -r

if [ ! -z $REPLY ]; then
echo # move to new line unless user confirmed with just 'enter'
else
return 0
fi
[[ $REPLY =~ ^[Yy]$ ]]
}

setup_platforms_file() {
touch $PLATFORMS_FILE
echo "Please select the hardware plaforms for which you would like to enable CI support:"
for platform in "${SUPPORTED_PLATFORMS[@]}"; do
question="Enable support for $platform?"
if confirm "$question"; then
echo $platform >> $PLATFORMS_FILE
fi
done
}

setup_dependabot_config() {
mkdir -p $(dirname $DEPENDABOT_FILE)

cat <<EOF
Dependabot allow you to automatically receive PRs for bumping your cargo
dependencies, as well as for updating the rust-vmm-ci submodule. You can choose
to run dependabot on different schedules: ${DEPENDABOT_SCHEDULES[@]}.

Which schedule would you like to enable? (say 'n' to disable dependabot)
EOF

select opt in "${DEPENDABOT_SCHEDULES[@]}"
do
selected_config=$RUST_VMM_CI/dependabot-$opt.yml

if [ -f $selected_config ]; then
cp $selected_config $DEPENDABOT_FILE
echo "Configured for $opt schedule"
else
echo "Not setting up dependabot"
fi
break
done
}

if [ -f $PLATFORMS_FILE ]; then
current_platforms=$(tr '\n' ' ' < $PLATFORMS_FILE)
question="This repository already has a $PLATFORMS_FILE file setup. Do you want to regenerate it? Current supported platforms are: $current_platforms"

if confirm "$question"; then
rm $PLATFORMS_FILE
setup_platforms_file
fi
else
setup_platforms_file
fi

echo

if [ -f "$DEPENDABOT_FILE" ]; then
well_defined=0
for schedule in "${DEPENDABOT_SCHEDULES[@]}"; do
if cmp --silent $RUST_VMM_CI/dependabot-$schedule.yml $DEPENDABOT_FILE; then
echo -n "Dependabot is already setup for the $schedule schedule. "
well_defined=1
fi
done
if [ $well_defined -eq 0 ]; then
echo -n "Dependabot is already configured, although configuration does not match any rust-vmm-ci provided ones. "
fi
if confirm "Would you like to reconfigure dependabot?"; then
rm $DEPENDABOT_FILE
setup_dependabot_config
fi
else
setup_dependabot_config
fi

echo
echo "Setting up auto-publish for crates.io upon creation of GitHub tags..."

if [ ! -f Cargo.toml ]; then
echo "Cargo.toml not found. Please re-run this script after setting up the crates to configure auto-publishing!"
else
mkdir -p .github/workflows
if grep -q '\[workspace\]' Cargo.toml; then
members="$(cargo metadata --format-version 1 | jq '.workspace_members[]')"
for member_path in $members; do
member_path="${member_path#*//}"
member_path="${member_path%#*}"

crate_name=$(basename $member_path)
# get path relative to crate root
member_path=$(realpath -m --relative-to . $member_path)

workflow_file=.github/workflows/publish-$crate_name.yml
# Use printf when writing this value, so that whitespaces/newlines are respected
workflow=$(sed "s/'v\*'/'$crate_name-v*'/" $RUST_VMM_CI/publish.yml | sed "s/cd ./cd $member_path/")

if [ -f $workflow_file ] && cmp --silent $workflow_file <(printf "$workflow"); then
echo "Publish workflow for $crate_name already setup, skipping"
continue
fi

if confirm "Found workspace member '$crate_name' at '$member_path'. Setup auto-publish?"; then
if [ -f $workflow_file ] && ! confirm "$workflow_file already exists. Overwrite?"; then
continue
fi

printf "$workflow" > $workflow_file
echo "If not already done, go to https://crates.io/crates/$crate_name/settings and add $(basename $workflow_file) as a trusted publisher!"
fi
done
else
question="Single crate repository detected, setup running 'cargo publish' at repository root when tags matching 'v*' are published? (if a .github/workflows/publish.yml file already exists, it will be overwritten)"
if confirm "$question"; then
cp $RUST_VMM_CI/publish.yml .github/workflows/publish.yml
fi
fi
fi