Skip to content

Commit

Permalink
openqa-clone-custom-git-refspec: Add option to pass clone-job arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
okurz committed Mar 3, 2020
1 parent 5c441cf commit c0c58e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 8 additions & 5 deletions script/openqa-clone-custom-git-refspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ Usage:
openqa-clone-custom-git-refspec <github_branch_url> <openqa_job_url> [CUSTOM_TEST_VAR_1=foo] [CUSTOM_TEST_VAR_2=bar] ...
Options:
-v, --verbose execute with verbose output
-h, -?, --help display this help
-n, --dry-run execute in dry-run mode, do not clone any openQA jobs
-v, --verbose execute with verbose output
-h, -?, --help display this help
-n, --dry-run execute in dry-run mode, do not clone any openQA jobs
-c --clone-job-args pass additional parameters to 'openqa-clone-job', e.g. '--clone-job-args="--show-progress"'
Examples:
openqa-clone-custom-git-refspec https://github.com/os-autoinst/os-autoinst-distri-opensuse/pull/6529 https://openqa.opensuse.org/tests/835060 DESKTOP=textmode
openqa-clone-custom-git-refspec https://github.com/coolgw/os-autoinst-distri-opensuse/tree/nfs https://openqa.opensuse.org/tests/835060 DESKTOP=textmode
openqa-clone-custom-git-refspec -n -c '--show-progress' https://github.com/coolgw/os-autoinst-distri-opensuse/tree/nfs https://openqa.opensuse.org/tests/835060 DESKTOP=textmode
EOF
exit
}
Expand All @@ -35,13 +37,14 @@ throw_json_error() {
exit 2
}

opts=$(getopt -o vhn --long verbose,dry-run,help -n 'parse-options' -- "$@") || usage
opts=$(getopt -o vhnc: --long verbose,dry-run,help,clone-job-args: -n 'parse-options' -- "$@") || usage
eval set -- "$opts"
while true; do
case "$1" in
-v | --verbose ) set -x; shift ;;
-h | --help ) usage; shift ;;
-n | --dry-run ) dry_run=true; shift ;;
-c | --clone-job-args ) clone_args="$2 $clone_args"; shift 2 ;;
-- ) shift; break ;;
* ) break ;;
esac
Expand Down Expand Up @@ -108,7 +111,7 @@ clone_job() {
local casedir="${casedir:-"$repo#$branch"}"
local GROUP="${GROUP:-0}"
local dry_run="${dry_run:-""}"
local cmd="$dry_run openqa-clone-job \"$clone_args\" \"$host\" \"$job\" _GROUP=\"$GROUP\" TEST=\"$test\" BUILD=\"$build\" CASEDIR=\"$casedir\" PRODUCTDIR=\"$productdir\" NEEDLES_DIR=\"$needles_dir\""
local cmd="$dry_run openqa-clone-job $clone_args \"$host\" \"$job\" _GROUP=\"$GROUP\" TEST=\"$test\" BUILD=\"$build\" CASEDIR=\"$casedir\" PRODUCTDIR=\"$productdir\" NEEDLES_DIR=\"$needles_dir\""
cmd=$cmd"$(printf " '%s'" "${args[@]}")"
if [[ -n "$MARKDOWN" ]]; then
eval "$cmd" | sed 's/^Created job.*: \([^ ]*\) -> \(.*\)$/* [\1](\2)/'
Expand Down
11 changes: 7 additions & 4 deletions t/40-script_openqa-clone-custom-git-refspec.t
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ combined_like sub { $ret = run_once('', $prefix) }, $expected_custom_re, 'testsu
is $ret, 0, 'exits successfully';
my $args_trailing = 'https://github.com/me/repo/pull/1/ https://openqa.opensuse.org/tests/1';
test_once $args_trailing, qr{TEST=my_test\@user/repo#my_branch.*}, 'trailing slash ignored';
$args .= ',https://openqa.opensuse.org/tests/1234';
my $args_list = $args . ',https://openqa.opensuse.org/tests/1234';
$expected_re = qr/${expected}.*opensuse.org 1234/s;
test_once $args, $expected_re, 'accepts comma-separated list of jobs';
$args .= ' FOO=bar';
test_once $args_list, $expected_re, 'accepts comma-separated list of jobs';
$args_list .= ' FOO=bar';
$expected_re = qr/${expected} FOO=bar.*opensuse.org 1234.*FOO=bar/s;
test_once $args, $expected_re, 'additional arguments are passed as test parameters for each job';
test_once $args_list, $expected_re, 'additional arguments are passed as test parameters for each job';
my $args_clone = '--clone-job-args="--show-progress" ' . $args;
$expected_re = qr/openqa-clone-job --show-progress --skip-chained-deps --within-instance https/;
test_once $args_clone, $expected_re, 'additional parameters can be passed to clone-job';

my $args_escape
= q(https://github.com/me/repo/pull/1/ https://openqa.opensuse.org/tests/1 TEST1=$FOO_BAR 'TEST2=$VAR' TEST3=space\\ space 'TEST4=(!?bla)');
Expand Down

0 comments on commit c0c58e3

Please sign in to comment.