From eb6660b7265d5d6f08731181f968a4d7ade41c15 Mon Sep 17 00:00:00 2001 From: mh4647 Date: Mon, 5 Sep 2022 14:07:16 +0300 Subject: [PATCH 1/9] Add commit to approve version action --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 53c38fd..4580312 100644 --- a/README.md +++ b/README.md @@ -73,4 +73,4 @@ jobs: # License -The scripts and documentation in this project are released under the [MIT License](LICENSE) \ No newline at end of file +The scripts and documentation in this project are released under the [MIT License](LICENSE) \ No newline at end of file From d09fdd904ff650b0830fc986d5676756b76bb0b2 Mon Sep 17 00:00:00 2001 From: mh4647 Date: Mon, 5 Sep 2022 14:15:38 +0300 Subject: [PATCH 2/9] Naming Add a note in readme --- README.md | 5 ++++- action.yml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4580312..09146d8 100644 --- a/README.md +++ b/README.md @@ -73,4 +73,7 @@ jobs: # License -The scripts and documentation in this project are released under the [MIT License](LICENSE) \ No newline at end of file +The scripts and documentation in this project are released under the [MIT License](LICENSE) + +This is a fork from https://github.com/datamonsters/replace-action. +I created this action becasue the the old repository doesn't get updated for 3 years. diff --git a/action.yml b/action.yml index 900302a..324737d 100755 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: 'Replace Action' +name: 'Replace Action-Z' description: 'Replaces substrings in files. Useful to enrich configs with previous steps artifacts.' author: Data Monsters branding: From 6a1fbb31819f2c89985aade502645890217b7f87 Mon Sep 17 00:00:00 2001 From: mh4647 Date: Mon, 5 Sep 2022 14:45:51 +0300 Subject: [PATCH 3/9] Add logs Revert "=" usage --- index.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 565db1e..597b542 100755 --- a/index.js +++ b/index.js @@ -5,30 +5,30 @@ try { const vars_string = core.getInput('replacements'); var filenames = files.replace(' ', '').split(',') var vars = vars_string.split(',') - console.log('files l:'+ filenames.length) - for(var fi = 0; fi < filenames.length; fi++) - { + console.log('files l:' + filenames.length) + for (var fi = 0; fi < filenames.length; fi++) { var filename = filenames[fi] var fs = require('fs') - console.log('file1: '+ fi + ' '+filename) - fs.readFile(filename, 'utf8', function (err,data) { + console.log('file1: ' + fi + ' ' + filename) + fs.readFile(filename, 'utf8', function (err, data) { if (err) { console.log(err); } else { var result = data console.log(data) - for(var i = 0; i < vars.length; i++) - { - var firstEqual = vars[i].indexOf('='); - var key = vars[i].substr(0,firstEqual); - var value = vars[i].substr(firstEqual+1); - result = result.replace(key, value) + for (var i = 0; i < vars.length; i++) { + var kv = vars[i].split('=') + var key = kv[0] + var value = kv[1] + console.log("key: " + key); + console.log("Value: " + value); + result = result.replace(key, value) } - console.log('file2: '+filename) + console.log('file2: ' + filename) fs.writeFile(filename, result, 'utf8', function (err) { - if (err) + if (err) console.log(err) - else + else console.log(result) }); } From 6130cb94ada1d5da468db243a0fa236038ccc508 Mon Sep 17 00:00:00 2001 From: mh4647 Date: Mon, 5 Sep 2022 15:30:34 +0300 Subject: [PATCH 4/9] Print vars to log --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 597b542..ce62e94 100755 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ try { var filenames = files.replace(' ', '').split(',') var vars = vars_string.split(',') console.log('files l:' + filenames.length) + console.log('vars:' + vars) for (var fi = 0; fi < filenames.length; fi++) { var filename = filenames[fi] var fs = require('fs') From 27a7371633b8fdded897a145d424637c545f9005 Mon Sep 17 00:00:00 2001 From: mh4647 <92085925+mh4647@users.noreply.github.com> Date: Sun, 4 Feb 2024 17:05:24 +0200 Subject: [PATCH 5/9] Update to node 20 --- action.yml | 4 ++-- index.js | 48 ++++++++++++++++++++++-------------------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/action.yml b/action.yml index 900302a..e0b1f1e 100755 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: 'Replace Action' +name: 'Replace Action-Z' description: 'Replaces substrings in files. Useful to enrich configs with previous steps artifacts.' author: Data Monsters branding: @@ -12,5 +12,5 @@ inputs: description: 'Comma-separated pairs PLACEHOLDER=value' required: true runs: - using: 'node12' + using: 'node20' main: 'index.js' diff --git a/index.js b/index.js index 565db1e..70dd4b7 100755 --- a/index.js +++ b/index.js @@ -1,35 +1,31 @@ -const core = require('@actions/core'); +const core = require("@actions/core"); try { - const files = core.getInput('files'); - const vars_string = core.getInput('replacements'); - var filenames = files.replace(' ', '').split(',') - var vars = vars_string.split(',') - console.log('files l:'+ filenames.length) - for(var fi = 0; fi < filenames.length; fi++) - { - var filename = filenames[fi] - var fs = require('fs') - console.log('file1: '+ fi + ' '+filename) - fs.readFile(filename, 'utf8', function (err,data) { + const files = core.getInput("files"); + const vars_string = core.getInput("replacements"); + const filenames = files.replace(" ", "").split(","); + const vars = vars_string.split(","); + console.log("files l:" + filenames.length); + for (var fi = 0; fi < filenames.length; fi++) { + const filename = filenames[fi]; + const fs = require("fs"); + console.log("file1: " + fi + " " + filename); + fs.readFile(filename, "utf8", function (err, data) { if (err) { console.log(err); } else { - var result = data - console.log(data) - for(var i = 0; i < vars.length; i++) - { - var firstEqual = vars[i].indexOf('='); - var key = vars[i].substr(0,firstEqual); - var value = vars[i].substr(firstEqual+1); - result = result.replace(key, value) + const result = data; + console.log(data); + for (let i = 0; i < vars.length; i++) { + const firstEqual = vars[i].indexOf("="); + const key = vars[i].substring(0, firstEqual); + const value = vars[i].substring(firstEqual + 1); + result = result.replace(key, value); } - console.log('file2: '+filename) - fs.writeFile(filename, result, 'utf8', function (err) { - if (err) - console.log(err) - else - console.log(result) + console.log("file2: " + filename); + fs.writeFile(filename, result, "utf8", function (err) { + if (err) console.log(err); + else console.log(result); }); } }); From 3ac2c9813baec5341b2754b6f6eaa8ba974323b7 Mon Sep 17 00:00:00 2001 From: mh4647 <92085925+mh4647@users.noreply.github.com> Date: Sun, 4 Feb 2024 17:10:16 +0200 Subject: [PATCH 6/9] Changed var to let --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 70dd4b7..8d7714b 100755 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ try { const filenames = files.replace(" ", "").split(","); const vars = vars_string.split(","); console.log("files l:" + filenames.length); - for (var fi = 0; fi < filenames.length; fi++) { + for (let fi = 0; fi < filenames.length; fi++) { const filename = filenames[fi]; const fs = require("fs"); console.log("file1: " + fi + " " + filename); From fb7815b071091a43536738fedf48f9f59294de2a Mon Sep 17 00:00:00 2001 From: mh4647 <92085925+mh4647@users.noreply.github.com> Date: Sun, 4 Feb 2024 17:28:07 +0200 Subject: [PATCH 7/9] Revert sub string to split --- .idea/sonarlint/issuestore/index.pb | 0 .idea/sonarlint/securityhotspotstore/index.pb | 0 .idea/workspace.xml | 14 ++++++++++++++ index.js | 8 +++++--- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 .idea/sonarlint/issuestore/index.pb create mode 100644 .idea/sonarlint/securityhotspotstore/index.pb create mode 100644 .idea/workspace.xml diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..68b8b9b --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,14 @@ + + + + + { + "keyToString": { + "settings.editor.selected.configurable": "AndroidSdkUpdater" + } +} + \ No newline at end of file diff --git a/index.js b/index.js index cc704f9..54c7c7e 100644 --- a/index.js +++ b/index.js @@ -17,9 +17,11 @@ try { const result = data; console.log(data); for (let i = 0; i < vars.length; i++) { - const firstEqual = vars[i].indexOf("="); - const key = vars[i].substring(0, firstEqual); - const value = vars[i].substring(firstEqual + 1); + const kv = vars[i].split('=') + const key = kv[0] + const value = kv[1] + console.log("key: " + key); + console.log("Value: " + value); result = result.replace(key, value); } console.log(`file2: ${filename}`); From 209b5d1cb554b2e5beb5d7172544b92326e4ef78 Mon Sep 17 00:00:00 2001 From: mh4647 <92085925+mh4647@users.noreply.github.com> Date: Sun, 4 Feb 2024 17:31:12 +0200 Subject: [PATCH 8/9] Printing formating --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 54c7c7e..ecb73a4 100644 --- a/index.js +++ b/index.js @@ -20,8 +20,8 @@ try { const kv = vars[i].split('=') const key = kv[0] const value = kv[1] - console.log("key: " + key); - console.log("Value: " + value); + console.log(`key: ${key}`); + console.log(`Value: ${value}`); result = result.replace(key, value); } console.log(`file2: ${filename}`); From 16feccb26650d9f5618210f302f7f1ffa0af82e4 Mon Sep 17 00:00:00 2001 From: mh4647 <92085925+mh4647@users.noreply.github.com> Date: Sun, 4 Feb 2024 17:33:57 +0200 Subject: [PATCH 9/9] Update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38aadf4..14a7a8e 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hello-world-javascript-action", - "version": "1.0.0", + "version": "2.0.5", "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", "main": "index.js", "scripts": {