mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2026-03-01 08:01:01 +08:00
add config.js...
This commit is contained in:
parent
01a39e3348
commit
c464f67edc
@ -2,15 +2,18 @@ name: "ssh deploy"
|
||||
description: "NodeJS action for FAST deployment with rsync/ssh and remote script execution before/after rsync"
|
||||
author: "easingthemes"
|
||||
inputs:
|
||||
CONFIG_PATH:
|
||||
description: "config path"
|
||||
required: false
|
||||
SSH_PRIVATE_KEY:
|
||||
description: "Private key part of an SSH key pair"
|
||||
required: true
|
||||
required: false
|
||||
REMOTE_HOST:
|
||||
description: "Remote host"
|
||||
required: true
|
||||
required: false
|
||||
REMOTE_USER:
|
||||
description: "Remote user"
|
||||
required: true
|
||||
required: false
|
||||
REMOTE_PORT:
|
||||
description: "Remote port"
|
||||
required: false
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@draganfilipovic/ssh-deploy",
|
||||
"version": "4.1.10",
|
||||
"version": "5.0.3",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@draganfilipovic/ssh-deploy",
|
||||
"version": "4.1.10",
|
||||
"version": "5.0.3",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"rsyncwrapper": "^3.0.1"
|
||||
|
||||
61
src/config.js
Normal file
61
src/config.js
Normal file
@ -0,0 +1,61 @@
|
||||
const { readFileSync, existsSync } = require('fs');
|
||||
const { handleError } = require('./helpers');
|
||||
|
||||
const githubWorkspace = process.env.GITHUB_WORKSPACE;
|
||||
const inputConfigKey = 'CONFIG_PATH';
|
||||
const inputSshKeyPath = 'SSH_PRIVATE_KEY_PATH';
|
||||
|
||||
const readConfig = (configPath) => {
|
||||
if (existsSync(configPath)) {
|
||||
const message = `⚠️ [FILE] ${configPath} Required file exist.`;
|
||||
handleError(message, true);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
console.log(`[FILE] reading ${configPath} file ...`);
|
||||
const fileContents = readFileSync(configPath, 'utf8');
|
||||
return JSON.parse(fileContents);
|
||||
} catch (error) {
|
||||
const message = `⚠️[FILE] reading file error. configPath: ${configPath}, message: ${error.message}`;
|
||||
handleError(message, true);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const readSshKey = (SshKeyPath) => {
|
||||
if (existsSync(SshKeyPath)) {
|
||||
const message = `⚠️ [FILE] ${SshKeyPath} Required file exist.`;
|
||||
handleError(message, true);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
console.log(`[FILE] reading ${SshKeyPath} file ...`);
|
||||
return readFileSync(SshKeyPath, 'utf8');
|
||||
} catch (error) {
|
||||
const message = `⚠️[FILE] reading file error. configPath: ${SshKeyPath}, message: ${error.message}`;
|
||||
handleError(message, true);
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
const initConfig = () => {
|
||||
const inputValue = process.env[inputConfigKey] || process.env[`INPUT_${inputConfigKey}`];
|
||||
if (inputValue) {
|
||||
const path = `${githubWorkspace}/${inputValue}`;
|
||||
const conf = readConfig(path);
|
||||
Object.keys(conf).forEach((k) => {
|
||||
if (k && conf[k]) {
|
||||
process.env[k] = conf[k];
|
||||
if (k === inputSshKeyPath) {
|
||||
process.env.SSH_PRIVATE_KEY = readSshKey(conf[k]);
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.warn('⚠️ [initConfig] CONFIG_PATH is not defined');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
initConfig
|
||||
};
|
||||
@ -1,4 +1,7 @@
|
||||
const { snakeToCamel } = require('./helpers');
|
||||
const { initConfig } = require('./config');
|
||||
|
||||
initConfig();
|
||||
|
||||
const inputNames = [
|
||||
'REMOTE_HOST', 'REMOTE_USER', 'REMOTE_PORT',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user