From 4af9434b29735f228f55bd5f9cbee2b4f2be193e Mon Sep 17 00:00:00 2001 From: andreas Date: Thu, 5 Oct 2023 19:37:46 +0200 Subject: [PATCH] ensure to load buildconfig from selected git sha --- webinstall/cibuild.js | 21 +++++++++++++++++---- webinstall/config.php | 4 ++-- webinstall/functions.php | 2 +- webinstall/install.php | 9 ++++++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/webinstall/cibuild.js b/webinstall/cibuild.js index c62b852..bf67b3b 100644 --- a/webinstall/cibuild.js +++ b/webinstall/cibuild.js @@ -226,7 +226,10 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12" downloadConfig: downloadConfig }; const loadConfig=async (url)=>{ - let config=await fetch(url).then((r)=>r.text()); + let config=await fetch(url).then((r)=>{ + if (!r.ok) throw new Error("unable to fetch: "+r.statusText); + return r.text() + }); let parsed=yamlLoad(config); return parsed; } @@ -423,9 +426,6 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12" fetchStatus(true); setRunning(true); } - structure=await loadConfig("build.yaml"); - buildSelectors(ROOT_PATH,structure.config.children,true); - if (! running) findPipeline(); let gitParam={user:GITUSER,repo:GITREPO}; let branch=getParam('branch'); if (branch){ @@ -479,6 +479,19 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12" else{ setValue('gitSha',gitSha); } + if (gitSha !== undefined){ + let url=buildUrl(GITAPI,Object.assign({},gitParam,{sha:gitSha,proxy:'webinstall/build.yaml'})); + try{ + structure=await loadConfig(url); + }catch (e){ + alert("unable to load config for selected release:\n "+e+"\n falling back to default"); + } + } + if (! structure){ + structure=await loadConfig("build.yaml"); + } + buildSelectors(ROOT_PATH,structure.config.children,true); + if (! running) findPipeline(); updateStart(); } })(); \ No newline at end of file diff --git a/webinstall/config.php b/webinstall/config.php index e63f800..2a7485b 100644 --- a/webinstall/config.php +++ b/webinstall/config.php @@ -15,12 +15,12 @@ function fillUserAndRepo($vars=null,$source=null){ } foreach (array('user','repo') as $n){ if (! isset($source[$n])){ - die("missing parameter $n"); + throw new Exception("missing parameter $n"); } $v=$source[$n]; $av=$allowed[$n]; if (! in_array($v,$av)){ - die("value $v for $n not allowed"); + throw new Exception("value $v for $n not allowed"); } $vars[$n]=$v; } diff --git a/webinstall/functions.php b/webinstall/functions.php index bb27108..c01888e 100644 --- a/webinstall/functions.php +++ b/webinstall/functions.php @@ -39,7 +39,7 @@ function addVars(&$vars,$names,$defaults=null){ foreach ($names as $n){ $v=null; if (! isset($_REQUEST[$n])){ - if ($defaults == null || ! isset($defaults[$n])) die("missing parameter $n"); + if ($defaults == null || ! isset($defaults[$n])) throw new Exception("missing parameter $n"); $v=$defaults[$n]; } else{ diff --git a/webinstall/install.php b/webinstall/install.php index c3fd6a8..d0dea66 100644 --- a/webinstall/install.php +++ b/webinstall/install.php @@ -7,6 +7,7 @@ $branchsha=API_BASE."/git/refs/heads/#branch#"; $tagsha=API_BASE."/git/refs/tags/#tag#"; $download = "https://github.com/#user#/#repo#/releases/download/#dlVersion#/#dlName#"; $manifest = "?dlName=#mName#&dlVersion=#mVersion#&user=#user#&repo=#repo#"; +$proxurl="https://raw.githubusercontent.com/#user#/#repo#/#sha#/#proxy#"; try { if (isset($_REQUEST['api'])) { $vars = fillUserAndRepo(); @@ -50,11 +51,17 @@ try { } } if (!$targetUrl) - die("unable to find $targetBase $mode\n"); + throw new Exception("unable to find $targetBase $mode\n"); #echo("download for $targetBase=$targetUrl\n"); proxy($targetUrl); exit(0); } + if (isset($_REQUEST['proxy'])){ + $vars = fillUserAndRepo(); + $vars = addVars($vars, array('sha', 'proxy')); + proxy(replaceVars($proxurl, $vars)); + exit(0); + } } catch (HTTPErrorException $h) { header($_SERVER['SERVER_PROTOCOL'] . " " . $h->code . " " . $h->getMessage()); die($h->getMessage());