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
126 changes: 126 additions & 0 deletions script/openqa-verify_pr
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/bin/bash
# Copyright 2024 (c) SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

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

USAGE:
======

$ schedule_verification_run $SOURCE $PR_ID $BASE_TEST_ID $[test/module, test/module,...] $TEST_NAME

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.: TEST=RUST)

Specify your GitHub access token in '~/.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'

Options
-------

* '-h' / '--help' - Display this help text.

EOF
)

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

config_file="$HOME/.config/openqa/gh.conf"
config=""

# See help text.
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$help_text"
exit 0
fi

# If too few or too many arguments are supplied -> die.
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)
else
echo "No GitHub token file found! Run with '-h' for more info."
exit 1
fi

GITHUB_TOKEN=$config

export GITHUB_TOKEN

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" \
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" \
Copy link
Member

Choose a reason for hiding this comment

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

I wonder, are you aware of the existing support for job URL's within the PR description? See https://github.com/os-autoinst/openQA/blob/master/script/openqa-clone-custom-git-refspec#L52

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually wasn't aware of this, thanks for making me aware. That'd make integrating parts of the ideas into openqa-clone-custom-git-refspec even more alluring to take advantage of this feature. @foursixnine, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to mention that we came to the conclusion that it is better to avoid the @-syntax as one probably don't want to mention the @openqa organization on GitHub here. Of course this makes the mentioned feature of the refspec script less interesting - unless one would change it.

However, I suggest to use https://github.com/os-autoinst/scripts/blob/master/openqa-clone-and-monitor-job-from-pr instead (which is already setup for the openSUSE test distribution and uses the openqa: Clone … syntax). It will soon also support creating clones by creating/editing comments but it is so far limited to the PR description.

(You can also read https://open.qa/docs/#_create_and_monitor_openqa_jobs_from_within_the_ci_runner for more information on the broader topic.)

Copy link
Member

@foursixnine foursixnine May 21, 2024

Choose a reason for hiding this comment

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

I actually wasn't aware of this, thanks for making me aware. That'd make integrating parts of the ideas into openqa-clone-custom-git-refspec even more alluring to take advantage of this feature. @foursixnine, what do you think?

Yep its the first point here: #5647 (comment)

I wonder, are you aware of the existing support for job URL's within the PR description?

the extract URLs from description sounds nice, but only useful if it would edit the description and add the badges; I'd say lets keep that out of scope :)

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' or 'opensuse'. Custom openqa instances not yet supported."
exit 1
fi
Loading