yaml-update-action icon indicating copy to clipboard operation
yaml-update-action copied to clipboard

Questions regarding forceing numberic values to be quoted

Open visdmin opened this issue 9 months ago • 1 comments

Here's the corrected version of your GitHub issue with typos fixed:


Hello,

I am trying to update a .yaml file containing container image tags. My container image tags are in the following format: 1.0.0.

The value 1.0.0 is understandably a numeric value from the standpoint of .yaml, but for my use case, it is very important that I would be able to write these values as strings, because the difference between tag: 1.0.0 and tag: "1.0.0" may cause issues or unexpected behavior later where the .yaml file is used.

Example usage:

File to be edited example.yaml:

foo:
  image:
    name: foo-image
    tag: "0.1.0"
bar:
  image:
    name: bar-image
    tag: "0.1.0"

I have steps in my workflow job that capture the values that I want to use for updating the example.yaml file, for this example both of these values are set to 1.0.0 (steps.capture_image_tag_foo.outputs.result & steps.capture_image_tag_bar.outputs.result)

- name: Update image tags
  uses: fjogeleit/yaml-update-action@main
  with:
    valueFile: example.yaml
    changes: |
      {
        "foo.image.tag":"${{ steps.capture_image_tag_foo.outputs.result }}",
        "bar.image.tag":"${{ steps.capture_image_tag_bar.outputs.result }}"
      }
    quotingType: '"'
    commitChange: true
    createPR: true

The resulting pull request contains the changes but of course, the image tag values are written to the example.yaml without quotes. Resulting example.yaml file:

foo:
  image:
    name: foo-image
    tag: 1.0.0
bar:
  image:
    name: bar-image
    tag: 1.0.0

Target:

Here is the resulting example.yaml file that I would like to achieve:

foo:
  image:
    name: foo-image
    tag: "1.0.0"
bar:
  image:
    name: bar-image
    tag: "1.0.0"

What have I tried so far:

I have tried using the yaml tags to specify the type for my values as mentioned in the README.md https://github.com/fjogeleit/yaml-update-action?tab=readme-overview-file#known-issues

Example:

- name: Update image tag foo
  uses: fjogeleit/yaml-update-action@main
  with:
    valueFile: example.yaml
    propertyPath: foo.image.tag
    value: "!!str '${{ steps.capture_image_tag_foo.outputs.result }}'"
    quotingType: '"'
    commitChange: false

- name: Update image tag bar and create PR
  uses: fjogeleit/yaml-update-action@main
  with:
    valueFile: example.yaml
    propertyPath: bar.image.tag
    value: "!!str '${{ steps.capture_image_tag_bar.outputs.result }}'"
    quotingType: '"'
    commitChange: true
    createPR: true

But this approach did not seem to affect the resulting edited .yaml file at all.

If anyone has any ideas how I could achieve the result I am looking for, please help me, thank you!

visdmin avatar May 17 '24 12:05 visdmin