Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
"@typescript-eslint/unbound-method": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"]
},
"env": {
"node": true,
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ jobs:
|labels | Comma separated list of labels, e.g. "feature, yaml-updates" | 'yaml-updates' |
|updateFile | By default the actual file is not updated, to do so set this property to 'true' | `false` |
|workDir | relative location of the configured `repository` | . | |
|method | Configures the processing of none existing properties. Possible values: `CreateOrUpdate`, `Update`, `Create` | `CreateOrUpdate` |

#### Methods

Determine the behavior for none existing properties or array elements.

| Enum | Description |
|----------------|-------------|
| CreateOrUpdate | Updates existing values or creates them if not available |
| Update | Updates existing values, skips the change if not |
| Create | Creates none existing values, skips the change if the property already exists |

### Git related Configurations

|Argument | Description | Default |
Expand Down
77 changes: 70 additions & 7 deletions __tests__/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import {runTest} from '../src/action'
import {YamlNode} from '../src/types'
import {EnvOptions} from '../src/options'

afterEach(() => {
process.env['VALUE_FILE'] = ''
process.env['VALUE_PATH'] = ''
process.env['VALUE'] = ''
process.env['METHOD'] = ''
process.env['CHANGES'] = ''
process.env['WORK_DIR'] = '__tests__'
})

test('test success', async () => {
process.env['VALUE_FILE'] = 'fixtures/values.yaml'
process.env['WORK_DIR'] = '__tests__'
Expand All @@ -28,6 +37,43 @@ test('test add new property', async () => {
expect(json.frontend).toEqual({version: 'v1.1.0'})
})

test('test ignore not existing property for method update', async () => {
process.env['VALUE_FILE'] = 'fixtures/values.yaml'
process.env['WORK_DIR'] = '__tests__'
process.env['VALUE_PATH'] = 'frontend.version'
process.env['VALUE'] = 'v1.1.0'
process.env['METHOD'] = 'update'

const updatedFiles = await runTest<{backend: {version: string}; frontend: YamlNode}>(new EnvOptions())

expect(updatedFiles.length).toEqual(0)
})

test('test create not existing property for method create', async () => {
process.env['VALUE_FILE'] = 'fixtures/values.yaml'
process.env['WORK_DIR'] = '__tests__'
process.env['VALUE_PATH'] = 'frontend.version'
process.env['VALUE'] = 'v1.1.0'
process.env['METHOD'] = 'create'

const [{json}] = await runTest<{backend: {version: string}; frontend: YamlNode}>(new EnvOptions())

expect(json.frontend).toEqual({version: 'v1.1.0'})
})

test('test ignore existing property for method create', async () => {
process.env['VALUE_FILE'] = 'fixtures/values.yaml'
process.env['WORK_DIR'] = '__tests__'
process.env['VALUE_PATH'] = 'backend.version'
process.env['VALUE'] = 'v1.1.0'
process.env['BRANCH'] = 'deployment/v1.1.0'
process.env['METHOD'] = 'create'

const updatedFiles = await runTest<{backend: {version: string}; frontend: YamlNode}>(new EnvOptions())

expect(updatedFiles.length).toEqual(0)
})

test('test yaml file path error', async () => {
process.env['VALUE_FILE'] = 'fixtures/not-exist.yaml'
process.env['WORK_DIR'] = '__tests__'
Expand Down Expand Up @@ -94,9 +140,6 @@ test('test int value', async () => {

test('multiple changes in one file', async () => {
process.env['VALUE_FILE'] = 'fixtures/values.yaml'
process.env['VALUE_PATH'] = ''
process.env['VALUE'] = ''
process.env['WORK_DIR'] = '__tests__'
process.env['CHANGES'] = '{"backend.version": "v1.1.0", "containers[1].image": "node:alpine"}'

const [{json, content}] = await runTest<{backend: {version: string}; containers: {name: string; image: string}[]}>(new EnvOptions())
Expand All @@ -107,10 +150,6 @@ test('multiple changes in one file', async () => {
})

test('multiple changes in multiple files', async () => {
process.env['VALUE_FILE'] = ''
process.env['VALUE_PATH'] = ''
process.env['VALUE'] = ''
process.env['WORK_DIR'] = '__tests__'
process.env['CHANGES'] = `{
"fixtures/values.yaml": {"backend.version": "v1.1.0", "containers[1].image": "node:alpine"},
"fixtures/values.prod.yaml": {"backend.version": "v1.3.0", "frontend": true}
Expand All @@ -126,3 +165,27 @@ test('multiple changes in multiple files', async () => {
expect(results[1].json.frontend).toEqual(true)
console.info(results[1].content)
})

test('append array node', async () => {
process.env['CHANGES'] = `{
"fixtures/values.yaml": {
"containers[(@.length)]": { "name": "database", "image": "postgres:alpine" }
}
}`

const [{json}] = await runTest<{containers: {name: string; image: string}[]}>(new EnvOptions())

expect(json.containers[2]).toEqual({name: 'database', image: 'postgres:alpine'})
})

test('append array node on index', async () => {
process.env['CHANGES'] = `{
"fixtures/values.yaml": {
"containers[2]": { "name": "database", "image": "postgres:alpine" }
}
}`

const [{json}] = await runTest<{containers: {name: string; image: string}[]}>(new EnvOptions())

expect(json.containers[2]).toEqual({name: 'database', image: 'postgres:alpine'})
})
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ inputs:
description: 'YAML file which should be updated'
propertyPath:
required: true
description: 'Property Path - using dot for nesting: e.g. backend.version'
description: 'Property Path - valid jsonPath expression'
value:
required: true
description: 'New property value'
method:
required: false
description: 'Configures the processing of none existing properties. Possible values: CreateOrUpdate, Update, Create'
changes:
required: false
description: 'Map of changes for a single or multiple files as JSON. Supports following formats: { "filepath": {"propertyPath": "value"}} or {"propertyPath": "value"}. If filepath is not provided it fallsback to the path configured under valueFile.'
Expand Down
70 changes: 65 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading