From 4ab116fedf0fd09136b3f1f7beaa7e83d98ffd97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Kamga?= Date: Sat, 6 Feb 2021 22:56:23 +0100 Subject: [PATCH 1/3] replace all occurrences Quick updates to allow the updates of all occurrences of a variable --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 493e581..5e6b1f8 100755 --- a/index.js +++ b/index.js @@ -22,7 +22,8 @@ try { var kv = vars[i].split('=') var key = kv[0] var value = kv[1] - result = result.replace(key, value) + var regx = new RegExp(key, 'g'); + result = result.replace(regx, value) } console.log('file2: '+filename) fs.writeFile(filename, result, 'utf8', function (err) { From 4c8db95508a755b884ff448544cf52baa1733281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Kamga?= Date: Sat, 6 Feb 2021 23:55:20 +0100 Subject: [PATCH 2/3] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 5e6b1f8..bbfb427 100755 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ try { var kv = vars[i].split('=') var key = kv[0] var value = kv[1] - var regx = new RegExp(key, 'g'); + var regx = new RegExp(key, 'g') result = result.replace(regx, value) } console.log('file2: '+filename) From adbc14f8fa605015dde37669c8b7c62fdbb5ec95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Kamga?= Date: Sun, 7 Feb 2021 10:14:59 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 53c38fd..5ed1d11 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # replace-action -This lightweight action replaces substrings in files. It is useful for CI process when you needto update your configs depending on the previous steps results. +This lightweight action replaces substrings in files. It is useful for CI process when you need to update your configs depending on the previous steps results. # Usage @@ -11,8 +11,9 @@ See [action.yml](action.yml) uses: datamonsters/replace-action with: files: 'path1/file1,path2/file2' - replacements: 'foo=bar,$FOO=Bar_Value' + replacements: 'foo=bar,@FOO=Bar_Value' ``` +As the replacement is using regular expression, you should avoid 'special' characters which might be misinterpreted in the RegEx context. # Example @@ -73,4 +74,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)