Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to create a file with curly braces using heredoc in GitHub Actions

I want to create on the fly a golang template file in GitHub Actions.

So I am doing more or less the following:

  - name: create the template
      shell: bash
      run: |
        cat <<EOF > myfile.tpl
        \{\{- if . \}\}
        \{\{- range . \}\}
        <h3>Target <code>{{ escapeXML .Target }}</code></h3>
        \{\{- if (eq (len .Vulnerabilities) 0) \}\}
        <h4>No Vulnerabilities found</h4>
        .
        .
        \{\{- end \}\}
        EOF

However, apart from the fact that I get errors when trying to use it, when I cat it I get the following

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

\***\***- if . \***\***
\***\***- range . \***\***
<h3>Target <code>*** escapeXML .Target ***</code></h3>
\***\***- if (eq (len .Vulnerabilities) 0) \***\***
<h4>No Vulnerabilities found</h4>

What is the proper way of going about it?

>Solution :

For create agolang template file in GitHub Actions workflow without the special characters being escaped. Use a different delimiter to the heredoc that prevents interpretation of the special characters. You can achieve this using EOF or another delimiter with quotes. Try the below way, it will be correct.

- name: Create the template
  shell: bash
  run: |
    cat <<'EOF' > myfile.tpl
{{- if . }}
{{- range . }}
<h3>Target <code>{{ escapeXML .Target }}</code></h3>
{{- if (eq (len .Vulnerabilities) 0) }}
<h4>No Vulnerabilities found</h4>
.
.
{{- end }}
{{- end }}
EOF
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading