correctly set tag filter for jobs, compute git sha before starting a job

This commit is contained in:
andreas 2023-10-02 20:31:29 +02:00
parent 9ddcbdc34a
commit faa946c8dc
5 changed files with 87 additions and 8 deletions

View File

@ -1,10 +1,6 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/configuration-reference
version: 2.1
# set the filter to allow a build for any sha tag
filters:
tags:
only: /.*/
parameters:
run_build:
type: boolean
@ -76,3 +72,7 @@ workflows:
when: << pipeline.parameters.run_build >>
jobs:
- pio-build
# set the filter to allow a build for any sha tag
filters:
tags:
only: /.*/

View File

@ -10,6 +10,14 @@
<div class="configui container">
<h1>Build your own ESP32-NMEA2000</h1>
<h3>New Build</h3>
<div class="row">
<span class="label" id="branchOrTag"></span>
<span class="value" id="branchOrTagValue">---</span>
</div>
<div class="row">
<span class="label" >GitSha</span>
<span class="value" id="gitSha">---</span>
</div>
<div class="row">
<button id="downloadConfig">SaveCfg</button>
<button id="uploadConfig">LoadCfg</button>

View File

@ -4,7 +4,10 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
(function(){
const STATUS_INTERVAL=2000;
const CURRENT_PIPELINE='pipeline';
let API="cibuild.php";
const API="cibuild.php";
const GITAPI="install.php";
const GITUSER="wellenvogel";
const GITREPO="esp32-nmea2000";
let currentPipeline=undefined;
let downloadUrl=undefined;
let timer=undefined;
@ -15,6 +18,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
let displayMode='last';
let delayedSearch=undefined;
let running=false;
let gitSha=undefined;
if (! branch) branch='master';
const modeStrings={
last: 'Last Build',
@ -123,6 +127,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
setValue('status','requested');
setValue('pipeline','');
setRunning(true);
if (gitSha !== undefined) param.tag=gitSha;
param.config=JSON.stringify(config);
fetchJson(API,Object.assign({
api:'start'},param))
@ -324,6 +329,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
}
let param={find:1};
fillValues(param,['environment','buildflags']);
if (gitSha !== undefined) param.tag=gitSha;
fetchJson(API,param)
.then((res)=>{
setCurrentPipeline(res.pipeline);
@ -347,6 +353,56 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
}
structure=await loadConfig("build.yaml");
buildSelectors(ROOT_PATH,structure.config.children,true);
//buildValues();
let gitParam={user:GITUSER,repo:GITREPO};
let branch=getParam('branch');
if (branch){
try{
let info=await fetchJson(GITAPI,Object.assign({},gitParam,{branch:branch}));
if (info.object){
gitSha=info.object.sha;
setValue('branchOrTag','branch');
setValue('branchOrTagValue',branch);
}
}catch (e){
console.log("branch query error",e);
}
}
if (gitSha === undefined) {
let tag = getParam('tag');
if (!tag) {
try {
let relinfo = await fetchJson(GITAPI, Object.assign({}, gitParam, { api: 1 }));
if (relinfo.tag_name) {
tag = relinfo.tag_name;
}
else {
alert("unable to query latest release");
}
} catch (e) {
alert("unable to query release info " + e);
}
}
if (tag){
try{
let info=await fetchJson(GITAPI,Object.assign({},gitParam,{tag:tag}));
if (info.object){
gitSha=info.object.sha;
setValue('branchOrTag','tag');
setValue('branchOrTagValue',tag);
}
}catch(e){
alert("cannot get sha for tag "+tag+": "+e);
}
}
}
if (gitSha === undefined){
//last resort: no sha, let the CI pick up latest
setValue('gitSha','unknown');
setValue('branchOrTag','branch');
setValue('branchOrTagValue','master');
}
else{
setValue('gitSha',gitSha);
}
}
})();

View File

@ -57,7 +57,7 @@ const fillValues=(values,items)=>{
const setValue=(id,value)=>{
let el=document.getElementById(id);
if (! el) return;
if (el.tagName == 'DIV'){
if (el.tagName == 'DIV' || el.tagName == 'SPAN' || el.tagName == 'P'){
el.textContent=value;
return;
}

View File

@ -1,7 +1,10 @@
<?php
include("functions.php");
include("config.php");
$api = "https://api.github.com/repos/#user#/#repo#/releases/latest";
const API_BASE="https://api.github.com/repos/#user#/#repo#";
$api = API_BASE."/releases/latest";
$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#";
try {
@ -10,6 +13,18 @@ try {
proxy(replaceVars($api, $vars));
exit(0);
}
if (isset($_REQUEST['branch'])){
$vars = fillUserAndRepo();
$vars = addVars($vars, array('branch'));
proxy(replaceVars($branchsha, $vars));
exit(0);
}
if (isset($_REQUEST['tag'])){
$vars = fillUserAndRepo();
$vars = addVars($vars, array('tag'));
proxy(replaceVars($tagsha, $vars));
exit(0);
}
if (isset($_REQUEST['dlName'])) {
$vars = fillUserAndRepo();
$vars = addVars($vars, array('dlName', 'dlVersion'));