2023-01-02 01:02:44 +01:00
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
2023-01-02 11:41:31 +01:00
|
|
|
const { privateKey, sshServer, githubWorkspace } = require('./inputs');
|
2023-01-02 01:02:44 +01:00
|
|
|
const { writeToFile } = require('./helpers');
|
|
|
|
|
2023-01-02 01:12:37 +01:00
|
|
|
const remoteCmd = (content, label) => {
|
|
|
|
const filename = `local_ssh_script-${label}.sh`;
|
2023-01-02 01:02:44 +01:00
|
|
|
try {
|
2023-01-02 01:12:37 +01:00
|
|
|
writeToFile({ dir: githubWorkspace, filename, content });
|
2023-01-02 01:02:44 +01:00
|
|
|
|
2023-01-02 11:41:31 +01:00
|
|
|
exec(`ssh -i ${privateKey} ${sshServer} 'bash -s' < ${filename}`, (err, data, stderr) => {
|
2023-01-02 01:02:44 +01:00
|
|
|
if (err) {
|
|
|
|
console.log('⚠️ [CMD] Remote script failed. ', err.message);
|
|
|
|
} else {
|
|
|
|
console.log('✅ [CMD] Remote script executed. \n', data, stderr);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.log('⚠️ [CMD] Starting Remote script execution failed. ', err.message);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
remoteCmdBefore: (cmd) => remoteCmd(cmd, 'before'),
|
|
|
|
remoteCmdAfter: (cmd) => remoteCmd(cmd, 'after')
|
|
|
|
};
|