Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verification run scheduler #5647

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
130 changes: 130 additions & 0 deletions script/openqa-verify-pr
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash
# Copyright 2024 (c) SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved

# Schedule a verification run for a os-autoinst PR
# USAGE:
#
# schedule_verification_run $SOURCE $PR_ID $BASE_TEST_ID $[test/module, test/module, ...] $TEST_NAME
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved
#
# Parameters
#
# * $SOURCE - The source you want to schedule a rund for. Can be either opensuse or suse.
# * $PR_ID - The ID of your GitHub Pull Request.
# * $BASE_TEST_ID - The ID of the test you want you use as a base.
# * $[test/module, ...] - The modules of your test you want to schedule for.
# * $TEST_NAME - The Name of your test. (E.g.: TETS=RUST)
#
# Specify your GitHub access token in a config file at '~/.config/openqa/gh.conf' like this:
#
# ```
# GH_ACCESS_TOKEN="YOUR_TOKEN_HERE"
# ```
#
# Default test modules
#
# The following modules are automatically selected to load for your run:
#
# * 'tests/installation/bootloader_start'
# * 'tests/boot/boot_to_desktop'
#
# Example
#
# Pass arguments to this script like this:
#
# schedule_verification_run opensuse TOKEN 1234 12345 tests/console/rustup,tests/console/cargo RUST


help_text=$(cat <<'EOF'
OpenQA verification run scheduler.
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved

Usage:
schedule_verification_run $SOURCE $PR_ID $BASE_TEST_ID $[test/module, test/module,...] $TEST_NAME
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved

Parameters:
SOURCE - The source you want to schedule a run for. Can be either opensuse or suse.
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved
PR_ID - The ID of your GitHub Pull Request.
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved
BASE_TEST_ID - The ID of the test you want you use as a base.
[test/module,...] - The modules of your test you want to schedule for.
TEST_NAME - The Name of your test. (E.g.: TEST=RUST)

Specify your GitHub access token in '~/.config/openqa/verification.conf' like this:

GH_ACCESS_TOKEN="YOUR_TOKEN_HERE"

To specify the URL to your own openQA instance specify it in the same config file like this:

CUSTOM_TARGET="https://openqa.yourdomain.com"

Default test modules:
The following modules are automatically selected to load for your run:
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved

'tests/installation/bootloader_start'
'tests/boot/boot_to_desktop'

Options:
-h, --help Display this help text.

EOF
)

set -o pipefail

source="$1"
pr_id="$2"
test_id="$3"
modules="$4"
test_name="$5"

config_file="$HOME/.config/openqa/verification.conf"
config=""
custom_target=""
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved

# See help text.
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved
echo "$help_text"
exit 0
fi

# If too few or too many arguments are supplied -> die.
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved
if [ "$#" -ne 5 ]; then
echo "Invalid number of arguments. Run with '-h' or '--help' to view usage."
exit 1
fi

# Read GH token from config file.
if [[ -f "$config_file" ]]; then
config=$(grep "^GH_ACCESS_TOKEN=" "$config_file" | cut -d'"' -f2)
custom_target=$(grep "^CUSTOM_TARGET=" "$config_file" | cut -d'"' -f2)
else
echo "No config file found! Run with '-h' for more info."
exit 1
fi

GITHUB_TOKEN=$config

export GITHUB_TOKEN
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved

if [ "$source" = "opensuse" ]; then
echo "Dispatching verification run for opensuse..."
openqa-clone-custom-git-refspec "https://github.com/os-autoinst/os-autoinst-distri-opensuse/pull/$pr_id" \
"https://openqa.opensuse.org/tests/$test_id" \
SCHEDULE="tests/installation/bootloader_start,tests/boot/boot_to_desktop,$modules" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to move this to the openqa-clone-custom-git-refspec behind a switch i.e --modules a,b,c so it gets appended via the for loop, before calling cone job.

and then there's the consideration that if the caller is passing:

  • YAML_SCHEDULE + SCHEDULE, die (as one of them has to be overwritten.
  • if the switch is passed, and so is either (yaml_schedule or schedule) die, as options aren't compatible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, currently looking into that :)

TEST="$test_name"
elif [ "$source" = "suse" ]; then
echo "Dispatching verification run for suse..."
openqa-clonse-custom-git-refspec "https://github.com/os-autoinst-distri-opensuse/pull/$pr_id" \
"https://openqa.suse.de/tests/$test_id" \
SCHEDULE="tests/installation/bootloader_start,tests/boot/boot_to_desktop,$modules" \
TEST="$test_name"
elif [ "$source" = "custom" ]; then
echo "Dispatching verification run for your custom target '$custom_target'..."
openqa-clone-custom-git-refspec "https://github.com/os-autoinst-distri-opensuse/pull/$pr_id" \
"$custom_target/tests/$test_id" \
SCHEDULE="tests/installation/bootloader_start,tests/boot/boot_to_desktop,$modules" \
TEST="$test_name"
else
# NOTE: Technically we could support custom targets via a config file. TBI.
echo "Unknown argument '$1'. Must be either 'suse', 'opensuse' or 'custom'."
exit 1
fi
Loading