Skip to content

Commit cc8c639

Browse files
committed
Fix array parsing
1 parent dc9697e commit cc8c639

File tree

6 files changed

+25
-26
lines changed

6 files changed

+25
-26
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
filename: 'test.json'
1616
prefix: test
1717
- name: Show output
18-
run: echo "The time was ${{ env.test_value }}, ${{ env.test_array_0_ }}, ${{ env.test_obj_value1 }}"
18+
run: echo "The time was ${{ env.test_value }}, ${{ env.test_array_0_value }}, ${{ env.test_obj_value1 }}"

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ The prefix. Default value `json`.
1414
## Usage
1515

1616
### File content
17-
```
17+
```json
1818
{
1919
"value": "value",
2020
"array": [
21-
"value 0",
21+
{
22+
"value": "value 0"
23+
},
2224
"value 1"
2325
],
2426
"obj": {
@@ -29,12 +31,12 @@ The prefix. Default value `json`.
2931
```
3032

3133
### YML example
32-
```
34+
```yml
3335
- name: JSON to variables
34-
uses: antifree/[email protected].0
36+
uses: antifree/[email protected].1
3537
with:
3638
filename: 'test.json'
3739
prefix: test
3840
- name: Show output
39-
run: echo "The time was ${{ env.test_value }}, ${{ env.test_array_0_ }}, ${{ env.test_obj_value1 }}"
41+
run: echo "The time was ${{ env.test_value }}, ${{ env.test_array_0_value }}, ${{ env.test_obj_value1 }}"
4042
```

dist/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,25 @@ try {
1414
const prefix = core.getInput('prefix') || 'json';
1515

1616
const fullPath = path.resolve(fileName);
17-
console.log(`Processing file: ${fullPath}`);
17+
core.info(`Processing file: ${fullPath}`);
1818

1919
const rawdata = fs.readFileSync(fullPath);
2020
const rootObj = JSON.parse(rawdata);
2121

22-
const provessVariable = (variable, name) => {
22+
const processVariable = (variable, name) => {
2323

2424
if (typeof variable === 'undefined' || variable === null) {
2525
return;
2626
}
2727

28-
if (Array.isArray(variable)) {
29-
28+
if (Array.isArray(variable)) {
3029
variable.forEach((value, index) => {
31-
provessVariable(value, `${name}_${index}_`);
30+
processVariable(value, `${name}_${index}`);
3231
});
33-
3432
}
3533
else if (typeof variable === 'object') {
3634
for(const field in variable) {
37-
provessVariable(variable[field], `${name}_${field}`);
35+
processVariable(variable[field], `${name}_${field}`);
3836
}
3937
}
4038
else {
@@ -43,9 +41,8 @@ try {
4341
}
4442
};
4543

46-
provessVariable(rootObj, prefix);
44+
processVariable(rootObj, prefix);
4745

48-
4946
} catch (error) {
5047
core.setFailed(error.message);
5148
}

index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@ try {
77
const prefix = core.getInput('prefix') || 'json';
88

99
const fullPath = path.resolve(fileName);
10-
console.log(`Processing file: ${fullPath}`);
10+
core.info(`Processing file: ${fullPath}`);
1111

1212
const rawdata = fs.readFileSync(fullPath);
1313
const rootObj = JSON.parse(rawdata);
1414

15-
const provessVariable = (variable, name) => {
15+
const processVariable = (variable, name) => {
1616

1717
if (typeof variable === 'undefined' || variable === null) {
1818
return;
1919
}
2020

21-
if (Array.isArray(variable)) {
22-
21+
if (Array.isArray(variable)) {
2322
variable.forEach((value, index) => {
24-
provessVariable(value, `${name}_${index}_`);
23+
processVariable(value, `${name}_${index}`);
2524
});
26-
2725
}
2826
else if (typeof variable === 'object') {
2927
for(const field in variable) {
30-
provessVariable(variable[field], `${name}_${field}`);
28+
processVariable(variable[field], `${name}_${field}`);
3129
}
3230
}
3331
else {
@@ -36,9 +34,8 @@ try {
3634
}
3735
};
3836

39-
provessVariable(rootObj, prefix);
37+
processVariable(rootObj, prefix);
4038

41-
4239
} catch (error) {
4340
core.setFailed(error.message);
4441
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "json-to-variables",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "This action reads json file and writes its content as environment variables",
55
"main": "index.js",
66
"scripts": {
7+
"build": "ncc build index.js --license licenses.txt",
78
"test": "echo \"Error: no test specified\" && exit 1"
89
},
910
"repository": {

test.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"value": "value",
33
"array": [
4-
"value 0",
4+
{
5+
"value": "value 0"
6+
},
57
"value 1"
68
],
79
"obj": {

0 commit comments

Comments
 (0)