2020-03-21 04:41:59 -07:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
const AdmZip = require("adm-zip");
|
|
|
|
const core = require("@actions/core");
|
|
|
|
|
2020-03-21 05:20:56 -07:00
|
|
|
const files = core.getInput("files");
|
|
|
|
const dest = core.getInput("dest");
|
2020-03-21 06:46:00 -07:00
|
|
|
const recursive = core.getInput("recursive") === "true";
|
2020-03-21 04:41:59 -07:00
|
|
|
|
2020-03-21 05:20:56 -07:00
|
|
|
console.log(`Ready to zip "${files}" into ${dest}`);
|
2020-03-21 04:41:59 -07:00
|
|
|
|
2020-03-21 05:08:23 -07:00
|
|
|
const zip = new AdmZip();
|
2020-03-21 04:46:09 -07:00
|
|
|
|
2020-03-21 05:20:56 -07:00
|
|
|
files.split(" ").forEach(fileName => {
|
|
|
|
const filePath = path.join(process.env.GITHUB_WORKSPACE, fileName);
|
2020-03-21 05:08:23 -07:00
|
|
|
|
2020-03-21 05:20:56 -07:00
|
|
|
if (!fs.existsSync(filePath)) {
|
|
|
|
console.log(` - ${fileName} (Not Found)`);
|
2020-03-21 04:41:59 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-21 05:20:56 -07:00
|
|
|
const dir = path.dirname(fileName);
|
|
|
|
const stats = fs.lstatSync(filePath);
|
2020-03-21 04:41:59 -07:00
|
|
|
|
|
|
|
if (stats.isDirectory()) {
|
2020-03-21 06:46:00 -07:00
|
|
|
const zipDir = dir === "." ? fileName : dir;
|
|
|
|
zip.addLocalFolder(filePath, !recursive && zipDir);
|
2020-03-21 04:41:59 -07:00
|
|
|
} else {
|
2020-03-21 06:46:00 -07:00
|
|
|
const zipDir = dir === "." ? "" : dir;
|
|
|
|
zip.addLocalFile(filePath, !recursive && zipDir);
|
2020-03-21 04:41:59 -07:00
|
|
|
}
|
|
|
|
|
2020-03-21 05:20:56 -07:00
|
|
|
console.log(` - ${fileName}`);
|
2020-03-21 04:41:59 -07:00
|
|
|
});
|
|
|
|
|
2020-03-21 05:20:56 -07:00
|
|
|
const destPath = path.join(process.env.GITHUB_WORKSPACE, dest);
|
|
|
|
|
|
|
|
zip.writeZip(destPath);
|
2020-03-21 04:41:59 -07:00
|
|
|
|
2020-03-21 05:33:59 -07:00
|
|
|
console.log(`\nZipped file ${dest} successfully`);
|