Skip to content

Commit

Permalink
A0-3429: Extend replace-string to handle multiple replaces (#20)
Browse files Browse the repository at this point in the history
* Extend replace-string to handle multiple replaces
  • Loading branch information
mikogs authored Oct 30, 2023
1 parent 827c356 commit bcd78c3
Show file tree
Hide file tree
Showing 5 changed files with 637 additions and 528 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/test-replace-string.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,60 @@ jobs:
run: |
if [[ ! -f tmp-write-to-file.txt ]]; then
echo "!!! Action failed to create an output file"
exit 1
fi
output_from_file=$(cat tmp-write-to-file.txt);
if [[ "${output_from_file}" != 'Cranberry and red apple' ]]; then
echo "!!! Action failed to create an output file with replaced string"
exit 1
fi
- name: Create a dummy file with multiple variables
id: from-file-with-multiple
run: |
cat >tmp-read-from-file-multiple.txt <<EOF
Line without anything to replace
The following should contain an apple: __APPLE__ is red
And the following shall be '\$AZERO': __CURRENCY__
Thanks!
EOF
cat >tmp-write-to-file-multiple-expected.txt <<EOF
Line without anything to replace
The following should contain an apple: apple is red
And the following shall be '\$AZERO': \$AZERO
Thanks!
EOF
- name: Replace multiple strings
uses: ./replace-string
with:
read-from-file: 'tmp-read-from-file-multiple.txt'
replace-regex: |-
__APPLE__
__CURRENCY__
replace-with: |-
apple
$AZERO
write-to-file: 'tmp-write-to-file-multiple.txt'

- name: Check multistring replacement
run: |
diff tmp-write-to-file-multiple.txt tmp-write-to-file-multiple-expected.txt
- name: Replace newline characters
uses: ./replace-string
id: replace-newlines
with:
read-from-file: 'tmp-read-from-file-multiple.txt'
replace-regex: '\n'
replace-with: '%'
write-to-file: 'tmp-write-to-file-multiple-newlines.txt'
flags: g

- name: Check newline replacement
shell: bash
# yamllint disable rule:line-length
run: |
echo -n "Line without anything to replace%The following should contain an apple: __APPLE__ is red%And the following shall be '\$AZERO': __CURRENCY__%Thanks!%" > tmp-expected.txt
diff tmp-expected.txt tmp-write-to-file-multiple-newlines.txt
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# github-actions

## Creating javascript actions
Please follow the official GitHub docs [here](https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action#commit-tag-and-push-your-action-to-github)
and use `@vercel/ncc` to compile the action into one `dist/index.js` file. Do not commmit `node_modules` directory as it contains loads of files.

### TL;DR

* install vercel with `npm install -g @vercel/ncc`
* create `src/index.js` and `action.yml` files
* run `npm install`
* run `ncc build src/index.js`
* commit `src/index.js`, `dist/index.js` and `action.yml`
Loading

0 comments on commit bcd78c3

Please sign in to comment.