Skip to content

Commit

Permalink
Add support for latest deployment release
Browse files Browse the repository at this point in the history
  • Loading branch information
BillAnastasiadis committed Jun 10, 2024
1 parent 8e8f041 commit 6987974
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
16 changes: 15 additions & 1 deletion lib/qesapdeployment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,21 @@ sub qesap_get_deployment_code {
if (get_var('QESAP_INSTALL_VERSION')) {
record_info('WARNING', 'QESAP_INSTALL_GITHUB_REPO will be ignored') if (get_var('QESAP_INSTALL_GITHUB_REPO'));
record_info('WARNING', 'QESAP_INSTALL_GITHUB_BRANCH will be ignored') if (get_var('QESAP_INSTALL_GITHUB_BRANCH'));
my $ver_artifact = 'v' . get_var('QESAP_INSTALL_VERSION') . '.tar.gz';
my $ver_artifact;
if (get_var('QESAP_INSTALL_VERSION') eq 'latest') {
my $latest_release_url = "https://$official_repo/releases/latest";
my $redirect_url = script_output("curl -s -L -o /dev/null -w %{url_effective} $latest_release_url");
if ($redirect_url =~ /\/tag\/v([0-9.]+)$/) {
my $version = $1;
$ver_artifact = "v$version.tar.gz";
record_info("Latest QE-SAP-DEPLOYMENT release used: $version", $version);
} else {
die "Failed to parse the latest version from $redirect_url";
}
}
else {
$ver_artifact = 'v' . get_var('QESAP_INSTALL_VERSION') . '.tar.gz';
}

my $curl_cmd = "curl -v -fL https://$official_repo/archive/refs/tags/$ver_artifact -o$ver_artifact";
assert_script_run("set -o pipefail ; $curl_cmd | tee " . $qesap_git_clone_log, quiet => 1);
Expand Down
28 changes: 27 additions & 1 deletion t/09_qesapdeployment.t
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ subtest '[qesap_get_deployment_code] from branch' => sub {
ok((any { /git.*clone.*--branch.*TED/ } @calls), 'Checkout expected branch');
};

subtest '[qesap_get_deployment_code] from a release' => sub {
subtest '[qesap_get_deployment_code] from a specific release' => sub {
my $qesap = Test::MockModule->new('qesapdeployment', no_auto => 1);
my @calls;
$qesap->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
Expand All @@ -152,6 +152,32 @@ subtest '[qesap_get_deployment_code] from a release' => sub {
ok((any { /tar.*[xvf]+.*vCORAL\.tar\.gz/ } @calls), 'Decompress the release archive');
};

subtest '[qesap_get_deployment_code] from the latest release' => sub {
my $qesap = Test::MockModule->new('qesapdeployment', no_auto => 1);
my @calls;
$qesap->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
$qesap->redefine(enter_cmd => sub { push @calls, $_[0]; });
$qesap->redefine(assert_script_run => sub { push @calls, $_[0]; });
$qesap->redefine(script_output => sub { return "MYGITHUBREPO/tag/v1.0.0" });
$qesap->redefine(qesap_get_file_paths => sub {
my %paths;
$paths{deployment_dir} = '/BRUCE';
$paths{terraform_dir} = '/BRUCE/OCEAN';
return (%paths);
});
set_var('QESAP_INSTALL_VERSION', 'latest');
# set to test that it is ignored
set_var('QESAP_INSTALL_GITHUB_REPO', 'WHALE');

qesap_get_deployment_code();

set_var('QESAP_INSTALL_VERSION', undef);
set_var('QESAP_INSTALL_GITHUB_REPO', undef);
note("\n --> " . join("\n --> ", @calls));
ok((any { /curl.*github.com\/SUSE\/qe-sap-deployment\/archive\/refs\/tags\/v1.0.0\.tar\.gz.*-ov1.0.0\.tar\.gz/ } @calls), 'Get latest release archive from github');
ok((any { /tar.*[xvf]+.*v1.0.0\.tar\.gz/ } @calls), 'Decompress the release archive');
};

subtest '[qesap_get_roles_code] from default github' => sub {
my $qesap = Test::MockModule->new('qesapdeployment', no_auto => 1);
my @calls;
Expand Down

0 comments on commit 6987974

Please sign in to comment.