Skip to content

Commit 1c3b431

Browse files
authored
Merge pull request #425 from fjogeleit/implement-jsonpath
Use JSONPath for value updates
2 parents 036e48d + c2fc74b commit 1c3b431

File tree

12 files changed

+20535
-5547
lines changed

12 files changed

+20535
-5547
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
|Argument | Description | Default |
8585
|----------|---------------|-----------|
8686
|valueFile | relative path from the Workspace Directory| _required_ Field |
87-
|propertyPath| PropertyPath for the new value | _required_ Field |
87+
|propertyPath| PropertyPath for the new value, JSONPath supported | _required_ Field |
8888
|value | New value for the related PropertyPath| _required_ Field |
8989
|repository| The Repository where the YAML file is located and should be updated. You have to checkout this repository too and set the working-directory for this action to the same as the repository. See the example below | ${{github.repository}} |
9090
|commitChange| Commit the change to __branch__ with the given __message__ | true |

__tests__/action.test.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as process from 'process'
22
import * as path from 'path'
3-
import {runTest} from '../src/action'
3+
import {runTest, YamlNode} from '../src/action'
44
import {EnvOptions} from '../src/options'
55

66
test('test success', async () => {
@@ -10,19 +10,21 @@ test('test success', async () => {
1010
process.env['VALUE'] = 'v1.1.0'
1111
process.env['BRANCH'] = 'deployment/v1.1.0'
1212

13-
const {json, yaml} = await runTest<{backend: {version: string}; frontend: boolean}>(new EnvOptions())
13+
const {json, yaml} = await runTest<{backend: {version: string}; frontend: YamlNode}>(new EnvOptions())
1414

1515
expect(json.backend.version).toEqual(process.env['VALUE'])
1616
console.info(yaml)
1717
})
1818

19-
test('test yaml value path error', async () => {
19+
test('test add new property', async () => {
2020
process.env['VALUE_FILE'] = 'fixtures/values.yaml'
2121
process.env['WORK_DIR'] = '__tests__'
2222
process.env['VALUE_PATH'] = 'frontend.version'
2323
process.env['VALUE'] = 'v1.1.0'
2424

25-
expect(runTest(new EnvOptions())).rejects.toThrowError('invalid property path - frontend is not an object')
25+
const {json} = await runTest<{backend: {version: string}; frontend: YamlNode}>(new EnvOptions())
26+
27+
expect(json.frontend).toEqual({version: 'v1.1.0'})
2628
})
2729

2830
test('test yaml file path error', async () => {
@@ -44,3 +46,25 @@ test('test yaml file parse error', async () => {
4446

4547
expect(runTest(new EnvOptions())).rejects.toThrowError(`could not parse content as YAML`)
4648
})
49+
50+
test('test array item change - old syntax', async () => {
51+
process.env['VALUE_FILE'] = 'fixtures/values.yaml'
52+
process.env['WORK_DIR'] = '__tests__'
53+
process.env['VALUE_PATH'] = 'containers.0.image'
54+
process.env['VALUE'] = 'nginx:alpine'
55+
56+
const {json, yaml} = await runTest<{containers: Array<{name: string; image: string}>}>(new EnvOptions())
57+
58+
expect(json.containers[0].image).toEqual(process.env['VALUE'])
59+
})
60+
61+
test('test array item change - new syntax', async () => {
62+
process.env['VALUE_FILE'] = 'fixtures/values.yaml'
63+
process.env['WORK_DIR'] = '__tests__'
64+
process.env['VALUE_PATH'] = 'containers[0].image'
65+
process.env['VALUE'] = 'nginx:alpine'
66+
67+
const {json, yaml} = await runTest<{containers: Array<{name: string; image: string}>}>(new EnvOptions())
68+
69+
expect(json.containers[0].image).toEqual(process.env['VALUE'])
70+
})

__tests__/fixtures/values.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
backend:
22
version: v1.2.0
3-
frontent: false
3+
frontend: {}
4+
containers:
5+
- name: nginx
6+
image: nginx:latest
7+
- name: node
8+
image: node:latest
49
config: {}

dist/action.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/esprima.js

Lines changed: 3756 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)