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");
|
|
|
|
|
|
|
|
const inputFiles = core.getInput("files", { required: true });
|
2020-03-21 04:52:26 -07:00
|
|
|
const filename = core.getInput("output");
|
2020-03-21 04:41:59 -07:00
|
|
|
|
2020-03-21 04:46:09 -07:00
|
|
|
const files = inputFiles
|
|
|
|
.split(" ")
|
|
|
|
.map(file => path.join(process.env.GITHUB_WORKSPACE, file));
|
2020-03-21 04:41:59 -07:00
|
|
|
|
|
|
|
console.log(`Ready to zip "${inputFiles}" into ${filename}`);
|
|
|
|
|
|
|
|
const zip = new AdmZip();
|
|
|
|
|
2020-03-21 04:46:09 -07:00
|
|
|
console.log(files);
|
|
|
|
|
2020-03-21 04:41:59 -07:00
|
|
|
files.forEach(file => {
|
|
|
|
if (!fs.existsSync(file)) {
|
|
|
|
console.log(` - ${file} (Not Found)`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const dir = path.dirname(file);
|
|
|
|
const stats = fs.lstatSync(file);
|
|
|
|
|
|
|
|
if (stats.isDirectory()) {
|
|
|
|
zip.addLocalFolder(file, dir);
|
|
|
|
} else {
|
|
|
|
zip.addLocalFile(file, dir === "." ? "" : dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(` - ${file}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
zip.writeZip(filename);
|
|
|
|
|
|
|
|
console.log(`\nZipped file ${filename}`);
|
|
|
|
|
|
|
|
core.setOutput(filename);
|