-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
72 lines (61 loc) · 2.1 KB
/
index.js
File metadata and controls
72 lines (61 loc) · 2.1 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs')
const SftpUpload = require('sftp-upload');
try {
console.log('Server:', core.getInput('server'));
console.log('Local Path', core.getInput('local-path'));
console.log('Remote Path', core.getInput('remote-path'));
const payload = JSON.stringify(github.context.payload, undefined, 2);
// let Client = require('ssh2-sftp-client');
// let sftp = new Client();
// let config = {
// host: core.getInput('server'),
// port: core.getInput('port'),
// username: core.getInput('user'),
// password: core.getInput('pass'),
// };
// sftp.connect(config)
// .then(data => {
// // Read local directory
// const dir = fs.opendirSync(core.getInput('local-path'))
// // Loop through directory and move each file
// let dirent
// while ((dirent = dir.readSync()) !== null) {
// console.log('Transferring: ' + core.getInput('local-path') + dirent.name, 'To Location: ' + core.getInput('remote-path') + dirent.name);
// sftp.put(core.getInput('local-path') + dirent.name, core.getInput('remote-path') + dirent.name);
// }
// dir.closeSync();
// })
// .then(() => {
// sftp.end();
// core.setOutput('transferStatus', 'completed');
// })
// .catch(err => {
// console.log(err, 'catch error');
// });
sftp2 = new SftpUpload({
host:core.getInput('server'),
username:core.getInput('user'),
password:core.getInput('pass'),
path: core.getInput('local-path'),
remoteDir: core.getInput('remote-path'),
excludedFolders: ['**/.git', 'node_modules'],
exclude: ['.gitignore', '.vscode/tasks.json'],
dryRun: false
});
sftp2.on('error', function(err) {
throw err;
})
.on('uploading', function(progress) {
console.log('Uploading', progress.file);
console.log(progress.percent+'% completed');
})
.on('completed', function() {
console.log('Upload Completed');
core.setOutput('transferStatus', 'completed');
})
.upload();
} catch (error) {
core.setFailed(error.message);
}