Fix selftest when run in docker
This commit is contained in:
@@ -8,7 +8,7 @@ require_once (__DIR__ . '/../internals/website.php');
|
||||
|
||||
if (!isset($API_OPTIONS['name'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
|
||||
|
||||
$name = $API_OPTIONS['name'];
|
||||
$name = urldecode($API_OPTIONS['name']);
|
||||
|
||||
$updatedata = $SITE->modules->UpdatesLog()->listUpdateData();
|
||||
|
||||
|
||||
@@ -532,25 +532,34 @@ class SelfTest implements IWebsiteModule
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
$r = shell_exec('git status 2>&1');
|
||||
$ok = ($r !== null) && (strpos($r, 'Your branch is up to date with') !== false) && (strpos($r, 'nothing to commit, working tree clean') !== false);
|
||||
$r = Website::inst()->gitStatus();
|
||||
|
||||
if (!$ok)
|
||||
if (!$r)
|
||||
{
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_ERROR,
|
||||
'message' => "{$xname} failed",
|
||||
'message' => "{$xname} failed (command error)",
|
||||
'long' => $r,
|
||||
'exception' => null,
|
||||
];
|
||||
}
|
||||
else
|
||||
else if (!$r[2])
|
||||
{
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_ERROR,
|
||||
'message' => "{$xname} failed (git repo not clean)",
|
||||
'long' => $r,
|
||||
'exception' => null,
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_OK,
|
||||
'message' => "{".$xname."} succeeded",
|
||||
'message' => "{".$xname."} succeeded ('$r[0]' | '$r[1]')",
|
||||
'long' => $r,
|
||||
'exception' => null,
|
||||
];
|
||||
@@ -599,7 +608,8 @@ class SelfTest implements IWebsiteModule
|
||||
$url = $urlobj;
|
||||
if (is_array($urlobj)) $url = $urlobj['url'];
|
||||
|
||||
if ($url === 'direct') continue;
|
||||
if ($url === 'direct') continue;
|
||||
if ($urlname === 'homebrew-tap') continue;
|
||||
|
||||
$r = curl_http_request($url);
|
||||
$count++;
|
||||
|
||||
@@ -161,6 +161,40 @@ class Website
|
||||
return $this->config['prod'];
|
||||
}
|
||||
|
||||
public function gitStatus(): array|false {
|
||||
if (file_exists('/DOCKER_GIT_INFO'))
|
||||
{
|
||||
$dgi = preg_split("/\r\n|\n|\r/", file_get_contents('/DOCKER_GIT_INFO'));
|
||||
$branch = '';
|
||||
$sha = '';
|
||||
foreach ($dgi as $line)
|
||||
{
|
||||
$split = explode('=', $line, 2);
|
||||
if (count($split) !== 2) continue;
|
||||
|
||||
if ($split[0] === 'BRANCH') { $branch = $split[1]; continue; }
|
||||
if ($split[0] === 'HASH') { $sha = $split[1]; continue; }
|
||||
}
|
||||
|
||||
if ($branch !== '' && $sha !== '') return [$branch, $sha, true];
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = shell_exec('git status 2>&1');
|
||||
$branch = shell_exec('git rev-parse --abbrev-ref HEAD');
|
||||
$sha = shell_exec('git rev-parse HEAD');
|
||||
|
||||
if ($status === false || $status === null || $status === '') return false;
|
||||
if ($branch === false || $branch === null || $branch === '') return false;
|
||||
if ($sha === false || $sha === null || $sha === '') return false;
|
||||
|
||||
$clean = (str_contains($status, 'Your branch is up to date with')) && (str_contains($status, 'nothing to commit, working tree clean'));
|
||||
|
||||
return [$branch, $sha, $clean];
|
||||
}
|
||||
}
|
||||
|
||||
public function isLoggedInByCookie()
|
||||
{
|
||||
if ($this->isLoggedIn !== null) return $this->isLoggedIn;
|
||||
|
||||
Reference in New Issue
Block a user