mirror of
https://github.com/papeloto/action-zip
synced 2024-11-22 05:29:35 -08:00
refactor: dest input name
This commit is contained in:
parent
a77ec1c880
commit
13e70558b7
3 changed files with 35 additions and 39 deletions
|
@ -7,7 +7,7 @@ inputs:
|
||||||
files:
|
files:
|
||||||
description: "Files or directories to zip"
|
description: "Files or directories to zip"
|
||||||
required: true
|
required: true
|
||||||
output:
|
dest:
|
||||||
description: "Name of output zip file"
|
description: "Name of output zip file"
|
||||||
default: "result.zip"
|
default: "result.zip"
|
||||||
runs:
|
runs:
|
||||||
|
|
36
dist/index.js
vendored
36
dist/index.js
vendored
|
@ -58,42 +58,40 @@ 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 files = core
|
const files = core.getInput("files");
|
||||||
.getInput("files", { required: true })
|
const dest = core.getInput("dest");
|
||||||
.split(" ")
|
|
||||||
.map(file => path.join(process.env.GITHUB_WORKSPACE, file));
|
|
||||||
|
|
||||||
const output = path.join(process.env.GITHUB_WORKSPACE, core.getInput("output"));
|
console.log(`Ready to zip "${files}" into ${dest}`);
|
||||||
|
|
||||||
console.log(`Ready to zip "${files}" into ${output}`);
|
|
||||||
|
|
||||||
const zip = new AdmZip();
|
const zip = new AdmZip();
|
||||||
|
|
||||||
files.forEach(file => {
|
files.split(" ").forEach(fileName => {
|
||||||
const filename = file.replace(`${process.env.GITHUB_WORKSPACE}/`, "");
|
const filePath = path.join(process.env.GITHUB_WORKSPACE, fileName);
|
||||||
|
|
||||||
if (!fs.existsSync(file)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
console.log(` - ${filename} (Not Found)`);
|
console.log(` - ${fileName} (Not Found)`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dir = path.dirname(filename);
|
const dir = path.dirname(fileName);
|
||||||
const stats = fs.lstatSync(file);
|
const stats = fs.lstatSync(filePath);
|
||||||
|
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
zip.addLocalFolder(file, dir);
|
zip.addLocalFolder(filePath, dir);
|
||||||
} else {
|
} else {
|
||||||
zip.addLocalFile(file, dir === "." ? "" : dir);
|
zip.addLocalFile(filePath, dir === "." ? "" : dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(` - ${filename}`);
|
console.log(` - ${fileName}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
zip.writeZip(output);
|
const destPath = path.join(process.env.GITHUB_WORKSPACE, dest);
|
||||||
|
|
||||||
console.log(`\nZipped file ${output}`);
|
zip.writeZip(destPath);
|
||||||
|
|
||||||
core.setOutput(output);
|
console.log(`\nZipped file ${destPath} successfully`);
|
||||||
|
|
||||||
|
core.setOutput(destPath);
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
36
index.js
36
index.js
|
@ -3,39 +3,37 @@ 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 files = core
|
const files = core.getInput("files");
|
||||||
.getInput("files", { required: true })
|
const dest = core.getInput("dest");
|
||||||
.split(" ")
|
|
||||||
.map(file => path.join(process.env.GITHUB_WORKSPACE, file));
|
|
||||||
|
|
||||||
const output = path.join(process.env.GITHUB_WORKSPACE, core.getInput("output"));
|
console.log(`Ready to zip "${files}" into ${dest}`);
|
||||||
|
|
||||||
console.log(`Ready to zip "${files}" into ${output}`);
|
|
||||||
|
|
||||||
const zip = new AdmZip();
|
const zip = new AdmZip();
|
||||||
|
|
||||||
files.forEach(file => {
|
files.split(" ").forEach(fileName => {
|
||||||
const filename = file.replace(`${process.env.GITHUB_WORKSPACE}/`, "");
|
const filePath = path.join(process.env.GITHUB_WORKSPACE, fileName);
|
||||||
|
|
||||||
if (!fs.existsSync(file)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
console.log(` - ${filename} (Not Found)`);
|
console.log(` - ${fileName} (Not Found)`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dir = path.dirname(filename);
|
const dir = path.dirname(fileName);
|
||||||
const stats = fs.lstatSync(file);
|
const stats = fs.lstatSync(filePath);
|
||||||
|
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
zip.addLocalFolder(file, dir);
|
zip.addLocalFolder(filePath, dir);
|
||||||
} else {
|
} else {
|
||||||
zip.addLocalFile(file, dir === "." ? "" : dir);
|
zip.addLocalFile(filePath, dir === "." ? "" : dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(` - ${filename}`);
|
console.log(` - ${fileName}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
zip.writeZip(output);
|
const destPath = path.join(process.env.GITHUB_WORKSPACE, dest);
|
||||||
|
|
||||||
console.log(`\nZipped file ${output}`);
|
zip.writeZip(destPath);
|
||||||
|
|
||||||
core.setOutput(output);
|
console.log(`\nZipped file ${destPath} successfully`);
|
||||||
|
|
||||||
|
core.setOutput(destPath);
|
||||||
|
|
Loading…
Reference in a new issue