You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 09:24:04