英文:
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 "a=b"
instead of echo "a = b"
. Another thing is, '[Proposal]'
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 'Proposal'
(or 'proposal'
as it is case insensitive). Hence you can rewrite the whole thing like this:
- 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
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 "category=$category3" >> $GITHUB_OUTPUT
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论