Skip to content

Commit

Permalink
FIxed RestSpecRunnner with build_id for rest-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Mar 27, 2024
1 parent 5812ed5 commit 6280c64
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions util/RestSpecRunner.php
Expand Up @@ -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
Expand All @@ -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");

0 comments on commit 6280c64

Please sign in to comment.