diff --git a/.releaserc b/.releaserc index 11794b9..806b273 100644 --- a/.releaserc +++ b/.releaserc @@ -9,9 +9,7 @@ "changelogFile": "docs/CHANGELOG.md" } ], - ["@semantic-release/npm", { - "npmPublish": false - }], + "@semantic-release/npm", [ "@semantic-release/git", { diff --git a/dist/index.js b/dist/index.js index 698eb01..25fbd55 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,746 +1,2 @@ #!/usr/bin/env node -/******/ (() => { // webpackBootstrap -/******/ var __webpack_modules__ = ({ - -/***/ 569: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -module.exports = __nccwpck_require__(325); - - -/***/ }), - -/***/ 325: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -"use strict"; - - -var exec = __nccwpck_require__(129).exec; -var execSync = __nccwpck_require__(129).execSync; -var fs = __nccwpck_require__(747); -var path = __nccwpck_require__(622); -var access = fs.access; -var accessSync = fs.accessSync; -var constants = fs.constants || fs; - -var isUsingWindows = process.platform == 'win32' - -var fileNotExists = function(commandName, callback){ - access(commandName, constants.F_OK, - function(err){ - callback(!err); - }); -}; - -var fileNotExistsSync = function(commandName){ - try{ - accessSync(commandName, constants.F_OK); - return false; - }catch(e){ - return true; - } -}; - -var localExecutable = function(commandName, callback){ - access(commandName, constants.F_OK | constants.X_OK, - function(err){ - callback(null, !err); - }); -}; - -var localExecutableSync = function(commandName){ - try{ - accessSync(commandName, constants.F_OK | constants.X_OK); - return true; - }catch(e){ - return false; - } -} - -var commandExistsUnix = function(commandName, cleanedCommandName, callback) { - - fileNotExists(commandName, function(isFile){ - - if(!isFile){ - var child = exec('command -v ' + cleanedCommandName + - ' 2>/dev/null' + - ' && { echo >&1 ' + cleanedCommandName + '; exit 0; }', - function (error, stdout, stderr) { - callback(null, !!stdout); - }); - return; - } - - localExecutable(commandName, callback); - }); - -} - -var commandExistsWindows = function(commandName, cleanedCommandName, callback) { - // Regex from Julio from: https://stackoverflow.com/questions/51494579/regex-windows-path-validator - if (!(/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName))) { - callback(null, false); - return; - } - var child = exec('where ' + cleanedCommandName, - function (error) { - if (error !== null){ - callback(null, false); - } else { - callback(null, true); - } - } - ) -} - -var commandExistsUnixSync = function(commandName, cleanedCommandName) { - if(fileNotExistsSync(commandName)){ - try { - var stdout = execSync('command -v ' + cleanedCommandName + - ' 2>/dev/null' + - ' && { echo >&1 ' + cleanedCommandName + '; exit 0; }' - ); - return !!stdout; - } catch (error) { - return false; - } - } - return localExecutableSync(commandName); -} - -var commandExistsWindowsSync = function(commandName, cleanedCommandName, callback) { - // Regex from Julio from: https://stackoverflow.com/questions/51494579/regex-windows-path-validator - if (!(/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName))) { - return false; - } - try { - var stdout = execSync('where ' + cleanedCommandName, {stdio: []}); - return !!stdout; - } catch (error) { - return false; - } -} - -var cleanInput = function(s) { - if (/[^A-Za-z0-9_\/:=-]/.test(s)) { - s = "'"+s.replace(/'/g,"'\\''")+"'"; - s = s.replace(/^(?:'')+/g, '') // unduplicate single-quote at the beginning - .replace(/\\'''/g, "\\'" ); // remove non-escaped single-quote if there are enclosed between 2 escaped - } - return s; -} - -if (isUsingWindows) { - cleanInput = function(s) { - var isPathName = /[\\]/.test(s); - if (isPathName) { - var dirname = '"' + path.dirname(s) + '"'; - var basename = '"' + path.basename(s) + '"'; - return dirname + ':' + basename; - } - return '"' + s + '"'; - } -} - -module.exports = function commandExists(commandName, callback) { - var cleanedCommandName = cleanInput(commandName); - if (!callback && typeof Promise !== 'undefined') { - return new Promise(function(resolve, reject){ - commandExists(commandName, function(error, output) { - if (output) { - resolve(commandName); - } else { - reject(error); - } - }); - }); - } - if (isUsingWindows) { - commandExistsWindows(commandName, cleanedCommandName, callback); - } else { - commandExistsUnix(commandName, cleanedCommandName, callback); - } -}; - -module.exports.sync = function(commandName) { - var cleanedCommandName = cleanInput(commandName); - if (isUsingWindows) { - return commandExistsWindowsSync(commandName, cleanedCommandName); - } else { - return commandExistsUnixSync(commandName, cleanedCommandName); - } -}; - - -/***/ }), - -/***/ 748: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const { exec, execSync } = __nccwpck_require__(129); - -const commandline={ - run:runCommand, - runSync:runSync, - //will be deprecated soon as run is now the same. - get:runCommand, - -}; - -function runCommand(command,callback){ - - return exec( - command, - ( - function(){ - return function(err,data,stderr){ - if(!callback) - return; - - callback(err, data, stderr); - } - } - )(callback) - ); -} - -function runSync(command){ - try { - return { - data: execSync(command).toString(), - err: null, - stderr: null - } - } - catch (error) { - return { - data: null, - err: error.stderr.toString(), - stderr: error.stderr.toString() - } - } -} - -module.exports=commandline; - - -/***/ }), - -/***/ 898: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -"use strict"; - - -var spawn = __nccwpck_require__(129).spawn -var util = __nccwpck_require__(669) - -var escapeSpaces = function(path) { - if (typeof path === 'string') { - return path.replace(/\b\s/g, '\\ ') - } else { - return path - } -} - -var escapeSpacesInOptions = function(options) { - // Escape paths in the src, dest, include, exclude, and excludeFirst arguments - ;['src', 'dest', 'include', 'exclude', 'excludeFirst'].forEach(function( - optionKey - ) { - var option = options[optionKey] - if (typeof option === 'string') { - options[optionKey] = escapeSpaces(option) - } else if (Array.isArray(option) === true) { - options[optionKey] = option.map(escapeSpaces) - } - }) - - return options -} - -module.exports = function(options, callback) { - options = options || {} - options = util._extend({}, options) - options = escapeSpacesInOptions(options) - - var platform = options.platform || process.platform // Enable process.platform to be mocked in options for testing - var isWin = platform === 'win32' - - if (typeof options.src === 'undefined') { - throw new Error("'src' directory is missing from options") - } - - if (typeof options.dest === 'undefined') { - throw new Error("'dest' directory is missing from options") - } - - var dest = options.dest - - if (typeof options.host !== 'undefined') { - dest = options.host + ':' + options.dest - } - - if (!Array.isArray(options.src)) { - options.src = [options.src] - } - - var args = [].concat(options.src) - - args.push(dest) - - // [rsync failed on windows, copying persmissions](https://github.com/jedrichards/rsyncwrapper/issues/28) - // [set chmod flag by default on Windows](https://github.com/jedrichards/rsyncwrapper/pull/29) - var chmodArg = (options.args || []).find(function(arg) { - return arg.match(/--chmod=/) - }) - if (isWin && !chmodArg) { - args.push('--chmod=ugo=rwX') - } - - if (typeof options.host !== 'undefined' || options.ssh) { - args.push('--rsh') - var rshCmd = 'ssh' - if (typeof options.port !== 'undefined') { - rshCmd += ' -p ' + options.port - } - if (typeof options.privateKey !== 'undefined') { - rshCmd += ' -i ' + options.privateKey - } - if (typeof options.sshCmdArgs !== 'undefined') { - rshCmd += ' ' + options.sshCmdArgs.join(' ') - } - args.push(rshCmd) - } - - if (options.recursive === true) { - args.push('--recursive') - } - - if (options.times === true) { - args.push('--times') - } - - if (options.syncDest === true || options.deleteAll === true) { - args.push('--delete') - args.push('--delete-excluded') - } - - if (options.syncDestIgnoreExcl === true || options.delete === true) { - args.push('--delete') - } - - if (options.dryRun === true) { - args.push('--dry-run') - args.push('--verbose') - } - - if ( - typeof options.excludeFirst !== 'undefined' && - util.isArray(options.excludeFirst) - ) { - options.excludeFirst.forEach(function(value, index) { - args.push('--exclude=' + value) - }) - } - - if (typeof options.include !== 'undefined' && util.isArray(options.include)) { - options.include.forEach(function(value, index) { - args.push('--include=' + value) - }) - } - - if (typeof options.exclude !== 'undefined' && util.isArray(options.exclude)) { - options.exclude.forEach(function(value, index) { - args.push('--exclude=' + value) - }) - } - - switch (options.compareMode) { - case 'sizeOnly': - args.push('--size-only') - break - case 'checksum': - args.push('--checksum') - break - } - - if (typeof options.args !== 'undefined' && util.isArray(options.args)) { - args = [...new Set([...args, ...options.args])] - } - - args = [...new Set(args)] - - var noop = function() {} - var onStdout = options.onStdout || noop - var onStderr = options.onStderr || noop - - var cmd = 'rsync ' - args.forEach(function(arg) { - if (arg.substr(0, 4) === 'ssh ') { - arg = '"' + arg + '"' - } - cmd += arg + ' ' - }) - cmd = cmd.trim() - - if (options.noExec) { - callback(null, null, null, cmd) - return - } - - try { - var stdout = '' - var stderr = '' - // Launch cmd in a shell just like Node's child_process.exec() does: - // see https://github.com/joyent/node/blob/937e2e351b2450cf1e9c4d8b3e1a4e2a2def58bb/lib/child_process.js#L589 - var child - if (isWin) { - child = spawn('cmd.exe', ['/s', '/c', '"' + cmd + '"'], { - windowsVerbatimArguments: true, - stdio: [process.stdin, 'pipe', 'pipe'], - }) - } else { - child = spawn('/bin/sh', ['-c', cmd]) - } - - child.stdout.on('data', function(data) { - onStdout(data) - stdout += data - }) - - child.stderr.on('data', function(data) { - onStderr(data) - stderr += data - }) - - child.on('exit', function(code) { - var err = null - if (code !== 0) { - err = new Error('rsync exited with code ' + code) - err.code = code - } - callback(err, stdout, stderr, cmd) - }) - } catch (err) { - callback(err, null, null, cmd) - } -} - - -/***/ }), - -/***/ 505: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const { existsSync, mkdirSync, writeFileSync } = __nccwpck_require__(747); - -const { - GITHUB_WORKSPACE -} = process.env; - -const validateDir = (dir) => { - if (!existsSync(dir)) { - console.log(`[SSH] Creating ${dir} dir in `, GITHUB_WORKSPACE); - mkdirSync(dir); - console.log('✅ [SSH] dir created.'); - } else { - console.log(`[SSH] ${dir} dir exist`); - } -}; - -const validateFile = (filePath) => { - if (!existsSync(filePath)) { - console.log(`[SSH] Creating ${filePath} file in `, GITHUB_WORKSPACE); - try { - writeFileSync(filePath, '', { - encoding: 'utf8', - mode: 0o600 - }); - console.log('✅ [SSH] file created.'); - } catch (e) { - console.error('⚠️ [SSH] writeFileSync error', filePath, e.message); - process.abort(); - } - } else { - console.log(`[SSH] ${filePath} file exist`); - } -}; - -module.exports = { - validateDir, - validateFile -}; - - -/***/ }), - -/***/ 229: -/***/ ((module) => { - -const inputNames = ['REMOTE_HOST', 'REMOTE_USER', 'REMOTE_PORT', 'SSH_PRIVATE_KEY', 'DEPLOY_KEY_NAME', 'SOURCE', 'TARGET', 'ARGS', 'EXCLUDE']; - -const inputs = { - GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE -}; -// Get inputs from ENV or WITH workflow settings -inputNames.forEach((input) => { - inputs[input] = process.env[input] || process.env[`INPUT_${input}`]; -}); - -module.exports = inputs; - - -/***/ }), - -/***/ 447: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const { sync: commandExists } = __nccwpck_require__(569); -const { get: nodeCmd } = __nccwpck_require__(748); - -const validateRsync = (callback = () => {}) => { - const rsyncCli = commandExists('rsync'); - - if (!rsyncCli) { - nodeCmd( - 'sudo apt-get --no-install-recommends install rsync', - (err, data, stderr) => { - if (err) { - console.log('⚠️ [CLI] Rsync installation failed. Aborting ... ', err.message); - process.abort(); - } else { - console.log('✅ [CLI] Rsync installed. \n', data, stderr); - callback(); - } - } - ); - } else { - callback(); - } -}; - -const validateInputs = (inputs) => { - const inputKeys = Object.keys(inputs); - const validInputs = inputKeys.filter((inputKey) => { - const inputValue = inputs[inputKey]; - - if (!inputValue) { - console.error(`⚠️ [INPUTS] ${inputKey} is mandatory`); - } - - return inputValue; - }); - - if (validInputs.length !== inputKeys.length) { - console.error('⚠️ [INPUTS] Inputs not valid, aborting ...'); - process.abort(); - } -}; - -module.exports = { - validateRsync, - validateInputs -}; - - -/***/ }), - -/***/ 822: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const { writeFileSync } = __nccwpck_require__(747); -const { join } = __nccwpck_require__(622); - -const { - validateDir, - validateFile -} = __nccwpck_require__(505); - -const { - HOME -} = process.env; - -const addSshKey = (key, name) => { - const sshDir = join(HOME || __dirname, '.ssh'); - const filePath = join(sshDir, name); - - validateDir(sshDir); - validateFile(`${sshDir}/known_hosts`); - - try { - writeFileSync(filePath, key, { - encoding: 'utf8', - mode: 0o600 - }); - } catch (e) { - console.error('⚠️ writeFileSync error', filePath, e.message); - process.abort(); - } - - console.log('✅ Ssh key added to `.ssh` dir ', filePath); - - return filePath; -}; - -module.exports = { - addSshKey -} - - -/***/ }), - -/***/ 129: -/***/ ((module) => { - -"use strict"; -module.exports = require("child_process");; - -/***/ }), - -/***/ 747: -/***/ ((module) => { - -"use strict"; -module.exports = require("fs");; - -/***/ }), - -/***/ 622: -/***/ ((module) => { - -"use strict"; -module.exports = require("path");; - -/***/ }), - -/***/ 669: -/***/ ((module) => { - -"use strict"; -module.exports = require("util");; - -/***/ }) - -/******/ }); -/************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __nccwpck_require__(moduleId) { -/******/ // Check if module is in cache -/******/ var cachedModule = __webpack_module_cache__[moduleId]; -/******/ if (cachedModule !== undefined) { -/******/ return cachedModule.exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ var threw = true; -/******/ try { -/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); -/******/ threw = false; -/******/ } finally { -/******/ if(threw) delete __webpack_module_cache__[moduleId]; -/******/ } -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/************************************************************************/ -/******/ /* webpack/runtime/compat */ -/******/ -/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/ -var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. -(() => { -const nodeRsync = __nccwpck_require__(898); - -const { validateRsync, validateInputs } = __nccwpck_require__(447); -const { addSshKey } = __nccwpck_require__(822); - -const { - REMOTE_HOST, REMOTE_USER, - REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, - SOURCE, TARGET, ARGS, EXCLUDE, - GITHUB_WORKSPACE -} = __nccwpck_require__(229); - -const defaultOptions = { - ssh: true, - sshCmdArgs: ['-o StrictHostKeyChecking=no'], - recursive: true -}; - -console.log('[general] GITHUB_WORKSPACE: ', GITHUB_WORKSPACE); - -const sshDeploy = (() => { - const rsync = ({ privateKey, port, src, dest, args, exclude }) => { - console.log(`[Rsync] Starting Rsync Action: ${src} to ${dest}`); - if (exclude) console.log(`[Rsync] exluding folders ${exclude}`); - - try { - // RSYNC COMMAND - nodeRsync({ - src, dest, args, privateKey, port, excludeFirst: exclude, ...defaultOptions - }, (error, stdout, stderr, cmd) => { - if (error) { - console.error('⚠️ [Rsync] error: ', error.message); - console.log('⚠️ [Rsync] stderr: ', stderr); - console.log('⚠️ [Rsync] stdout: ', stdout); - console.log('⚠️ [Rsync] cmd: ', cmd); - process.abort(); - } else { - console.log('✅ [Rsync] finished.', stdout); - } - }); - } catch (err) { - console.error('⚠️ [Rsync] command error: ', err.message, err.stack); - process.abort(); - } - }; - - const init = ({ src, dest, args, host = 'localhost', port, username, privateKeyContent, exclude = [] }) => { - validateRsync(() => { - const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME || 'deploy_key'); - const remoteDest = `${username}@${host}:${dest}`; - - rsync({ privateKey, port, src, dest: remoteDest, args, exclude }); - }); - }; - - return { - init - }; -})(); - -const run = () => { - validateInputs({ SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER }); - - sshDeploy.init({ - src: `${GITHUB_WORKSPACE}/${SOURCE || ''}`, - dest: TARGET || `/home/${REMOTE_USER}/`, - args: ARGS ? [ARGS] : ['-rltgoDzvO'], - host: REMOTE_HOST, - port: REMOTE_PORT || '22', - username: REMOTE_USER, - privateKeyContent: SSH_PRIVATE_KEY, - exclude: (EXCLUDE || '').split(',').map((item) => item.trim()) // split by comma and trim whitespace - }); -}; - -run(); - -})(); - -module.exports = __webpack_exports__; -/******/ })() -; \ No newline at end of file +(()=>{var e={569:(e,r,t)=>{e.exports=t(325)},325:(e,r,t)=>{"use strict";var n=t(129).exec;var s=t(129).execSync;var o=t(747);var c=t(622);var i=o.access;var a=o.accessSync;var u=o.constants||o;var l=process.platform=="win32";var fileNotExists=function(e,r){i(e,u.F_OK,(function(e){r(!e)}))};var fileNotExistsSync=function(e){try{a(e,u.F_OK);return false}catch(e){return true}};var localExecutable=function(e,r){i(e,u.F_OK|u.X_OK,(function(e){r(null,!e)}))};var localExecutableSync=function(e){try{a(e,u.F_OK|u.X_OK);return true}catch(e){return false}};var commandExistsUnix=function(e,r,t){fileNotExists(e,(function(s){if(!s){var o=n("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }",(function(e,r,n){t(null,!!r)}));return}localExecutable(e,t)}))};var commandExistsWindows=function(e,r,t){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){t(null,false);return}var s=n("where "+r,(function(e){if(e!==null){t(null,false)}else{t(null,true)}}))};var commandExistsUnixSync=function(e,r){if(fileNotExistsSync(e)){try{var t=s("command -v "+r+" 2>/dev/null"+" && { echo >&1 "+r+"; exit 0; }");return!!t}catch(e){return false}}return localExecutableSync(e)};var commandExistsWindowsSync=function(e,r,t){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(e)){return false}try{var n=s("where "+r,{stdio:[]});return!!n}catch(e){return false}};var cleanInput=function(e){if(/[^A-Za-z0-9_\/:=-]/.test(e)){e="'"+e.replace(/'/g,"'\\''")+"'";e=e.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")}return e};if(l){cleanInput=function(e){var r=/[\\]/.test(e);if(r){var t='"'+c.dirname(e)+'"';var n='"'+c.basename(e)+'"';return t+":"+n}return'"'+e+'"'}}e.exports=function commandExists(e,r){var t=cleanInput(e);if(!r&&typeof Promise!=="undefined"){return new Promise((function(r,t){commandExists(e,(function(n,s){if(s){r(e)}else{t(n)}}))}))}if(l){commandExistsWindows(e,t,r)}else{commandExistsUnix(e,t,r)}};e.exports.sync=function(e){var r=cleanInput(e);if(l){return commandExistsWindowsSync(e,r)}else{return commandExistsUnixSync(e,r)}}},748:(e,r,t)=>{const{exec:n,execSync:s}=t(129);const o={run:runCommand,runSync:runSync,get:runCommand};function runCommand(e,r){return n(e,function(){return function(e,t,n){if(!r)return;r(e,t,n)}}(r))}function runSync(e){try{return{data:s(e).toString(),err:null,stderr:null}}catch(e){return{data:null,err:e.stderr.toString(),stderr:e.stderr.toString()}}}e.exports=o},898:(e,r,t)=>{"use strict";var n=t(129).spawn;var s=t(669);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=s._extend({},e);e=escapeSpacesInOptions(e);var t=e.platform||process.platform;var o=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(o&&!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"&&s.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){i.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&s.isArray(e.include)){e.include.forEach((function(e,r){i.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&s.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"&&s.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 y="";var v;if(o){v=n("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{v=n("/bin/sh",["-c",f])}v.stdout.on("data",(function(e){l(e);p+=e}));v.stderr.on("data",(function(e){d(e);y+=e}));v.on("exit",(function(e){var t=null;if(e!==0){t=new Error("rsync exited with code "+e);t.code=e}r(t,p,y,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,t)=>{const{existsSync:n,mkdirSync:s,writeFileSync:o}=t(747);const{GITHUB_WORKSPACE:c}=process.env;const validateDir=e=>{if(!n(e)){console.log(`[SSH] Creating ${e} dir in `,c);s(e);console.log("✅ [SSH] dir created.")}else{console.log(`[SSH] ${e} dir exist`)}};const validateFile=e=>{if(!n(e)){console.log(`[SSH] Creating ${e} file in `,c);try{o(e,"",{encoding:"utf8",mode:384});console.log("✅ [SSH] file created.")}catch(r){console.error("⚠️ [SSH] writeFileSync error",e,r.message);process.abort()}}else{console.log(`[SSH] ${e} file exist`)}};e.exports={validateDir:validateDir,validateFile:validateFile}},229:e=>{const r=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","EXCLUDE"];const t={GITHUB_WORKSPACE:process.env.GITHUB_WORKSPACE};r.forEach((e=>{t[e]=process.env[e]||process.env[`INPUT_${e}`]}));e.exports=t},447:(e,r,t)=>{const{sync:n}=t(569);const{get:s}=t(748);const validateRsync=(e=(()=>{}))=>{const r=n("rsync");if(!r){s("sudo apt-get --no-install-recommends install rsync",((r,t,n)=>{if(r){console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ",r.message);process.abort()}else{console.log("✅ [CLI] Rsync installed. \n",t,n);e()}}))}else{e()}};const validateInputs=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){console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");process.abort()}};e.exports={validateRsync:validateRsync,validateInputs:validateInputs}},822:(e,r,t)=>{const{writeFileSync:n}=t(747);const{join:s}=t(622);const{validateDir:o,validateFile:c}=t(505);const{HOME:i}=process.env;const addSshKey=(e,r)=>{const t=s(i||__dirname,".ssh");const a=s(t,r);o(t);c(`${t}/known_hosts`);try{n(a,e,{encoding:"utf8",mode:384})}catch(e){console.error("⚠️ writeFileSync error",a,e.message);process.abort()}console.log("✅ Ssh key added to `.ssh` dir ",a);return a};e.exports={addSshKey:addSshKey}},129:e=>{"use strict";e.exports=require("child_process")},747:e=>{"use strict";e.exports=require("fs")},622:e=>{"use strict";e.exports=require("path")},669:e=>{"use strict";e.exports=require("util")}};var r={};function __nccwpck_require__(t){var n=r[t];if(n!==undefined){return n.exports}var s=r[t]={exports:{}};var o=true;try{e[t](s,s.exports,__nccwpck_require__);o=false}finally{if(o)delete r[t]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t={};(()=>{const e=__nccwpck_require__(898);const{validateRsync:r,validateInputs:t}=__nccwpck_require__(447);const{addSshKey:n}=__nccwpck_require__(822);const{REMOTE_HOST:s,REMOTE_USER:o,REMOTE_PORT:c,SSH_PRIVATE_KEY:i,DEPLOY_KEY_NAME:a,SOURCE:u,TARGET:l,ARGS:d,EXCLUDE:f,GITHUB_WORKSPACE:p}=__nccwpck_require__(229);const y={ssh:true,sshCmdArgs:["-o StrictHostKeyChecking=no"],recursive:true};console.log("[general] GITHUB_WORKSPACE: ",p);const v=(()=>{const rsync=({privateKey:r,port:t,src:n,dest:s,args:o,exclude:c})=>{console.log(`[Rsync] Starting Rsync Action: ${n} to ${s}`);if(c)console.log(`[Rsync] exluding folders ${c}`);try{e({src:n,dest:s,args:o,privateKey:r,port:t,excludeFirst:c,...y},((e,r,t,n)=>{if(e){console.error("⚠️ [Rsync] error: ",e.message);console.log("⚠️ [Rsync] stderr: ",t);console.log("⚠️ [Rsync] stdout: ",r);console.log("⚠️ [Rsync] cmd: ",n);process.abort()}else{console.log("✅ [Rsync] finished.",r)}}))}catch(e){console.error("⚠️ [Rsync] command error: ",e.message,e.stack);process.abort()}};const init=({src:e,dest:t,args:s,host:o="localhost",port:c,username:i,privateKeyContent:u,exclude:l=[]})=>{r((()=>{const r=n(u,a||"deploy_key");const d=`${i}@${o}:${t}`;rsync({privateKey:r,port:c,src:e,dest:d,args:s,exclude:l})}))};return{init:init}})();const run=()=>{t({SSH_PRIVATE_KEY:i,REMOTE_HOST:s,REMOTE_USER:o});v.init({src:`${p}/${u||""}`,dest:l||`/home/${o}/`,args:d?[d]:["-rltgoDzvO"],host:s,port:c||"22",username:o,privateKeyContent:i,exclude:(f||"").split(",").map((e=>e.trim()))})};run()})();module.exports=t})(); \ No newline at end of file diff --git a/package.json b/package.json index 44aee2a..29fb3ae 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ssh-deploy", "version": "2.1.9", "description": "Fast NodeJS action to deploy specific directory from `GITHUB_WORKSPACE` to a server via rsync over ssh.", - "main": "src/index.js", + "main": "dist/index.js", "dependencies": { "command-exists": "1.2.9", "node-cmd": "4.0.0", @@ -15,7 +15,7 @@ "eslint-plugin-import": "^2.23.3" }, "scripts": { - "build": "npm run lint && ncc build ./src/index.js -o dist", + "build": "npm run lint && ncc build ./src/index.js -o dist -m", "lint": "eslint ./src/index.js", "lint:fix": "eslint ./src/index.js --fix" },