From 65e53b8e3b2ded39b96358472d6e9d4628d3f455 Mon Sep 17 00:00:00 2001 From: moweilin Date: Thu, 18 Jan 2024 00:07:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=98=BE=E7=A4=BA=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- action.yml | 5 ++++- dist/index.js | 9 +++++++++ package.json | 2 +- src/index.js | 9 +++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 487de74..34947f0 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ This action replace all env that starts with APP_ with env value in file ## Example usage ```yaml -uses: git.qtoa.cn/actions/action-env-replacer@0.0.1 +uses: git.qtoa.cn/actions/action-env-replacer@0.0.2 with: file: 'deployment.yaml' - force: true + show: false ``` deployment.yaml diff --git a/action.yml b/action.yml index 673a289..e77e20b 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,10 @@ inputs: file: description: 'file name' required: true - default: '' + show: + description: 'show content' + required: false + default: false runs: using: 'node20' main: 'dist/index.js' \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index e387aaf..11a4fe5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -26590,6 +26590,12 @@ const core = __nccwpck_require__(2186); const { writeFileSync, readFileSync } = __nccwpck_require__(7147); try { const file = core.getInput('file'); + core.info(`file:${file}`) + if(!file){ + throw { + message:"file should not be empty" + } + } let content = readFileSync(file, { encoding: "utf-8" }) const envs = process.env for (const key in envs) { @@ -26599,6 +26605,9 @@ try { } writeFileSync(file, content) core.info(`replace envs in ${file}`); + if(core.getBooleanInput("show")){ + core.info(`=============\n${content}\n=============`) + } } catch (error) { core.setFailed(error.message); } diff --git a/package.json b/package.json index 26f7a1d..ba75bc5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "action-env-replacer", - "version": "0.0.1", + "version": "0.0.2", "type": "commonjs", "scripts": { "build": "ncc build src/index.js -o dist" diff --git a/src/index.js b/src/index.js index 28a3f56..d684eda 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,12 @@ const core = require('@actions/core'); const { writeFileSync, readFileSync } = require('fs'); try { const file = core.getInput('file'); + core.info(`file:${file}`) + if(!file){ + throw { + message:"file should not be empty" + } + } let content = readFileSync(file, { encoding: "utf-8" }) const envs = process.env for (const key in envs) { @@ -11,6 +17,9 @@ try { } writeFileSync(file, content) core.info(`replace envs in ${file}`); + if(core.getBooleanInput("show")){ + core.info(`=============\n${content}\n=============`) + } } catch (error) { core.setFailed(error.message); } \ No newline at end of file