fjogeleit / yaml-update-action

Update YAML property with dynamic values

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error due to Hypen(-) in key name in yaml

prabhat-kumar-ts opened this issue · comments

Not updating yaml file due to hyphen in key name and generating error.

Run fjogeleit/yaml-update-action@main
  with:
    repository: xxx/test-repo
    workDir: release
    valueFile: manifest.yaml
    propertyPath: app.test-repo
    value: v1.3.5
    branch: develop
    targetBranch: develop
    createPR: false
    message: Update Image Version to v1.3.5
    token: ***
    noCompatMode: false
    quotingType: '
    force: false
    masterBranchName: master
    githubAPI: https://api.github.com
    commitChange: true
    updateFile: false
    labels: yaml-updates
    commitUserName: github-actions[bot]
    commitUserEmail: 41898[2](https://github.com/xxxx/test-repo/actions/runs/781150244/job/21433313884#step:5:2)82+github-actions[bot]@users.noreply.github.com

Error: failed to create PR: Error: Lexical error on line 1. Unrecognized text.
$.app.test-repo
----------^

Please check e.g #433

@prabhat-kumar-ts Hi, fellas.

In my case, I found the perfect solution for handling jsonPath:


Solution

The value structure of the helm chart I was trying to change is as follows:

# example-chart/values.yaml
...
podLabels:
  restarting-trigger-salt: '0434'

I observed that setting propertyPath to '.podLabels.restarting-trigger-salt' or .podLabels[restart-trigger-salt] does not work.

# Error log for Github Actions Workflow
2024-05-08T04:24:10.8095603Z ##[error]Error: Parse error on line 1:
$..podLabels[restarting-trigger-s
-------------^
Expecting 'STAR', 'SCRIPT_EXPRESSION', 'INTEGER', 'ARRAY_SLICE', 'FILTER_EXPRESSION', 'QQ_STRING', 'Q_STRING', got 'IDENTIFIER'

To make it work properly, propertyPath must be wrapped in double quotes, such as '.podLabels["restarting-trigger-salt"]'.

- '.podLabels[restarting-trigger-salt]'
+ '.podLabels["restarting-trigger-salt"]'

In Actions Workflow, the normally executed yaml update step is as follows.

# .github/workflows/yaml-update.yml
      - name: Update helm chart
        uses: actions/yaml-update-action@main
        with:
          valueFile: ${{ inputs.application }}/values.yaml
          propertyPath: '.podLabels["restarting-trigger-salt"]'
          value: ${{ env.RESTART_TRIGGER_SALT }}

Related issue

#567, #433