first cycle lab release
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env node
|
||||
import { createInterface } from 'node:readline';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { deployOnHost } from '../platform/deployment.mjs';
|
||||
import { rollbackOnHost } from '../platform/rollback.mjs';
|
||||
const input=createInterface({input:process.stdin,terminal:false});
|
||||
const messages=input[Symbol.asyncIterator]();
|
||||
const send=value=>process.stdout.write('MCPACK:'+JSON.stringify(value)+'\n');
|
||||
try{
|
||||
const first=await messages.next();
|
||||
if(first.done)throw new Error('Missing deploy request');
|
||||
const request=JSON.parse(first.value);
|
||||
const repository=fileURLToPath(new URL('../',import.meta.url));
|
||||
const state=request.operation==='rollback' ? rollbackOnHost({...request,repository}) : await deployOnHost({...request,repository,receive:async stage=>{
|
||||
send({type:'ready',stage});
|
||||
const next=await messages.next();
|
||||
if(next.done)throw new Error('SSH upload/session interrupted');
|
||||
const message=JSON.parse(next.value);
|
||||
if(message.type!=='uploaded')throw new Error('Release transfer failed or aborted');
|
||||
}});
|
||||
send({type:'complete',state});
|
||||
}catch(error){send({type:'error',message:error.message});process.exitCode=1;}
|
||||
finally{input.close();}
|
||||
Reference in New Issue
Block a user