@r5n/gh-spawner
Advanced tools
Comparing version 0.0.0-rc.3 to 0.0.0-rc.5
#!/usr/bin/env bun | ||
// @bun | ||
import{parseArgs as y}from"util";import s from"picocolors";var l=[];async function c(){let{values:{directory:n,numberOfMachines:o,os:d,token:i,url:a,run:p,name:m,labels:f}}=y({allowPositionals:!0,args:Bun.argv,strict:!0,options:{destroy:{default:!1,type:"boolean",short:"D"},directory:{default:`${process.cwd()}/zosia`,type:"string",short:"d"},labels:{type:"string",short:"l"},name:{type:"string",default:"runner",short:"n"},numberOfMachines:{default:"1",type:"string",short:"m"},os:{default:"osx",type:"string",short:"o"},run:{default:!1,type:"boolean",short:"r"},token:{type:"string",short:"t"},url:{type:"string",short:"u"}}});if(!(i&&a))throw new Error("Token and URL are required");let h=Bun.spawnSync(["curl","-Ls","-o","/dev/null","-w","%{url_effective}","https://github.com/actions/runner/releases/latest"]),u=Bun.spawnSync(["basename",h.stdout.toString()]).stdout.toString().trim().replace("v",""),r=`actions-runner-${d}-x64-${u}.tar.gz`,$=`https://github.com/actions/runner/releases/download/v${u}/${r}`;if(Bun.spawnSync(["mkdir","-p",n],{stdout:"inherit"}),Bun.spawnSync(["mkdir","-p",`${n}/machines`],{stdout:"inherit"}),!await Bun.file(`${n}/${r}`).exists())Bun.spawnSync(["curl","-o",`${n}/${r}`,"-L",$],{stdout:"inherit"});for(let e=1;e<=Number(o);e++)Bun.spawnSync(["mkdir","-p",`${n}/machines/${e}`],{stdout:"inherit"}),Bun.spawnSync(["tar","xzf",r,"-C",`${n}/machines/${e}`],{cwd:n,stdout:"inherit"});if(p){for(let e=1;e<=Number(o);e++){let t=new Worker(new URL("./runner.ts",import.meta.url).href,{name:`[MACHINE ${e}]:`});t.addEventListener("open",()=>{console.info(`${s.bold(`[MACHINE ${e}]:`)} started...`),t.postMessage({machineCwd:`${n}/machines/${e}`,token:i,url:a,name:m,index:e,labels:f})}),t.addEventListener("message",({data:w})=>{console.info(`${s.bold(`[MACHINE ${e}]:`)} ${w}`)}),l.push(t)}console.info("Press Ctrl+C to stop all machines")}}process.on("SIGINT",()=>{for(let n of l)n.terminate(),console.info(`\n${s.bold(`[MACHINE ${n.name||""}]:`)} stopping...`);Bun.spawn(["rm","-rf"]),process.exit(0)});var[,,g]=Bun.argv;if(g==="destroy");else c(); | ||
import{parseArgs as d}from"util";import c from"picocolors";function o(e,s={}){return Bun.spawnSync(e,{stdio:["inherit","inherit","inherit"],...s})}var p=[];function g(){let{values:e}=d({allowPositionals:!0,args:Bun.argv,strict:!0,options:{directory:{default:`${process.cwd()}/gh-runners`,type:"string",short:"d"},labels:{type:"string",short:"l"},name:{type:"string",default:"runner",short:"n"},numberOfMachines:{default:"1",type:"string",short:"m"},os:{default:"osx",type:"string",short:"o"},overwrite:{default:!1,type:"boolean",short:"o"},run:{default:!1,type:"boolean",short:"r"},token:{type:"string",short:"t"},url:{type:"string",short:"u"}}});return e}async function h({directory:e,os:s}){let i=o(["curl","-Ls","-o","/dev/null","-w","%{url_effective}","https://github.com/actions/runner/releases/latest"],{stdio:["ignore","pipe","inherit"]}),r=o(["basename",i.stdout.toString()],{stdio:["ignore","pipe","inherit"]}).stdout.toString().trim().replace("v",""),n=`actions-runner-${s}-x64-${r}.tar.gz`,t=`https://github.com/actions/runner/releases/download/v${r}/${n}`;if(o(["mkdir","-p",e]),o(["mkdir","-p",`${e}/machines`]),!await Bun.file(`${e}/${n}`).exists())o(["curl","-o",`${e}/${n}`,"-L",t],{stdout:"inherit"});return n}async function w({overwrite:e,numberOfMachines:s,directory:i,runnerBase:u}){for(let r=1;r<=Number(s);r++){let n=`${i}/machines/${r}`;if(await Bun.file(n).exists())if(e)console.warn(`Machine ${r} already exists, removing...`),o(["rm","-rf",n]);else{console.warn(`Machine ${r} already exists, skipping...`);continue}o(["mkdir","-p",n]),o(["tar","xzf",u,"-C",n],{cwd:i}),o(["cp","-R",`${import.meta.require.resolve("@r5n/gh-spawner").replace("/cli.ts","")}/src/runner/.`,n])}}function b({directory:e,numberOfMachines:s,token:i,url:u,name:r,labels:n}){for(let t=1;t<=Number(s);t++){let a=new Worker(new URL("./runner-worker.ts",import.meta.url).href,{name:`[MACHINE ${t}]:`});a.addEventListener("open",()=>{console.info(`${c.bold(`[MACHINE ${t}]:`)} started...`),a.postMessage({machineCwd:`${e}/machines/${t}`,token:i,url:u,name:r,index:t,labels:n})}),a.addEventListener("message",({data:l})=>{console.info(`${c.bold(`[MACHINE ${t}]:`)} ${l}`)}),p.push(a)}console.info("Press Ctrl+C to stop all machines")}async function f(){let{overwrite:e,directory:s,numberOfMachines:i,os:u,token:r,url:n,run:t,name:a,labels:l}=g();if(!(r&&n))throw new Error("Token (-t) and URL (-u) parameters are required");let m=await h({directory:s,os:u});if(w({overwrite:e,numberOfMachines:i,directory:s,runnerBase:m}),!t)return console.info("Runners created but not started");b({directory:s,numberOfMachines:i,token:r,url:n,name:a,labels:l})}process.on("SIGINT",()=>{for(let e of p)e.terminate(),console.info(`\n${c.bold(`[MACHINE ${e.name||""}]:`)} stopping...`);o(["rm","-rf"]),process.exit(0)});var[,,$]=Bun.argv;if($==="destroy");else f(); |
@@ -11,3 +11,3 @@ { | ||
}, | ||
"files": ["dist"], | ||
"files": ["dist", "src/runner"], | ||
"homepage": "https://github.com/r5n-dev/ts-packages/tree/develop/packages/cli/gh-spawner", | ||
@@ -36,3 +36,3 @@ "license": "MIT", | ||
"types": "./cli.ts", | ||
"version": "0.0.0-rc.3" | ||
"version": "0.0.0-rc.5" | ||
} |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
4112
5
13
0