Essentially this is a question about best practice in Terraform YAML documents, and is probably only about formatting conventions, but I also want to check about GitHub and bash
behaviour.
I've encountered a bash
script inside a YAML document that's run as part of a GitHub Actions workflow, and the block is introduced with a "chomp" modifier:
- name: Terraform Apply
run: |-
TAGS=${{needs.tags.outputs.NEW_TAG_VERSION}}
export SOMEVAR='hello'
export ANOTHERVAR='etc'
...
aws s3 crucial operation
I'm somewhat new to this application area for YAML, and the particular GitHub implementation, so I want to confirm that given my expected treatment of the bash
script by GitHub, whether there are any genuine reasons why a "chomp" indicator is necessary or useful and whether there are any risks in omitting it:
- Using the "chomp" operator will strip the final newline from the script
- Using the "chomp" operator will not strip intervening newlines from the script
- The script will therefore run fine, including the last command
- That is, the last command runs even though there's no newline there, because it's run as a
bash
script, not as a sequence of typed-in commands - However, there's no need to strip the last newline, the script will run with a trailing newline just as well
- But in fact, having a newline at the end of your script is the normal expectation and fits canonical approaches more uniformly
So if this is all true, there's no reason at all to add the chomp modifier, and following normal expectations it's marginally better without it, and 1 less character to boot, and one less thing to think about. So the script should rather be introduced with run: |
, not run: |-
.
If not, what does the "chomp" modifier achieve for this use-case?