UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.59 kB
import{n as runCommandWithTimeout}from"../exec-runner-BiCq-T1F.mjs";import"../exec-c5tqm8tb.mjs";import{o as UPDATE_NETWORK_TIMEOUT_MS}from"../npm-install-env-Eij54zuY.mjs";import{t as collectGitRuntimeErrors}from"../update-git-runtime-Bysaru5h.mjs";import{a as runStep}from"../update-runner-command-pmKamyNm.mjs";import{t as runGitCandidatePreflight}from"../update-runner-git-preflight-M4xy8TmF.mjs";import path from"node:path";import fs from"node:fs/promises"; //!src/infra/update-immutable-build.worker.ts async function build(){if(process.geteuid?.()===0)throw new Error(`Immutable builds require a non-root build account.`);const[e,t,n,r=`0`,i,a]=process.argv.slice(2);if(!e||!i||!a||!/^[a-f0-9]{40}$/u.test(a)||!t||!/^[a-f0-9]{40}$/u.test(t))throw new Error(`Immutable builds require a private stage, exact SHA.`);const o=Number(n);const s=Number(r);if(!Number.isSafeInteger(o)||o<=0||!Number.isSafeInteger(s)||s<0)throw new Error(`Invalid immutable build command deadline.`);await fs.access(e,fs.constants.W_OK).catch(t=>{throw new Error(`Immutable build account cannot write private staging area ${e}.`,{cause:t})});const runCommand=(e,t)=>runCommandWithTimeout(e,{...t,killProcessTree:true});const c=[];const step=(e,t,n,r)=>({name:e,argv:t,cwd:n,env:r,runCommand,timeoutMs:o,stepIndex:0,totalSteps:0,results:c});const command=async(e,t,n,r=false)=>{for(let i=0;;i++){const a=await runStep({...step(e,t,n),timeoutMs:r?UPDATE_NETWORK_TIMEOUT_MS:o});if(a.exitCode===0&&(!a.termination||a.termination===`exit`))return;if(!r||i===1||a.termination===`signal`)throw new Error(`${e} failed: ${a.stderrTail??``}`);process.stderr.write(`${e} failed; retrying with retained local objects.\n`)}};const l=path.join(e,`source`);await command(`immutable-init`,[`git`,`init`,l],e);const u=path.join(l,`.git`,`objects`,`info`,`alternates`);await fs.writeFile(u,`${i}/.git/objects\n`);await command(`immutable-seed`,[`git`,`-C`,l,`update-ref`,`refs/remotes/origin/main`,a],l);await command(`immutable-origin`,[`git`,`-C`,l,`remote`,`add`,`origin`,`https://github.com/openclaw/openclaw.git`],l);await command(`immutable-fetch`,[`git`,`-C`,l,`fetch`,`--no-tags`,`origin`,`+refs/heads/main:refs/remotes/origin/main`],l,true);await command(`immutable-official-ancestry`,[`git`,`-C`,l,`merge-base`,`--is-ancestor`,t,`refs/remotes/origin/main`],l);await command(`immutable-dissociate`,[`git`,`-C`,l,`repack`,`-a`,`-d`],l);await fs.unlink(u);const d=await runGitCandidatePreflight({gitRoot:l,artifactRoot:e,targetRevision:t,refreshedRemotes:[`origin`],beforeRuntimeVerified:false,frozenLockfile:true,needsCheckoutMain:false,runCommand,timeoutMs:o,defaultCommandEnv:process.env,steps:c,step,workStep:step,workTimeoutMs:s||void 0,beforeCandidate:async e=>{if(e!==t)throw new Error(`Immutable preparation cannot fall back to another commit.`)},validateCandidate:async e=>{const n=await collectGitRuntimeErrors({root:e,sha:t});if(n.length)throw new Error(n.join(`; `))},prepareCandidate:async n=>{const r=path.join(e,`generation`);await command(`immutable-independent-git`,[`git`,`clone`,`--no-hardlinks`,`--no-checkout`,l,r],e);await command(`immutable-exact-checkout`,[`git`,`-C`,r,`checkout`,`--detach`,t],r);await fs.cp(n,r,{recursive:true,verbatimSymlinks:true,filter:e=>e!==path.join(n,`.git`)})}});if(d.status!==`ok`){const e=c.findLast(e=>e.exitCode!==0||e.termination&&e.termination!==`exit`);throw new Error(`${d.reason}${e?`: ${e.name}: ${e.stderrTail??``}`:``}`)}}build().catch(e=>{process.stderr.write(`${e instanceof Error?e.message:`Immutable build failed`}\n`);process.exitCode=1});export{};