From 13e70558b7bf3ed41ff7486b52ecd4897a24fd32 Mon Sep 17 00:00:00 2001 From: papeloto Date: Sat, 21 Mar 2020 13:20:56 +0100 Subject: [PATCH] refactor: dest input name --- action.yml | 2 +- dist/index.js | 36 +++++++++++++++++------------------- index.js | 36 +++++++++++++++++------------------- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/action.yml b/action.yml index 25e0da8..1c62b91 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/dist/index.js b/dist/index.js index 7c20b7d..e43102f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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); /***/ }), diff --git a/index.js b/index.js index 7828864..7ad395e 100644 --- a/index.js +++ b/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);