代码之家  ›  专栏  ›  技术社区  ›  pkaramol

无法在GitHub操作中使用heredoc创建带大括号的文件

  •  -1
  • pkaramol  · 技术社区  · 1 年前

    我想在飞行中创建 golang GitHub Actions中的模板文件。

    因此,我或多或少地在做以下事情:

      - 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
    

    然而,除了我在尝试使用它时会出错之外,当我 cat 它我得到以下

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

    做这件事的正确方法是什么?

    1 回复  |  直到 1 年前
        1
  •  1
  •   Isuru Bandara    1 年前

    用于创建 agolang GitHub Actions工作流中没有转义特殊字符的模板文件。对heredoc使用不同的分隔符,以防止解释特殊字符。您可以使用EOF或另一个带引号的分隔符来实现这一点。试试下面的方法,它将是正确的。

    - 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