mirror of
https://github.com/papeloto/action-zip
synced 2024-11-22 05:29:35 -08:00
39 lines
926 B
JavaScript
39 lines
926 B
JavaScript
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");
|
|
|
|
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()) {
|
|
zip.addLocalFolder(filePath, dir);
|
|
} else {
|
|
zip.addLocalFile(filePath, dir === "." ? "" : dir);
|
|
}
|
|
|
|
console.log(` - ${fileName}`);
|
|
});
|
|
|
|
const destPath = path.join(process.env.GITHUB_WORKSPACE, dest);
|
|
|
|
zip.writeZip(destPath);
|
|
|
|
console.log(`\nZipped file ${destPath} successfully`);
|
|
|
|
core.setOutput(destPath);
|