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:
|
||||
description: "Files or directories to zip"
|
||||
required: true
|
||||
output:
|
||||
dest:
|
||||
description: "Name of output zip file"
|
||||
default: "result.zip"
|
||||
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 core = __webpack_require__(470);
|
||||
|
||||
const files = core
|
||||
.getInput("files", { required: true })
|
||||
.split(" ")
|
||||
.map(file => path.join(process.env.GITHUB_WORKSPACE, file));
|
||||
const files = core.getInput("files");
|
||||
const dest = core.getInput("dest");
|
||||
|
||||
const output = path.join(process.env.GITHUB_WORKSPACE, core.getInput("output"));
|
||||
|
||||
console.log(`Ready to zip "${files}" into ${output}`);
|
||||
console.log(`Ready to zip "${files}" into ${dest}`);
|
||||
|
||||
const zip = new AdmZip();
|
||||
|
||||
files.forEach(file => {
|
||||
const filename = file.replace(`${process.env.GITHUB_WORKSPACE}/`, "");
|
||||
files.split(" ").forEach(fileName => {
|
||||
const filePath = path.join(process.env.GITHUB_WORKSPACE, fileName);
|
||||
|
||||
if (!fs.existsSync(file)) {
|
||||
console.log(` - ${filename} (Not Found)`);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
console.log(` - ${fileName} (Not Found)`);
|
||||
return;
|
||||
}
|
||||
|
||||
const dir = path.dirname(filename);
|
||||
const stats = fs.lstatSync(file);
|
||||
const dir = path.dirname(fileName);
|
||||
const stats = fs.lstatSync(filePath);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
zip.addLocalFolder(file, dir);
|
||||
zip.addLocalFolder(filePath, dir);
|
||||
} 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 core = require("@actions/core");
|
||||
|
||||
const files = core
|
||||
.getInput("files", { required: true })
|
||||
.split(" ")
|
||||
.map(file => path.join(process.env.GITHUB_WORKSPACE, file));
|
||||
const files = core.getInput("files");
|
||||
const dest = core.getInput("dest");
|
||||
|
||||
const output = path.join(process.env.GITHUB_WORKSPACE, core.getInput("output"));
|
||||
|
||||
console.log(`Ready to zip "${files}" into ${output}`);
|
||||
console.log(`Ready to zip "${files}" into ${dest}`);
|
||||
|
||||
const zip = new AdmZip();
|
||||
|
||||
files.forEach(file => {
|
||||
const filename = file.replace(`${process.env.GITHUB_WORKSPACE}/`, "");
|
||||
files.split(" ").forEach(fileName => {
|
||||
const filePath = path.join(process.env.GITHUB_WORKSPACE, fileName);
|
||||
|
||||
if (!fs.existsSync(file)) {
|
||||
console.log(` - ${filename} (Not Found)`);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
console.log(` - ${fileName} (Not Found)`);
|
||||
return;
|
||||
}
|
||||
|
||||
const dir = path.dirname(filename);
|
||||
const stats = fs.lstatSync(file);
|
||||
const dir = path.dirname(fileName);
|
||||
const stats = fs.lstatSync(filePath);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
zip.addLocalFolder(file, dir);
|
||||
zip.addLocalFolder(filePath, dir);
|
||||
} 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