-
Notifications
You must be signed in to change notification settings - Fork 2
139 lines (122 loc) · 4.14 KB
/
test-replace-string.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
name: Test replace-string action
on:
pull_request:
branches:
- main
push:
branches:
- main
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
main:
name: Test replace-string action
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Replace string
id: str
uses: ./replace-string
with:
string: 'Apple Redberry'
replace-regex: 'Redberry'
flags: 'g'
replace-with: 'Apricot'
- name: Check replaced string
shell: bash
run: |
if [[ '${{ steps.str.outputs.replaced-string }}' != 'Apple Apricot' ]]; then
echo '!!! Action failed to make simple string replacement'
exit 1
fi
- name: Create a dummy file to read from
shell: bash
run: |
echo -n 'Apricot Blueberry' > tmp-read-from-file.txt
- name: Replace string from file
id: from-file
uses: ./replace-string
with:
read-from-file: 'tmp-read-from-file.txt'
replace-regex: 'Blue'
flags: 'g'
replace-with: 'Red'
- name: Check replaced string
shell: bash
run: |
if [[ '${{ steps.from-file.outputs.replaced-string }}' != 'Apricot Redberry' ]]; then
echo '!!! Action failed to replace string from a file'
exit 1
fi
- name: Create an output to read from
shell: bash
id: output
run: |
echo "read-me=Cranberry and green apple" >> $GITHUB_OUTPUT
- name: Replace string from output and write to file
uses: ./replace-string
with:
string: ${{ steps.output.outputs.read-me }}
replace-regex: 'green'
flags: 'g'
replace-with: 'red'
write-to-file: 'tmp-write-to-file.txt'
- name: Check replaced string
shell: bash
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'
- name: Check newline replacement
shell: bash
run: |
if [[ '${{ steps.replace-newlines.outputs.replaced-string }}' != 'Line without anything to replace%The following should contain an apple: __APPLE__ is red%And the following shall be \\'$AZERO\\': __CURRENCY__%Thanks!' ]]; then
echo "!!! Action failed to replace newline characters"
exit 1
fi