mirror of
https://github.com/papeloto/action-zip
synced 2024-11-22 05:29:35 -08:00
fix: nested paths
This commit is contained in:
parent
32017ec6d6
commit
a1b75eab61
2 changed files with 34 additions and 34 deletions
34
dist/index.js
vendored
34
dist/index.js
vendored
|
@ -58,42 +58,42 @@ const path = __webpack_require__(622);
|
|||
const AdmZip = __webpack_require__(639);
|
||||
const core = __webpack_require__(470);
|
||||
|
||||
const inputFiles = core.getInput("files", { required: true });
|
||||
const filename = core.getInput("output");
|
||||
|
||||
const files = inputFiles
|
||||
const files = core
|
||||
.getInput("files", { required: true })
|
||||
.split(" ")
|
||||
.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();
|
||||
|
||||
console.log(files);
|
||||
|
||||
files.forEach(file => {
|
||||
if (!fs.existsSync(file)) {
|
||||
console.log(` - ${file} (Not Found)`);
|
||||
const filename = file.replace(process.env.GITHUB_WORKSPACE, "");
|
||||
|
||||
if (!fs.existsSync(filename)) {
|
||||
console.log(` - ${filename} (Not Found)`);
|
||||
return;
|
||||
}
|
||||
|
||||
const dir = path.dirname(file);
|
||||
const stats = fs.lstatSync(file);
|
||||
const dir = path.dirname(filename);
|
||||
const stats = fs.lstatSync(filename);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
zip.addLocalFolder(file, dir);
|
||||
zip.addLocalFolder(filename, dir);
|
||||
} 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);
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
|
34
index.js
34
index.js
|
@ -3,39 +3,39 @@ const path = require("path");
|
|||
const AdmZip = require("adm-zip");
|
||||
const core = require("@actions/core");
|
||||
|
||||
const inputFiles = core.getInput("files", { required: true });
|
||||
const filename = core.getInput("output");
|
||||
|
||||
const files = inputFiles
|
||||
const files = core
|
||||
.getInput("files", { required: true })
|
||||
.split(" ")
|
||||
.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();
|
||||
|
||||
console.log(files);
|
||||
|
||||
files.forEach(file => {
|
||||
if (!fs.existsSync(file)) {
|
||||
console.log(` - ${file} (Not Found)`);
|
||||
const filename = file.replace(process.env.GITHUB_WORKSPACE, "");
|
||||
|
||||
if (!fs.existsSync(filename)) {
|
||||
console.log(` - ${filename} (Not Found)`);
|
||||
return;
|
||||
}
|
||||
|
||||
const dir = path.dirname(file);
|
||||
const stats = fs.lstatSync(file);
|
||||
const dir = path.dirname(filename);
|
||||
const stats = fs.lstatSync(filename);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
zip.addLocalFolder(file, dir);
|
||||
zip.addLocalFolder(filename, dir);
|
||||
} 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);
|
||||
|
|
Loading…
Reference in a new issue