From 6280c6439dc4bf49ad0333594e6e6162e37a95ec Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Wed, 27 Mar 2024 14:58:18 +0100 Subject: [PATCH] FIxed RestSpecRunnner with build_id for rest-resource --- util/RestSpecRunner.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/util/RestSpecRunner.php b/util/RestSpecRunner.php index 121c68790..8f749c0ad 100644 --- a/util/RestSpecRunner.php +++ b/util/RestSpecRunner.php @@ -39,7 +39,8 @@ $version = $serverInfo['version']['number']; $artifactFile = sprintf("rest-resources-zip-%s.zip", $version); -$tempFilePath = sprintf("%s/%s.zip", sys_get_temp_dir(), $serverInfo['version']['build_hash']); +$buildHash = $serverInfo['version']['build_hash']; +$tempFilePath = sprintf("%s/%s.zip", sys_get_temp_dir(), $buildHash); if (!file_exists($tempFilePath)) { // Download of Elasticsearch rest-api artifacts @@ -49,28 +50,37 @@ exit(1); } $content = json_decode($json, true); + $found = false; foreach ($content['version']['builds'] as $builds) { - if ($builds['projects']['elasticsearch']['commit_hash'] === $serverInfo['version']['build_hash']) { + if ($builds['projects']['elasticsearch']['commit_hash'] === $buildHash) { // Download the artifact ZIP file (rest-resources-zip-$version.zip) printf("Download %s\n", $builds['projects']['elasticsearch']['packages'][$artifactFile]['url']); if (!copy($builds['projects']['elasticsearch']['packages'][$artifactFile]['url'], $tempFilePath)) { printf ("ERROR: failed to download %s\n", $artifactFile); } + $found = true; break; } } + if (!$found) { + $build = $content['version']['builds'][0]; // pick the most recent + $resource = $build["projects"]["elasticsearch"]["packages"][sprintf("rest-resources-zip-%s.zip", $version)]['url']; + if (!copy($resource, $tempFilePath)) { + printf ("ERROR: failed to download %s\n", $resource); + } + } } else { printf("The file %s already exists\n", $tempFilePath); } if (!file_exists($tempFilePath)) { - printf("ERROR: the commit_hash %s has not been found\n", $serverInfo['version']['build_hash']); + printf("ERROR: I cannot download file %s\n", $tempFilePath); exit(1); } $zip = new ZipArchive(); $zip->open($tempFilePath); -printf("Extracting %s\ninto %s/rest-spec/%s\n", $tempFilePath, __DIR__, $serverInfo['version']['build_hash']); -$zip->extractTo(sprintf("%s/rest-spec/%s", __DIR__, $serverInfo['version']['build_hash'])); +printf("Extracting %s\ninto %s/rest-spec/%s\n", $tempFilePath, __DIR__, $buildHash); +$zip->extractTo(sprintf("%s/rest-spec/%s", __DIR__, $buildHash)); $zip->close(); printf ("Rest-spec API installed successfully!\n\n"); \ No newline at end of file