GitHub Actions中如何用逻辑与判断多个正则匹配均不成立
错误原因
GitHub Actions 表达式语法中,逻辑与运算符为双&&而非单&,单个&不属于表达式支持的合法逻辑运算符,因此会触发语法识别失败。
修正方案
你可以直接将逻辑运算符替换为&&即可实现「所有正则都匹配失败时触发」的逻辑,修正后的步骤代码如下:
- name: Failure if: ${{ steps.fix-match.outputs.match == '' && steps.refactor-match.outputs.match == '' && steps.feature-match.outputs.match == '' }} run: exit 1
可选简化写法
由于正则匹配失败时match输出为空字符串,属于 GitHub Actions 表达式中的 falsy 值,你也可以通过取反运算符进一步简化判断逻辑,效果完全一致:
- name: Failure if: ${{ !steps.fix-match.outputs.match && !steps.refactor-match.outputs.match && !steps.feature-match.outputs.match }} run: exit 1
注:GitHub Actions 会自动解析
if字段的内容为表达式,你也可以省略外层的${{ }}包裹,写法同样合法。
内容的提问来源于stack exchange,提问作者Alex Petrosyan
相关产品推荐
相关产品推荐

