-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsftp.js
37 lines (32 loc) · 1.58 KB
/
sftp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const core = require('@actions/core');
const fs = require('fs');
const { Deployer } = require('./lib/deployer');
const config = {
host: core.getInput('host'), // Required.
port: core.getInput('port'), // Optional, Default to 22.
username: core.getInput('username'), // Required.
password: core.getInput('password'), // Optional.
privateKey: core.getInput('privateKey'), // Optional.
passphrase: core.getInput('passphrase'), // Optional.
algorithms: core.getInput('compress') ? {compress: '[email protected]'} : {}, // Optional. Default to false.
agent: core.getInput('agent'), // Optional, path to the ssh-agent socket.
localDir: core.getInput('localDir'), // Required, Absolute or relative to cwd.
remoteDir: core.getInput('remoteDir') // Required, Absolute path only.
};
const options = {
dryRun: JSON.parse(core.getInput('dryRun')), // Enable dry-run mode. Default to false.
exclude: core.getInput('exclude').split(','), // exclude patterns (glob) like .gitignore.
forceUpload: JSON.parse(core.getInput('forceUpload')), // Force uploading all files, Default to false(upload only newer files).
removeExtraFilesOnServer: JSON.parse(core.getInput('removeExtraFilesOnServer')) // Remove extra files on server, default to false.
};
if (config.privateKey && !/^[-]+[A-Z ]+[-]+\n/.test(config.privateKey)) {
try {
config.privateKey = fs.readFileSync(config.privateKey);;
} catch (err) {
console.error(err);
throw new Error(`Private key file not found ${config.privateKey}`);
}
}
new Deployer(config, options)
.sync()
.then(() => console.log('sftp upload success!'));