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 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
|
|
|
|
2020-03-21 05:29:35 -07:00
|
|
|
console.log(`filePath: ${filePath}`);
|
|
|
|
console.log(`fileName: ${fileName}`);
|
2020-03-21 05:33:59 -07:00
|
|
|
console.log(`dir: ${dir}`);
|
|
|
|
console.log(`Is dir: ${stats.isDirectory()}`);
|
2020-03-21 05:29:35 -07:00
|
|
|
|
2020-03-21 04:41:59 -07:00
|
|
|
if (stats.isDirectory()) {
|
2020-03-21 05:33:59 -07:00
|
|
|
zip.addLocalFolder(filePath, dir === "." ? fileName : dir);
|
2020-03-21 04:41:59 -07:00
|
|
|
} else {
|
2020-03-21 05:20:56 -07:00
|
|
|
zip.addLocalFile(filePath, dir === "." ? "" : dir);
|
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`);
|
2020-03-21 04:41:59 -07:00
|
|
|
|
2020-03-21 05:20:56 -07:00
|
|
|
core.setOutput(destPath);
|