-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.js
40 lines (29 loc) · 1.03 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
const fs = require("fs");
const path = require("path");
const AdmZip = require("adm-zip");
const core = require("@actions/core");
const files = core.getInput("files");
const dest = core.getInput("dest");
const recursive = core.getInput("recursive") === "true";
console.log(`Ready to zip "${files}" into ${dest}`);
const zip = new AdmZip();
files.split(" ").forEach(fileName => {
const filePath = path.join(process.env.GITHUB_WORKSPACE, fileName);
if (!fs.existsSync(filePath)) {
console.log(` - ${fileName} (Not Found)`);
return;
}
const dir = path.dirname(fileName);
const stats = fs.lstatSync(filePath);
if (stats.isDirectory()) {
const zipDir = dir === "." ? fileName : dir;
zip.addLocalFolder(filePath, !recursive && zipDir);
} else {
const zipDir = dir === "." ? "" : dir;
zip.addLocalFile(filePath, !recursive && zipDir);
}
console.log(` - ${fileName}`);
});
const destPath = path.join(process.env.GITHUB_WORKSPACE, dest);
zip.writeZip(destPath);
console.log(`\nZipped file ${dest} successfully`);