From a285ca6ac056570d07575972d84960a478cabe83 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Mon, 2 Jan 2023 01:33:48 +0100 Subject: [PATCH] add sshCmdArgs option --- action.yml | 4 ++++ dist/index.js | 2 +- src/index.js | 4 ++-- src/inputs.js | 14 +++++++------- src/rsyncCli.js | 7 +++---- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index ca7935b..ff133c9 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,10 @@ inputs: description: "Arguments to pass to rsync" required: false default: "-rltgoDzvO" + SSH_CMD_ARGS: + description: "An array of ssh arguments, they must be prefixed with -o and separated by a comma, for example: -o SomeArgument=no, -o SomeOtherArgument=5 " + required: false + default: "-o StrictHostKeyChecking=no" EXCLUDE: description: "An array of folder to exclude" required: false diff --git a/dist/index.js b/dist/index.js index 738ec52..e3c1b2e 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -(()=>{var e={126:(e,t,r)=>{var s=r(147);var o;if(process.platform==="win32"||global.TESTING_WINDOWS){o=r(1)}else{o=r(728)}e.exports=isexe;isexe.sync=sync;function isexe(e,t,r){if(typeof t==="function"){r=t;t={}}if(!r){if(typeof Promise!=="function"){throw new TypeError("callback not provided")}return new Promise((function(r,s){isexe(e,t||{},(function(e,t){if(e){s(e)}else{r(t)}}))}))}o(e,t||{},(function(e,s){if(e){if(e.code==="EACCES"||t&&t.ignoreErrors){e=null;s=false}}r(e,s)}))}function sync(e,t){try{return o.sync(e,t||{})}catch(e){if(t&&t.ignoreErrors||e.code==="EACCES"){return false}else{throw e}}}},728:(e,t,r)=>{e.exports=isexe;isexe.sync=sync;var s=r(147);function isexe(e,t,r){s.stat(e,(function(e,s){r(e,e?false:checkStat(s,t))}))}function sync(e,t){return checkStat(s.statSync(e),t)}function checkStat(e,t){return e.isFile()&&checkMode(e,t)}function checkMode(e,t){var r=e.mode;var s=e.uid;var o=e.gid;var n=t.uid!==undefined?t.uid:process.getuid&&process.getuid();var c=t.gid!==undefined?t.gid:process.getgid&&process.getgid();var i=parseInt("100",8);var a=parseInt("010",8);var u=parseInt("001",8);var l=i|a;var f=r&u||r&a&&o===c||r&i&&s===n||r&l&&n===0;return f}},1:(e,t,r)=>{e.exports=isexe;isexe.sync=sync;var s=r(147);function checkPathExt(e,t){var r=t.pathExt!==undefined?t.pathExt:process.env.PATHEXT;if(!r){return true}r=r.split(";");if(r.indexOf("")!==-1){return true}for(var s=0;s{"use strict";var s=r(81).spawn;var o=r(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(t){var r=e[t];if(typeof r==="string"){e[t]=escapeSpaces(r)}else if(Array.isArray(r)===true){e[t]=r.map(escapeSpaces)}}));return e};e.exports=function(e,t){e=e||{};e=o._extend({},e);e=escapeSpacesInOptions(e);var r=e.platform||process.platform;var n=r==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(n&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&o.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,t){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&o.isArray(e.include)){e.include.forEach((function(e,t){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&o.isArray(e.exclude)){e.exclude.forEach((function(e,t){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&o.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var f=e.onStderr||noop;var d="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}d+=e+" "}));d=d.trim();if(e.noExec){t(null,null,null,d);return}try{var p="";var h="";var y;if(n){y=s("cmd.exe",["/s","/c",'"'+d+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{y=s("/bin/sh",["-c",d])}y.stdout.on("data",(function(e){l(e);p+=e}));y.stderr.on("data",(function(e){f(e);h+=e}));y.on("exit",(function(e){var r=null;if(e!==0){r=new Error("rsync exited with code "+e);r.code=e}t(r,p,h,d)}))}catch(e){t(e,null,null,d)}}},143:(e,t,r)=>{const s=r(126);const{join:o,delimiter:n,sep:c,posix:i}=r(17);const a=process.platform==="win32";const u=new RegExp(`[${i.sep}${c===i.sep?"":c}]`.replace(/(\\)/g,"\\$1"));const l=new RegExp(`^\\.${u.source}`);const getNotFoundError=e=>Object.assign(new Error(`not found: ${e}`),{code:"ENOENT"});const getPathInfo=(e,{path:t=process.env.PATH,pathExt:r=process.env.PATHEXT,delimiter:s=n})=>{const o=e.match(u)?[""]:[...a?[process.cwd()]:[],...(t||"").split(s)];if(a){const t=r||[".EXE",".CMD",".BAT",".COM"].join(s);const n=t.split(s);if(e.includes(".")&&n[0]!==""){n.unshift("")}return{pathEnv:o,pathExt:n,pathExtExe:t}}return{pathEnv:o,pathExt:[""]}};const getPathPart=(e,t)=>{const r=/^".*"$/.test(e)?e.slice(1,-1):e;const s=!r&&l.test(t)?t.slice(0,2):"";return s+o(r,t)};const which=async(e,t={})=>{const{pathEnv:r,pathExt:o,pathExtExe:n}=getPathInfo(e,t);const c=[];for(const i of r){const r=getPathPart(i,e);for(const e of o){const o=r+e;const i=await s(o,{pathExt:n,ignoreErrors:true});if(i){if(!t.all){return o}c.push(o)}}}if(t.all&&c.length){return c}if(t.nothrow){return null}throw getNotFoundError(e)};const whichSync=(e,t={})=>{const{pathEnv:r,pathExt:o,pathExtExe:n}=getPathInfo(e,t);const c=[];for(const i of r){const r=getPathPart(i,e);for(const e of o){const o=r+e;const i=s.sync(o,{pathExt:n,ignoreErrors:true});if(i){if(!t.all){return o}c.push(o)}}}if(t.all&&c.length){return c}if(t.nothrow){return null}throw getNotFoundError(e)};e.exports=which;which.sync=whichSync},505:(e,t,r)=>{const{existsSync:s,mkdirSync:o,writeFileSync:n}=r(147);const{join:c}=r(17);const validateDir=e=>{if(!e){console.log("[SSH] dir is not defined");return}if(s(e)){console.log(`[SSH] ${e} dir exist`);return}console.log(`[SSH] Creating ${e} dir in workspace root`);o(e);console.log("✅ [SSH] dir created.")};const writeToFile=({dir:e,filename:t,content:r,isRequired:o})=>{validateDir(e);const i=c(e,t);if(s(i)){console.log(`[FILE] ${i} file exist`);if(o){throw new Error(`⚠️ [FILE] ${i} Required file exist, aborting ...`)}return}try{n(i,r,{encoding:"utf8",mode:384})}catch(e){throw new Error(`⚠️[FILE] Writing to file error. filePath: ${i}, message: ${e.message}`)}};const validateRequiredInputs=e=>{const t=Object.keys(e);const r=t.filter((t=>{const r=e[t];if(!r){console.error(`⚠️ [INPUTS] ${t} is mandatory`)}return r}));if(r.length!==t.length){throw new Error("⚠️ [INPUTS] Inputs not valid, aborting ...")}};const snakeToCamel=e=>e.replace(/[^a-zA-Z0-9]+(.)/g,((e,t)=>t.toUpperCase()));e.exports={writeToFile:writeToFile,validateRequiredInputs:validateRequiredInputs,snakeToCamel:snakeToCamel}},229:(e,t,r)=>{const{snakeToCamel:s}=r(505);const o=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE","SCRIPT_BEFORE","SCRIPT_AFTER"];const n=process.env.GITHUB_WORKSPACE;const c=process.env.REMOTE_USER;const i={source:"",target:`/home/${c}/`,exclude:"",args:"-rltgoDzvO",deployKeyName:"deploy_key"};const a={githubWorkspace:n};o.forEach((e=>{const t=s(e.toLowerCase());const r=process.env[e]||process.env[`INPUT_${e}`];const o=r===undefined?i[t]:r;let c=o;switch(t){case"source":c=`${n}/${o}`;break;case"exclude":c=o.split(",").map((e=>e.trim()));break;case"args":c=[o];break}a[t]=c}));a.sshServer=`${a.remoteUser}@${a.remoteHost}:${a.target}`;e.exports=a},976:(e,t,r)=>{const{exec:s}=r(81);const{sshServer:o,githubWorkspace:n}=r(229);const{writeToFile:c}=r(505);const remoteCmd=(e,t)=>{const r=`local_ssh_script-${t}.sh`;try{c({dir:n,filename:r,content:e});s(`ssh ${o} 'bash -s' < ${r}`,((e,t,r)=>{if(e){console.log("⚠️ [CMD] Remote script failed. ",e.message)}else{console.log("✅ [CMD] Remote script executed. \n",t,r)}}))}catch(e){console.log("⚠️ [CMD] Starting Remote script execution failed. ",e.message)}};e.exports={remoteCmdBefore:e=>remoteCmd(e,"before"),remoteCmdAfter:e=>remoteCmd(e,"after")}},447:(e,t,r)=>{const{execSync:s}=r(81);const o=r(143);const n=r(898);const validateRsync=()=>new Promise((async(e,t)=>{const r=await o("rsync",{nothrow:true});s("rsync --version",{stdio:"inherit"});if(r){console.log("⚠️ [CLI] Rsync exists");s("rsync --version",{stdio:"inherit"});e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');try{s("sudo apt-get update && sudo apt-get --no-install-recommends install rsync",{stdio:"inherit"});console.log("✅ [CLI] Rsync installed. \n");e()}catch(e){t(Error(`⚠️ [CLI] Rsync installation failed. Aborting ... error: ${e.message}`))}}));const rsyncCli=({source:e,sshServer:t,exclude:r,remotePort:s,privateKey:o,args:c,callback:i})=>{console.log(`[Rsync] Starting Rsync Action: ${e} to ${t}`);if(r)console.log(`[Rsync] excluding folders ${r}`);const a={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};try{n({src:e,dest:t,excludeFirst:r,port:s,privateKey:o,args:c,...a},((e,t,r,s)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",r);console.log("⚠️ [Rsync] stdout: ",t);console.log("⚠️ [Rsync] cmd: ",s)}else{console.log("✅ [Rsync] finished.",t)}i(e,t,r,s);if(e){process.abort()}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const sshDeploy=e=>{validateRsync.then((()=>{rsyncCli(e)})).catch((e=>{throw e}))};e.exports={sshDeploy:sshDeploy}},822:(e,t,r)=>{const{join:s}=r(17);const{writeToFile:o}=r(505);const addSshKey=(e,t)=>{const{HOME:r}=process.env;const n=s(r||__dirname,".ssh");const c=s(n,t);o({dir:n,filename:"known_hosts",content:""});console.log("✅ [SSH] known_hosts file ensured",n,t,e);o({dir:n,filename:t,content:e,isRequired:true});console.log("✅ [SSH] key added to `.ssh` dir ",n);return c};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var t={};function __nccwpck_require__(r){var s=t[r];if(s!==undefined){return s.exports}var o=t[r]={exports:{}};var n=true;try{e[r](o,o.exports,__nccwpck_require__);n=false}finally{if(n)delete t[r]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var r={};(()=>{const{sshDeploy:e}=__nccwpck_require__(447);const{remoteCmdBefore:t,remoteCmdAfter:r}=__nccwpck_require__(976);const{addSshKey:s}=__nccwpck_require__(822);const{validateRequiredInputs:o}=__nccwpck_require__(505);const n=__nccwpck_require__(229);const run=()=>{const{source:c,remoteUser:i,remoteHost:a,remotePort:u,deployKeyName:l,sshPrivateKey:f,args:d,exclude:p,scriptBefore:h,scriptAfter:y,sshServer:g}=n;o({sshPrivateKey:f,remoteHost:a,remoteUser:i});const x=s(f,l);if(h){t(h)}let callback=()=>{};if(y){callback=(...e)=>{r(y,e)}}e({source:c,sshServer:g,exclude:p,remotePort:u,privateKey:x,args:d,callback:callback})};run()})();module.exports=r})(); \ No newline at end of file +(()=>{var e={126:(e,r,t)=>{var s=t(147);var o;if(process.platform==="win32"||global.TESTING_WINDOWS){o=t(1)}else{o=t(728)}e.exports=isexe;isexe.sync=sync;function isexe(e,r,t){if(typeof r==="function"){t=r;r={}}if(!t){if(typeof Promise!=="function"){throw new TypeError("callback not provided")}return new Promise((function(t,s){isexe(e,r||{},(function(e,r){if(e){s(e)}else{t(r)}}))}))}o(e,r||{},(function(e,s){if(e){if(e.code==="EACCES"||r&&r.ignoreErrors){e=null;s=false}}t(e,s)}))}function sync(e,r){try{return o.sync(e,r||{})}catch(e){if(r&&r.ignoreErrors||e.code==="EACCES"){return false}else{throw e}}}},728:(e,r,t)=>{e.exports=isexe;isexe.sync=sync;var s=t(147);function isexe(e,r,t){s.stat(e,(function(e,s){t(e,e?false:checkStat(s,r))}))}function sync(e,r){return checkStat(s.statSync(e),r)}function checkStat(e,r){return e.isFile()&&checkMode(e,r)}function checkMode(e,r){var t=e.mode;var s=e.uid;var o=e.gid;var n=r.uid!==undefined?r.uid:process.getuid&&process.getuid();var c=r.gid!==undefined?r.gid:process.getgid&&process.getgid();var i=parseInt("100",8);var a=parseInt("010",8);var u=parseInt("001",8);var l=i|a;var d=t&u||t&a&&o===c||t&i&&s===n||t&l&&n===0;return d}},1:(e,r,t)=>{e.exports=isexe;isexe.sync=sync;var s=t(147);function checkPathExt(e,r){var t=r.pathExt!==undefined?r.pathExt:process.env.PATHEXT;if(!t){return true}t=t.split(";");if(t.indexOf("")!==-1){return true}for(var s=0;s{"use strict";var s=t(81).spawn;var o=t(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var t=e[r];if(typeof t==="string"){e[r]=escapeSpaces(t)}else if(Array.isArray(t)===true){e[r]=t.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=o._extend({},e);e=escapeSpacesInOptions(e);var t=e.platform||process.platform;var n=t==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var c=e.dest;if(typeof e.host!=="undefined"){c=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var i=[].concat(e.src);i.push(c);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(n&&!a){i.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){i.push("--rsh");var u="ssh";if(typeof e.port!=="undefined"){u+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){u+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){u+=" "+e.sshCmdArgs.join(" ")}i.push(u)}if(e.recursive===true){i.push("--recursive")}if(e.times===true){i.push("--times")}if(e.syncDest===true||e.deleteAll===true){i.push("--delete");i.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){i.push("--delete")}if(e.dryRun===true){i.push("--dry-run");i.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&o.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&o.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&o.isArray(e.exclude)){e.exclude.forEach((function(e,r){i.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":i.push("--size-only");break;case"checksum":i.push("--checksum");break}if(typeof e.args!=="undefined"&&o.isArray(e.args)){i=[...new Set([...i,...e.args])]}i=[...new Set(i)];var noop=function(){};var l=e.onStdout||noop;var d=e.onStderr||noop;var f="rsync ";i.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var h="";var y;if(n){y=s("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{y=s("/bin/sh",["-c",f])}y.stdout.on("data",(function(e){l(e);p+=e}));y.stderr.on("data",(function(e){d(e);h+=e}));y.on("exit",(function(e){var t=null;if(e!==0){t=new Error("rsync exited with code "+e);t.code=e}r(t,p,h,f)}))}catch(e){r(e,null,null,f)}}},143:(e,r,t)=>{const s=t(126);const{join:o,delimiter:n,sep:c,posix:i}=t(17);const a=process.platform==="win32";const u=new RegExp(`[${i.sep}${c===i.sep?"":c}]`.replace(/(\\)/g,"\\$1"));const l=new RegExp(`^\\.${u.source}`);const getNotFoundError=e=>Object.assign(new Error(`not found: ${e}`),{code:"ENOENT"});const getPathInfo=(e,{path:r=process.env.PATH,pathExt:t=process.env.PATHEXT,delimiter:s=n})=>{const o=e.match(u)?[""]:[...a?[process.cwd()]:[],...(r||"").split(s)];if(a){const r=t||[".EXE",".CMD",".BAT",".COM"].join(s);const n=r.split(s);if(e.includes(".")&&n[0]!==""){n.unshift("")}return{pathEnv:o,pathExt:n,pathExtExe:r}}return{pathEnv:o,pathExt:[""]}};const getPathPart=(e,r)=>{const t=/^".*"$/.test(e)?e.slice(1,-1):e;const s=!t&&l.test(r)?r.slice(0,2):"";return s+o(t,r)};const which=async(e,r={})=>{const{pathEnv:t,pathExt:o,pathExtExe:n}=getPathInfo(e,r);const c=[];for(const i of t){const t=getPathPart(i,e);for(const e of o){const o=t+e;const i=await s(o,{pathExt:n,ignoreErrors:true});if(i){if(!r.all){return o}c.push(o)}}}if(r.all&&c.length){return c}if(r.nothrow){return null}throw getNotFoundError(e)};const whichSync=(e,r={})=>{const{pathEnv:t,pathExt:o,pathExtExe:n}=getPathInfo(e,r);const c=[];for(const i of t){const t=getPathPart(i,e);for(const e of o){const o=t+e;const i=s.sync(o,{pathExt:n,ignoreErrors:true});if(i){if(!r.all){return o}c.push(o)}}}if(r.all&&c.length){return c}if(r.nothrow){return null}throw getNotFoundError(e)};e.exports=which;which.sync=whichSync},505:(e,r,t)=>{const{existsSync:s,mkdirSync:o,writeFileSync:n}=t(147);const{join:c}=t(17);const validateDir=e=>{if(!e){console.log("[SSH] dir is not defined");return}if(s(e)){console.log(`[SSH] ${e} dir exist`);return}console.log(`[SSH] Creating ${e} dir in workspace root`);o(e);console.log("✅ [SSH] dir created.")};const writeToFile=({dir:e,filename:r,content:t,isRequired:o})=>{validateDir(e);const i=c(e,r);if(s(i)){console.log(`[FILE] ${i} file exist`);if(o){throw new Error(`⚠️ [FILE] ${i} Required file exist, aborting ...`)}return}try{n(i,t,{encoding:"utf8",mode:384})}catch(e){throw new Error(`⚠️[FILE] Writing to file error. filePath: ${i}, message: ${e.message}`)}};const validateRequiredInputs=e=>{const r=Object.keys(e);const t=r.filter((r=>{const t=e[r];if(!t){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return t}));if(t.length!==r.length){throw new Error("⚠️ [INPUTS] Inputs not valid, aborting ...")}};const snakeToCamel=e=>e.replace(/[^a-zA-Z0-9]+(.)/g,((e,r)=>r.toUpperCase()));e.exports={writeToFile:writeToFile,validateRequiredInputs:validateRequiredInputs,snakeToCamel:snakeToCamel}},229:(e,r,t)=>{const{snakeToCamel:s}=t(505);const o=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","SSH_CMD_ARGS","EXCLUDE","SCRIPT_BEFORE","SCRIPT_AFTER"];const n=process.env.GITHUB_WORKSPACE;const c=process.env.REMOTE_USER;const i={source:"",target:`/home/${c}/`,exclude:"",args:"-rltgoDzvO",sshCmdArgs:"-o StrictHostKeyChecking=no",deployKeyName:"deploy_key"};const a={githubWorkspace:n};o.forEach((e=>{const r=s(e.toLowerCase());const t=process.env[e]||process.env[`INPUT_${e}`];const o=t===undefined?i[r]:t;let c=o;switch(r){case"source":c=`${n}/${o}`;break;case"exclude":case"args":case"sshCmdArgs":c=o.split(",").map((e=>e.trim()));break}a[r]=c}));a.sshServer=`${a.remoteUser}@${a.remoteHost}:${a.target}`;e.exports=a},976:(e,r,t)=>{const{exec:s}=t(81);const{sshServer:o,githubWorkspace:n}=t(229);const{writeToFile:c}=t(505);const remoteCmd=(e,r)=>{const t=`local_ssh_script-${r}.sh`;try{c({dir:n,filename:t,content:e});s(`ssh ${o} 'bash -s' < ${t}`,((e,r,t)=>{if(e){console.log("⚠️ [CMD] Remote script failed. ",e.message)}else{console.log("✅ [CMD] Remote script executed. \n",r,t)}}))}catch(e){console.log("⚠️ [CMD] Starting Remote script execution failed. ",e.message)}};e.exports={remoteCmdBefore:e=>remoteCmd(e,"before"),remoteCmdAfter:e=>remoteCmd(e,"after")}},447:(e,r,t)=>{const{execSync:s}=t(81);const o=t(143);const n=t(898);const validateRsync=()=>new Promise((async(e,r)=>{const t=await o("rsync",{nothrow:true});s("rsync --version",{stdio:"inherit"});if(t){console.log("⚠️ [CLI] Rsync exists");s("rsync --version",{stdio:"inherit"});e()}console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');try{s("sudo apt-get update && sudo apt-get --no-install-recommends install rsync",{stdio:"inherit"});console.log("✅ [CLI] Rsync installed. \n");e()}catch(e){r(Error(`⚠️ [CLI] Rsync installation failed. Aborting ... error: ${e.message}`))}}));const rsyncCli=({source:e,sshServer:r,exclude:t,remotePort:s,privateKey:o,args:c,sshCmdArgs:i,callback:a})=>{console.log(`[Rsync] Starting Rsync Action: ${e} to ${r}`);if(t)console.log(`[Rsync] excluding folders ${t}`);const u={ssh:true,recursive:true};try{n({...u,src:e,dest:r,excludeFirst:t,port:s,privateKey:o,args:c,sshCmdArgs:i},((e,r,t,s)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",t);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",s)}else{console.log("✅ [Rsync] finished.",r)}a(e,r,t,s);if(e){process.abort()}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const sshDeploy=e=>{validateRsync.then((()=>{rsyncCli(e)})).catch((e=>{throw e}))};e.exports={sshDeploy:sshDeploy}},822:(e,r,t)=>{const{join:s}=t(17);const{writeToFile:o}=t(505);const addSshKey=(e,r)=>{const{HOME:t}=process.env;const n=s(t||__dirname,".ssh");const c=s(n,r);o({dir:n,filename:"known_hosts",content:""});console.log("✅ [SSH] known_hosts file ensured",n,r,e);o({dir:n,filename:r,content:e,isRequired:true});console.log("✅ [SSH] key added to `.ssh` dir ",n);return c};e.exports={addSshKey:addSshKey}},81:e=>{"use strict";e.exports=require("child_process")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(t){var s=r[t];if(s!==undefined){return s.exports}var o=r[t]={exports:{}};var n=true;try{e[t](o,o.exports,__nccwpck_require__);n=false}finally{if(n)delete r[t]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t={};(()=>{const{sshDeploy:e}=__nccwpck_require__(447);const{remoteCmdBefore:r,remoteCmdAfter:t}=__nccwpck_require__(976);const{addSshKey:s}=__nccwpck_require__(822);const{validateRequiredInputs:o}=__nccwpck_require__(505);const n=__nccwpck_require__(229);const run=()=>{const{source:c,remoteUser:i,remoteHost:a,remotePort:u,deployKeyName:l,sshPrivateKey:d,args:f,exclude:p,sshCmdArgs:h,scriptBefore:y,scriptAfter:g,sshServer:m}=n;o({sshPrivateKey:d,remoteHost:a,remoteUser:i});const x=s(d,l);if(y){r(y)}let callback=()=>{};if(g){callback=(...e)=>{t(g,e)}}e({source:c,sshServer:m,exclude:p,remotePort:u,privateKey:x,args:f,sshCmdArgs:h,callback:callback})};run()})();module.exports=t})(); \ No newline at end of file diff --git a/src/index.js b/src/index.js index 1cd13c4..afd09cc 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,7 @@ const run = () => { const { source, remoteUser, remoteHost, remotePort, deployKeyName, sshPrivateKey, - args, exclude, + args, exclude, sshCmdArgs, scriptBefore, scriptAfter, sshServer } = inputs; @@ -31,7 +31,7 @@ const run = () => { /* eslint-disable object-property-newline */ sshDeploy({ source, sshServer, exclude, remotePort, - privateKey, args, callback + privateKey, args, sshCmdArgs, callback }); }; diff --git a/src/inputs.js b/src/inputs.js index 54460a1..6eb970c 100644 --- a/src/inputs.js +++ b/src/inputs.js @@ -3,17 +3,18 @@ const { snakeToCamel } = require('./helpers'); const inputNames = [ 'REMOTE_HOST', 'REMOTE_USER', 'REMOTE_PORT', 'SSH_PRIVATE_KEY', 'DEPLOY_KEY_NAME', - 'SOURCE', 'TARGET', 'ARGS', 'EXCLUDE', + 'SOURCE', 'TARGET', 'ARGS', 'SSH_CMD_ARGS', 'EXCLUDE', 'SCRIPT_BEFORE', 'SCRIPT_AFTER']; const githubWorkspace = process.env.GITHUB_WORKSPACE; const remoteUser = process.env.REMOTE_USER; const defaultInputs = { - source: '', // TODO + source: '', target: `/home/${remoteUser}/`, - exclude: '', // TODO - args: '-rltgoDzvO', // TODO + exclude: '', + args: '-rltgoDzvO', + sshCmdArgs: '-o StrictHostKeyChecking=no', deployKeyName: 'deploy_key' }; @@ -32,10 +33,9 @@ inputNames.forEach((input) => { extendedVal = `${githubWorkspace}/${validVal}`; break; case 'exclude': - extendedVal = validVal.split(',').map((item) => item.trim()); - break; case 'args': - extendedVal = [validVal]; + case 'sshCmdArgs': + extendedVal = validVal.split(',').map((item) => item.trim()); break; } diff --git a/src/rsyncCli.js b/src/rsyncCli.js index f167dd0..d08dc96 100644 --- a/src/rsyncCli.js +++ b/src/rsyncCli.js @@ -25,14 +25,13 @@ const validateRsync = () => new Promise(async (resolve, reject) => { const rsyncCli = ({ source, sshServer, exclude, remotePort, - privateKey, args, callback + privateKey, args, sshCmdArgs, callback }) => { console.log(`[Rsync] Starting Rsync Action: ${source} to ${sshServer}`); if (exclude) console.log(`[Rsync] excluding folders ${exclude}`); const defaultOptions = { ssh: true, - sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }; @@ -40,9 +39,9 @@ const rsyncCli = ({ // RSYNC COMMAND /* eslint-disable object-property-newline */ nodeRsync({ + ...defaultOptions, src: source, dest: sshServer, excludeFirst: exclude, port: remotePort, - privateKey, args, - ...defaultOptions + privateKey, args, sshCmdArgs, }, (error, stdout, stderr, cmd) => { if (error) { console.error('⚠️ [Rsync] error: ', error.message);