fix: nested paths

This commit is contained in:
papeloto 2020-03-21 13:08:23 +01:00
parent 32017ec6d6
commit a1b75eab61
2 changed files with 34 additions and 34 deletions

34
dist/index.js vendored
View file

@ -58,42 +58,42 @@ const path = __webpack_require__(622);
const AdmZip = __webpack_require__(639); const AdmZip = __webpack_require__(639);
const core = __webpack_require__(470); const core = __webpack_require__(470);
const inputFiles = core.getInput("files", { required: true }); const files = core
const filename = core.getInput("output"); .getInput("files", { required: true })
const files = inputFiles
.split(" ") .split(" ")
.map(file => path.join(process.env.GITHUB_WORKSPACE, file)); .map(file => path.join(process.env.GITHUB_WORKSPACE, file));
console.log(`Ready to zip "${inputFiles}" into ${filename}`); const output = path.join(process.env.GITHUB_WORKSPACE, core.getInput("output"));
console.log(`Ready to zip "${files}" into ${output}`);
const zip = new AdmZip(); const zip = new AdmZip();
console.log(files);
files.forEach(file => { files.forEach(file => {
if (!fs.existsSync(file)) { const filename = file.replace(process.env.GITHUB_WORKSPACE, "");
console.log(` - ${file} (Not Found)`);
if (!fs.existsSync(filename)) {
console.log(` - ${filename} (Not Found)`);
return; return;
} }
const dir = path.dirname(file); const dir = path.dirname(filename);
const stats = fs.lstatSync(file); const stats = fs.lstatSync(filename);
if (stats.isDirectory()) { if (stats.isDirectory()) {
zip.addLocalFolder(file, dir); zip.addLocalFolder(filename, dir);
} else { } else {
zip.addLocalFile(file, dir === "." ? "" : dir); zip.addLocalFile(filename, dir === "." ? "" : dir);
} }
console.log(` - ${file}`); console.log(` - ${filename}`);
}); });
zip.writeZip(filename); zip.writeZip(output);
console.log(`\nZipped file ${filename}`); console.log(`\nZipped file ${output}`);
core.setOutput(filename); core.setOutput(output);
/***/ }), /***/ }),

View file

@ -3,39 +3,39 @@ const path = require("path");
const AdmZip = require("adm-zip"); const AdmZip = require("adm-zip");
const core = require("@actions/core"); const core = require("@actions/core");
const inputFiles = core.getInput("files", { required: true }); const files = core
const filename = core.getInput("output"); .getInput("files", { required: true })
const files = inputFiles
.split(" ") .split(" ")
.map(file => path.join(process.env.GITHUB_WORKSPACE, file)); .map(file => path.join(process.env.GITHUB_WORKSPACE, file));
console.log(`Ready to zip "${inputFiles}" into ${filename}`); const output = path.join(process.env.GITHUB_WORKSPACE, core.getInput("output"));
console.log(`Ready to zip "${files}" into ${output}`);
const zip = new AdmZip(); const zip = new AdmZip();
console.log(files);
files.forEach(file => { files.forEach(file => {
if (!fs.existsSync(file)) { const filename = file.replace(process.env.GITHUB_WORKSPACE, "");
console.log(` - ${file} (Not Found)`);
if (!fs.existsSync(filename)) {
console.log(` - ${filename} (Not Found)`);
return; return;
} }
const dir = path.dirname(file); const dir = path.dirname(filename);
const stats = fs.lstatSync(file); const stats = fs.lstatSync(filename);
if (stats.isDirectory()) { if (stats.isDirectory()) {
zip.addLocalFolder(file, dir); zip.addLocalFolder(filename, dir);
} else { } else {
zip.addLocalFile(file, dir === "." ? "" : dir); zip.addLocalFile(filename, dir === "." ? "" : dir);
} }
console.log(` - ${file}`); console.log(` - ${filename}`);
}); });
zip.writeZip(filename); zip.writeZip(output);
console.log(`\nZipped file ${filename}`); console.log(`\nZipped file ${output}`);
core.setOutput(filename); core.setOutput(output);