在GitHub工作流中的流水线处理

huangapple go评论63阅读模式
英文:

Pipelining in github workflows

问题

如何在GitHub工作流中使用管道处理?我在从github.event.issue.body中查找模式时遇到了困难。

下面是我尝试过的代码:
图片描述

在运行时,我收到了错误消息"-e: command not found"。

英文:

How do I use pipelining in github workflows? I was having difficulty while finding patterns from from github.event.issue.body.

Below one is the one I tried.enter image description here While running it, I am getting the error "-e: command not found".

答案1

得分: 0

这似乎是由于grep命令及其格式引起的。基本上有一些语法问题(关于如何从stdout分配值给变量),然后grep命令将根据您提供的格式搜索文件。即使您纠正了语法,这也会失败,因为没有与${{ github.event.issue.body }}的输出相对应的文件。为了避免这种文件搜索,您可以使用管道。您的环境分配中有空格,但它应该是echo "a=b"而不是echo "a = b"。另一件事是,包含查询中的'[Proposal]'可能会始终评估为false(我不是百分之百确定,但在我测试时确实是这样),所以您可能希望将其更改为'Proposal'(或'proposal',因为它是不区分大小写的)。因此,您可以像这样重写整个内容:

- name: <your-step-name>
  run: |
    echo "has_proposal_label=${{ contains(github.event.issue.title, 'proposal') }}" >> $GITHUB_OUTPUT
    category3=$(echo "${{ github.event.issue.body }}" | grep -e "Category" -A2 | grep -v "Category" | grep "\S")
    echo "category<<EOF" >> $GITHUB_OUTPUT
    echo "$category3" >> $GITHUB_OUTPUT
    echo "EOF" >> $GITHUB_OUTPUT

这假设您的类别输出将有多行,但如果您没有多行而只有一行,那么您可以简单地执行echo "category=$category3" >> $GITHUB_OUTPUT

英文:

This seems to be because of the grep commands and their format. Basically there are some syntax issues (with how you are assigning the values to the varibale from stdout) and then the grep command will search for files as per your given format. Even if you correct the syntax this will fail because there are no such file corresponding to the output of ${{ github.event.issue.body }}. To avoid this file search you can use pipes. You have whitespaces in your env assignment, but it should be echo &quot;a=b&quot; instead of echo &quot;a = b&quot;. Another thing is, &#39;[Proposal]&#39; in the contains query might always evaluate to false (I am not a hundred percent sure regarding this but it indeed was so when I tested it out) so you might want to change it to &#39;Proposal&#39; (or &#39;proposal&#39; as it is case insensitive). Hence you can rewrite the whole thing like this:

- name: &lt;your-step-name&gt;
  run: |
    echo &quot;has_proposal_label=${{ contains(github.event.issue.title, &#39;proposal&#39;) }}&quot; &gt;&gt; $GITHUB_OUTPUT
    category3=$(echo &quot;${{ github.event.issue.body }}&quot; | grep -e &quot;Category&quot; -A2 | grep -v &quot;Category&quot; | grep &quot;\S&quot;)
    echo &quot;category&lt;&lt;EOF&quot; &gt;&gt; $GITHUB_OUTPUT
    echo &quot;$category3&quot; &gt;&gt; $GITHUB_OUTPUT
    echo &quot;EOF&quot; &gt;&gt; $GITHUB_OUTPUT

This assumes your category output will have multiple lines, but if you don't have and it is a single line, then you can simply do echo &quot;category=$category3&quot; &gt;&gt; $GITHUB_OUTPUT.

huangapple
  • 本文由 发表于 2023年6月19日 18:15:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76505652.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定