1
0
Fork 0

DGI fixes
Build Docker and Deploy / Build Docker (push) Successful in 18s Details
Build Docker and Deploy / Deploy to Server (push) Successful in 16s Details

This commit is contained in:
Mike Schwörer 2023-09-12 17:43:01 +02:00
parent 8a22671f0b
commit f69a219927
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
5 changed files with 68 additions and 29 deletions

View File

@ -11,11 +11,14 @@ run:
dgi:
[ ! -f "DOCKER_GIT_INFO" ] || rm DOCKER_GIT_INFO
echo -n "VCSTYPE=" >> DOCKER_GIT_INFO ; { echo "git" ; } >> DOCKER_GIT_INFO
echo -n "BRANCH=" >> DOCKER_GIT_INFO ; { git rev-parse --abbrev-ref HEAD ; } >> DOCKER_GIT_INFO
echo -n "HASH=" >> DOCKER_GIT_INFO ; { git rev-parse HEAD ; } >> DOCKER_GIT_INFO
echo -n "COMMITTIME=" >> DOCKER_GIT_INFO ; { git log -1 --format=%cd --date=iso ; } >> DOCKER_GIT_INFO
echo -n "REMOTE=" >> DOCKER_GIT_INFO ; { git remote -v | awk '{print $$2}' | uniq | tr '\n' ';'; } >> DOCKER_GIT_INFO
echo -n "VCSTYPE=" >> DOCKER_GIT_INFO ; { echo -n "git" ; echo ""; } >> DOCKER_GIT_INFO
echo -n "BRANCH=" >> DOCKER_GIT_INFO ; { git rev-parse --abbrev-ref HEAD ; } >> DOCKER_GIT_INFO
echo -n "HASH=" >> DOCKER_GIT_INFO ; { git rev-parse HEAD ; } >> DOCKER_GIT_INFO
echo -n "COMMITTIME=" >> DOCKER_GIT_INFO ; { git log -1 --format=%cd --date=iso ; } >> DOCKER_GIT_INFO
echo -n "REMOTE=" >> DOCKER_GIT_INFO ; { git remote -v | awk '{print $$2}' | uniq | tr '\n' ';'; echo ""; } >> DOCKER_GIT_INFO
echo -n "MESSAGE=" >> DOCKER_GIT_INFO ; { git log -1 --format=%B | awk '{s=s $$0 "\n"}END{sub(/\n+$$/,"",s);printf "%s",s}' | base64 --wrap=0; echo ""; } >> DOCKER_GIT_INFO
docker: dgi
docker build \

View File

@ -8,14 +8,17 @@ require_once (__DIR__ . '/../internals/website.php');
if (!isset($API_OPTIONS['field'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
$info = $SITE->gitStatus();
function printInfo($v) { if ($v === false) throw new Exception('Failed to query field'); else echo $v; }
$field = strtolower($API_OPTIONS['field']);
if ($field === 'branch') { echo exec('git rev-parse --abbrev-ref HEAD'); return; }
if ($field === 'head') { echo exec('git rev-parse HEAD'); return; }
if ($field === 'timestamp') { echo (new DateTime(exec('git log -1 --format=%cd --date=iso')))->format('Y-m-d H:i:s'); return; }
if ($field === 'origin') { echo exec('git config --get remote.origin.url'); return; }
if ($field === 'message') { echo trim(shell_exec('git log -1 --format=%B')); return; }
if ($field === 'branch') { printInfo($info[0]); return; }
if ($field === 'head') { printInfo($info[1]); return; }
if ($field === 'timestamp') { printInfo($info[3]); return; }
if ($field === 'origin') { printInfo(str_replace(';', "\n", $info[4])); return; }
if ($field === 'message') { printInfo($info[5]); return; }
$FRAME_OPTIONS->statuscode = 400;
echo 'Unknown field';

View File

@ -546,7 +546,8 @@ class SelfTest implements IWebsiteModule
'exception' => null,
];
}
else if (!$r[2])
if (!$r[2])
{
return
[
@ -556,7 +557,18 @@ class SelfTest implements IWebsiteModule
'exception' => null,
];
}
else
if ($r[0] === false || $r[1] === false)
{
return
[
'result' => self::STATUS_ERROR,
'message' => "{$xname} failed (failed to query branch/sha)",
'long' => $r,
'exception' => null,
];
}
{
return
[

View File

@ -165,33 +165,50 @@ class Website
if (file_exists('/DOCKER_GIT_INFO'))
{
$dgi = preg_split("/\r\n|\n|\r/", file_get_contents('/DOCKER_GIT_INFO'));
$branch = '';
$sha = '';
$branch = false;
$sha = false;
$time = false;
$remote = false;
$message = false;
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 ($split[0] === 'BRANCH') { $branch = $split[1]; continue; }
if ($split[0] === 'HASH') { $sha = $split[1]; continue; }
if ($split[0] === 'COMMITTIME') { $time = $split[1]; continue; }
if ($split[0] === 'REMOTE') { $remote = $split[1]; continue; }
if ($split[0] === 'MESSAGE') { $message = base64_decode($split[1]); continue; }
}
if ($branch !== '' && $sha !== '') return [$branch, $sha, true];
return false;
if ($branch === '') $branch = false;
if ($sha === '') $sha = false;
if ($time === '') $time = false;
if ($remote === '') $remote = false;
if ($message === '') $message = false;
return [$branch, $sha, true, $time, $remote, $message];
}
else
{
$status = shell_exec('git status 2>&1');
$branch = shell_exec('git rev-parse --abbrev-ref HEAD');
$sha = shell_exec('git rev-parse HEAD');
$status = shell_exec('git status 2>&1');
$branch = shell_exec('git rev-parse --abbrev-ref HEAD');
$sha = shell_exec('git rev-parse HEAD');
$time = shell_exec('git log -1 --format=%cd --date=iso');
$remote = shell_exec("git remote -v | awk '{print \$2}' | uniq | tr '\\n' ';'");
$message = shell_exec("git log -1 --format=%B | awk '{s=s \$0 \"\\n\"}END{sub(/\\n+\$/,\"\",s);printf \"%s\",s}'");
if ($status === false || $status === null || $status === '') return false;
if ($branch === false || $branch === null || $branch === '') return false;
if ($sha === false || $sha === null || $sha === '') return false;
if ($status === false || $status === null || $status === '') $status = false;
if ($branch === false || $branch === null || $branch === '') $branch = false;
if ($sha === false || $sha === null || $sha === '') $sha = false;
if ($time === false || $time === null || $time === '') $time = false;
if ($remote === false || $remote === null || $remote === '') $remote = false;
if ($message === false || $message === null || $message === '') $message = 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];
return [$branch, $sha, $clean, $time, $remote, $message];
}
}

View File

@ -96,9 +96,13 @@ $connected = true; try { $SITE->modules->Database(); } catch (Exception $e) { $c
<div class="bc_header">Project Lawful ebook (download count)</div>
<div class="bc_data keyvaluelist kvl_250">
<?php foreach ($SITE->modules->ProjectLawful()->listDownloadCounts() as $dlc): ?>
<div><span><?php echo $dlc['variant']; ?>:</span> <span><?php echo $dlc['count']; ?></span></div>
<?php endforeach; ?>
<?php if ($connected): ?>
<?php foreach ($SITE->modules->ProjectLawful()->listDownloadCounts() as $dlc): ?>
<div><span><?php echo $dlc['variant']; ?>:</span> <span><?php echo $dlc['count']; ?></span></div>
<?php endforeach; ?>
<?php else: ?>
<div class="bc_data keyvaluelist admindberr">Database not connected.</div>
<?php endif; ?>
</div>
</div>