sethvargo / ratchet

A tool for securing CI/CD workflows with version pinning.
Apache License 2.0
771 stars 32 forks source link

github actions run: step re-format #27

Closed sbe-arg closed 2 years ago

sbe-arg commented 2 years ago

TL;DR

When running pin against a github actions step that has

- shell: bash
  run: |
    echo 1
    echo 2
    echo 3

ratchet converts this block into

- shell: bash
  run: "echo 1 echo 2 echo 3"

unsure why is breaking this formating

is there a way to exclude the run: blocks from being reformated?

Expected behavior

don't reformat code inside run: blocks

Observed behavior

run blocks modified when they should not

Version

0.2.3

On what operating system are you using ratchet?

Linux

CI/CD workflow file

No response

Relevant log output

No response

Additional information

No response

sbe-arg commented 2 years ago

maybe something like a flag to skip yaml reformating/prettier altogether

sethvargo commented 2 years ago

Hi @sbe-arg

This is a duplicate of https://github.com/sethvargo/ratchet/issues/14 and noted in the README's known issues.

The library we use to parse the YAML into an AST tree does not preserve whitespace or indentation, so unfortunately there's nothing Ratchet can do here. The original version of YAML did regex-based replacements on the file, but that proved to be extremely error-prone, so now it parses and re-renders the AST tree.

The example you provided is concerning, since it's actually a different representation of the data. Are you able to reproduce this issue using the library natively? If so, I would recommend filing an issue there: https://github.com/go-yaml/yaml/issues/new