Skip to content

Commit

Permalink
Add support for multiple files and properties (#505)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <[email protected]>
  • Loading branch information
fjogeleit authored Oct 10, 2022
1 parent a77606c commit ebdcbcb
Show file tree
Hide file tree
Showing 19 changed files with 3,927 additions and 1,790 deletions.
49 changes: 24 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
with:
valueFile: '__tests__/fixtures/values.yaml'
propertyPath: 'backend.version'
masterBranchName: main
value: v1.0.1
branch: deployment/v1.0.1
targetBranch: main
Expand All @@ -44,6 +45,7 @@ jobs:
valueFile: '__tests__/fixtures/values.yaml'
propertyPath: 'backend.version'
value: v1.2.1
masterBranchName: main
branch: deployment/v1.2.1
targetBranch: main
createPR: 'false'
Expand All @@ -63,6 +65,7 @@ jobs:
valueFile: '__tests__/fixtures/values.yaml'
propertyPath: 'backend.version'
value: v1.0.1
masterBranchName: main
commitChange: 'false'
updateFile: 'true'
- name: Cat Updated values.yaml
Expand All @@ -74,34 +77,28 @@ jobs:
- uses: actions/checkout@v2
- uses: ./
with:
valueFile: '__tests__/fixtures/values.dev.yaml'
propertyPath: 'backend.version'
value: v1.0.1
branch: deployment/test-multi-file-update
createPR: 'false'
message: 'Update DEV Image'
token: ${{ secrets.GH_TOKEN }}
- uses: ./
with:
valueFile: '__tests__/fixtures/values.stage.yaml'
propertyPath: 'backend.version'
value: v1.0.1
branch: deployment/test-multi-file-update
masterBranchName: main
createPR: 'false'
message: 'Update STAGE Image'
token: ${{ secrets.GH_TOKEN }}
- uses: ./
with:
valueFile: '__tests__/fixtures/values.prod.yaml'
propertyPath: 'backend.version'
value: v1.0.1
branch: deployment/test-multi-file-update
targetBranch: main
description: Test GitHub Action
message: 'Update PROD Image'
title: 'Version Update on all Environments'
token: ${{ secrets.GH_TOKEN }}

message: 'Update All Images'
title: 'Version Updates on all Environments'
changes: |
{
"__tests__/fixtures/values.dev.yaml": {
"backend.version": "v1.0.1",
"frontend": true
},
"__tests__/fixtures/values.stage.yaml": {
"backend.version": "v1.0.1",
"frontend": true
},
"__tests__/fixtures/values.prod.yaml": {
"backend.version": "v1.0.1",
"frontend": true
}
}
test-value-types:
runs-on: ubuntu-latest
steps:
Expand All @@ -112,6 +109,7 @@ jobs:
propertyPath: 'config.prod'
value: "!!bool 'true'"
branch: deployment/test-bool-value
masterBranchName: main
targetBranch: main
description: Test GitHub Action
message: 'Update Config'
Expand All @@ -123,6 +121,7 @@ jobs:
propertyPath: 'config.version'
value: "!!int '1234'"
branch: deployment/test-int-value
masterBranchName: main
targetBranch: main
description: Test GitHub Action
message: 'Update Config'
Expand All @@ -142,4 +141,4 @@ jobs:
uses: dawidd6/action-delete-branch@v3
with:
token: ${{ secrets.GH_TOKEN }}
branches: deployment/v1.2.1,deployment/v1.0.1,deployment/test-multi-file-update,deployment/test-bool-value,deployment/test-int-value
branches: deployment/v1.2.1,deployment/v1.0.1,deployment/test-bool-value,deployment/test-int-value,deployment/test-multi-file-update
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ jobs:
|valueFile | relative path from the Workspace Directory | _required_ Field |
|propertyPath| PropertyPath for the new value, JSONPath supported | _required_ Field |
|value | New value for the related PropertyPath | _required_ Field |
|changes | Configure changes on multiple values and/or multiple files. Expects all changes as JSON, supported formats are `{ "filepath": { "propertyPath": "value"}}` and `{ "propertyPath": "value"}`. If you use the second format, it uses the filepath provided from the `valueFile` intput. ||
|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` | . |

|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` | . | |
### Git related Configurations

|Argument | Description | Default |
Expand Down
52 changes: 44 additions & 8 deletions __tests__/action.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as process from 'process'
import * as path from 'path'
import {runTest, YamlNode} from '../src/action'
import {runTest} from '../src/action'
import {YamlNode} from '../src/types'
import {EnvOptions} from '../src/options'

test('test success', async () => {
Expand All @@ -10,10 +11,10 @@ test('test success', async () => {
process.env['VALUE'] = 'v1.1.0'
process.env['BRANCH'] = 'deployment/v1.1.0'

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

expect(json.backend.version).toEqual(process.env['VALUE'])
console.info(yaml)
console.info(content)
})

test('test add new property', async () => {
Expand All @@ -22,7 +23,7 @@ test('test add new property', async () => {
process.env['VALUE_PATH'] = 'frontend.version'
process.env['VALUE'] = 'v1.1.0'

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

expect(json.frontend).toEqual({version: 'v1.1.0'})
})
Expand Down Expand Up @@ -53,7 +54,7 @@ test('test array item change - old syntax', async () => {
process.env['VALUE_PATH'] = 'containers.0.image'
process.env['VALUE'] = 'nginx:alpine'

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

expect(json.containers[0].image).toEqual(process.env['VALUE'])
})
Expand All @@ -64,7 +65,7 @@ test('test array item change - new syntax', async () => {
process.env['VALUE_PATH'] = 'containers[0].image'
process.env['VALUE'] = 'nginx:alpine'

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

expect(json.containers[0].image).toEqual(process.env['VALUE'])
})
Expand All @@ -75,7 +76,7 @@ test('test bool value', async () => {
process.env['VALUE_PATH'] = 'config.prod'
process.env['VALUE'] = "!!bool 'true'"

const {json} = await runTest<{config: {prod: boolean}}>(new EnvOptions())
const [{json}] = await runTest<{config: {prod: boolean}}>(new EnvOptions())

expect(json.config.prod).toEqual(true)
})
Expand All @@ -86,7 +87,42 @@ test('test int value', async () => {
process.env['VALUE_PATH'] = 'config.version'
process.env['VALUE'] = "!!int '123456'"

const {json} = await runTest<{config: {version: number}}>(new EnvOptions())
const [{json}] = await runTest<{config: {version: number}}>(new EnvOptions())

expect(json.config.version).toEqual(123456)
})

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())

expect(json.backend.version).toEqual('v1.1.0')
expect(json.containers[1].image).toEqual('node:alpine')
console.info(content)
})

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}
}`

const results = await runTest<{backend: {version: string}; fronted: boolean; containers: {name: string; image: string}[]}>(new EnvOptions())

expect(results[0].json.backend.version).toEqual('v1.1.0')
expect(results[0].json.containers[1].image).toEqual('node:alpine')
console.info(results[0].content)

expect(results[1].json.backend.version).toEqual('v1.3.0')
expect(results[1].json.frontend).toEqual(true)
console.info(results[1].content)
})
2 changes: 1 addition & 1 deletion __tests__/fixtures/values.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
backend:
version: v1.2.0
frontent: false
frontend: false
config: {}
2 changes: 1 addition & 1 deletion __tests__/fixtures/values.prod.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
backend:
version: v1.2.0
frontent: false
frontend: false
config: {}
2 changes: 1 addition & 1 deletion __tests__/fixtures/values.stage.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
backend:
version: v1.2.0
frontent: false
frontend: false
config: {}
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
value:
required: true
description: 'New property value'
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.'
branch:
required: false
description: 'Branch to commit the change, will be created if not exist'
Expand Down
Loading

0 comments on commit ebdcbcb

Please sign in to comment.