2023-01-03 04:06:33 +08:00
|
|
|
const { snakeToCamel } = require('./helpers');
|
|
|
|
|
|
|
|
const inputNames = [
|
|
|
|
'REMOTE_HOST', 'REMOTE_USER', 'REMOTE_PORT',
|
|
|
|
'SSH_PRIVATE_KEY', 'DEPLOY_KEY_NAME',
|
|
|
|
'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: '',
|
|
|
|
target: `/home/${remoteUser}/`,
|
|
|
|
exclude: '',
|
|
|
|
args: '-rltgoDzvO',
|
|
|
|
sshCmdArgs: '-o StrictHostKeyChecking=no',
|
|
|
|
deployKeyName: 'deploy_key'
|
|
|
|
};
|
2020-07-01 06:54:24 +08:00
|
|
|
|
|
|
|
const inputs = {
|
2023-01-03 04:06:33 +08:00
|
|
|
githubWorkspace
|
2020-07-01 06:54:24 +08:00
|
|
|
};
|
2022-12-31 09:43:17 +08:00
|
|
|
|
2020-07-01 06:54:24 +08:00
|
|
|
inputNames.forEach((input) => {
|
2023-01-03 04:06:33 +08:00
|
|
|
const inputName = snakeToCamel(input.toLowerCase());
|
|
|
|
const inputVal = process.env[input] || process.env[`INPUT_${input}`];
|
|
|
|
const validVal = inputVal === undefined ? defaultInputs[inputName] : inputVal;
|
|
|
|
let extendedVal = validVal;
|
|
|
|
// eslint-disable-next-line default-case
|
|
|
|
switch (inputName) {
|
2023-01-03 06:50:02 +08:00
|
|
|
case 'args':
|
|
|
|
extendedVal = validVal.split(' ');
|
2023-01-03 04:06:33 +08:00
|
|
|
break;
|
|
|
|
case 'exclude':
|
|
|
|
case 'sshCmdArgs':
|
|
|
|
extendedVal = validVal.split(',').map((item) => item.trim());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
inputs[inputName] = extendedVal;
|
2020-07-01 06:54:24 +08:00
|
|
|
});
|
|
|
|
|
2023-01-03 04:06:33 +08:00
|
|
|
inputs.sshServer = `${inputs.remoteUser}@${inputs.remoteHost}`;
|
|
|
|
inputs.rsyncServer = `${inputs.remoteUser}@${inputs.remoteHost}:${inputs.target}`;
|
|
|
|
|
2020-07-01 06:54:24 +08:00
|
|
|
module.exports = inputs;
|