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
15 changes: 14 additions & 1 deletion script/openqa-clone-custom-git-refspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ set -o pipefail
if [[ -n "$GITHUB_TOKEN" ]]; then
AUTHENTICATED_REQUEST=" -u $GITHUB_TOKEN:x-oauth-basic"
echo "Github oauth token provided, performing authenticated requests"
elif [[ -f "$HOME/.config/openqa/verification.conf" ]]; then
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved
AUTHENTICATED_REQUEST=" -u $(get_token_from_file):x-oauth-basic"
echo "Github oauth token found in config file, performing authenticated requests"
fi

curl_github="${curl_github:-"curl${AUTHENTICATED_REQUEST}"}"
Expand All @@ -55,6 +58,16 @@ extract_urls_from_pr() {
fi
}

# Get the Github Token from a config file
# located at ~/.config/openqa/verification.conf
get_token_from_file() {
local config_file="$HOME/.config/openqa/verification.conf"
ByteOtter marked this conversation as resolved.
Show resolved Hide resolved
if [[ -f $config_file ]]; then
token=$(grep "^GH_ACCESS_TOKEN=" "$config_file" | cut -d'd' -f2)
echo "$token"
fi
}

opts=$(getopt -o vhnc: --long verbose,dry-run,help,clone-job-args: -n "$0" -- "$@") || usage 1
eval set -- "$opts"
while true; do
Expand Down Expand Up @@ -97,8 +110,8 @@ if [[ -z "$repo_name" ]] || [[ -z "$pr" ]]; then
casedir="${casedir:-"${forked_repo_part}.git#${branch}"}"
build="${build:-"$repo_name#$branch"}"
fi

fi

if [[ -z "$branch" ]] || [[ -z "$repo_name" ]]; then
pr_url=${target_repo_part/github.com/api.github.com/repos}/pulls/$pr
pr_content=$(eval "${curl_github} -s $pr_url")
Expand Down
119 changes: 119 additions & 0 deletions script/openqa-verify-pr
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/bash
# Copyright 2024 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

# OpenQA verification run scheduler
#
# Usage:
# openqa-verify-pr $SOURCE $PR_ID $BASE_TEST_ID $[test/module, test/module,...] $TEST_NAME
#
# Parameters:
# SOURCE - The source you want to schedule a run 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.: 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
# 'tests/installation/bootloader_start'
# 'tests/boot/boot_to_desktop'
#
# Options:
# -h, --help Display this help text.
#
# 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

Usage:
openqa-verify-pr $SOURCE $PR_ID $BASE_TEST_ID $[test/module, test/module,...] $TEST_NAME

Parameters:
SOURCE - The source you want to schedule a run 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.: 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:
'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=

if [ $1 = '-h' ] || [ $1 = '--help' ]; then
echo "$help_text"
exit 0
fi

# Validate argument count
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

export GITHUB_TOKEN=$config

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