-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (42 loc) · 1.46 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');
const Koofr = require('koofr');
const path = require('path');
const glob = require('@actions/glob');
// action variables
const baseUrl = core.getInput('baseUrl');
const username = core.getInput('username');
const password = core.getInput('appPassword');
const mountId = core.getInput('mountId');
const localPath = core.getInput('localPath');
const remotePath = core.getInput('remotePath');
const client = new Koofr(baseUrl);
async function uploadFile(mountId, pth, name, data) {
try {
console.log("Uploading to", mountId, pth, name);
await client.authenticate(username, password);
} catch (ex) {
throw new Error(`Authentication failed: ${ex.statusCode} ${ex.statusMessage}`);
}
try {
const ret = await client.filesPut(mountId, pth, name, data);
core.setOutput("name", ret.name);
} catch (ex) {
throw new Error(`Upload failed: ${ex.statusCode} ${ex.statusMessage}`);
}
}
async function main() {
try {
const globber = await glob.create(localPath)
const files = await globber.glob()
files.forEach(async function (filePath) {
const fileName = path.basename(filePath);
const file = fs.readFileSync(filePath);
await uploadFile(mountId, remotePath, fileName, file);
})
} catch (error) {
core.setFailed(error.message);
}
}
main()