fjogeleit / yaml-update-action

Update YAML property with dynamic values

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to: Update the Version Array

RobinSCU opened this issue · comments

Hi,

we have the case that our version Field is an array of versions because we always want to have the last two versions on K8s.
Do you have a quick example of how we can archive this? Is it possible to use values from the property path?

Something like this:

 - name: Update Image Version in the related HelmChart values.yaml
        uses: fjogeleit/yaml-update-action@main
        with:
          valueFile: 'deployment/helm/values.yaml'
          propertyPath: 'backend.versions'
          value: [${{ steps.image.outputs.version }}, backend.versions.0] # uses the last "latest" version as new secondary and removes the old secondary
          branch: deployment/${{ steps.image.outputs.version }}
          targetBranch: development
          createPR: true
          message: 'Update Image Version to ${{ steps.image.outputs.version }}' 

Thanks for your help!
Robin

Hey, currently value does not support arrays as value and references to YAML values.. What you could do is to split your YAML in to multiple steps.

You could use yq to read and save the current value (https://mikefarah.gitbook.io/yq/v/v4.x/usage/github-action) and then update your YAML with 2 update action steps.

 - name: Get last Version
    id: lookupLastVersion
    uses: mikefarah/yq@master
    with:
          cmd: yq '. backend.versions.0' 'deployment/helm/values.yaml'

 - name: Update Image Version in the related HelmChart values.yaml
    uses: fjogeleit/yaml-update-action@main
    with:
          valueFile: 'deployment/helm/values.yaml'
          propertyPath: 'backend.versions[0]'
          value: ${{ steps.image.outputs.version }}
          branch: deployment/${{ steps.image.outputs.version }}
          message: 'Update Image Version to ${{ steps.image.outputs.version }}'

 - name: Update Image Version in the related HelmChart values.yaml
    uses: fjogeleit/yaml-update-action@main
    with:
          valueFile: 'deployment/helm/values.yaml'
          propertyPath: 'backend.versions[1]'
          value: ${{ steps.image.outputs.version }}
          branch: deployment/${{ steps.image.outputs.version }}
          targetBranch: development
          createPR: true
          message: 'Update Image Version to ${{ steps.lookupLastVersion.outputs.result }}'

Something like this should work with the current implementation and features.

Thanks for your answer! It helps us a lot!

Great, let me know if you still need help or anything does not work as expected.