testing - 如何使用“deployment_status”小猫并且仅在 QAS 分支上运行 Github Actions?
问题描述
我需要 github 操作仅在 QAS 分支上运行并部署事件。它应该在“pull_request”和“pull”上运行,并且只能在 QAS 分支上运行。
name: Cypress
on: [deployment_status]
jobs:
e2e:
if: github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
steps:
- name: Print URL
run: echo Testing URL ${{ github.event.deployment_status.target_url }}
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2-beta
with:
node-version: 14
- name: Install modules
run: yarn
- name: Run Cypress
uses: cypress-io/github-action@v2
但我想要这样的东西:
name: Cypress
on:
deployment_status:
pull_request:
branches:
- qas
push:
branches:
- qas
jobs:...
解决方案
目前无法单独使用触发器条件来实现您想要的。这是因为这些条件被配置为作为OR
而不是作为AND
。
在这种情况下,一种解决方法是使用一个触发条件 -例如on: [deployment_status]
您当前正在使用的 - 然后在作业级别添加一个过滤器,以根据github.ref
来自Github Context的 来检查分支名称。
在你的情况下,我想它看起来像这样:
name: Cypress
on: [deployment_status]
jobs:
e2e:
if: ${{ github.event.deployment_status.state == 'success' && github.ref == 'refs/heads/qas' }}
runs-on: ubuntu-latest
steps:
[...]
注意:让我知道是否job if condition
按预期工作(我没有配置 webhook 的 poc 存储库也可以尝试使用github.event.deployment_status.state
)。
注意 2:可能不需要使用${{ }}
around 条件:
if: github.event.deployment_status.state == 'success' && github.ref == 'refs/heads/qas'
推荐阅读
- sql-server - 如何判断更新是否成功
- wysiwyg - 添加列出所有文档的自定义图标,单击时应将其添加为链接
- python - 如何使用 Pymongo 将带有 collection.update_many() 的文档插入到 Collection (MongoDB) 中(不重复)
- php - 如果 PHP 中的运算符无法正常工作
- python - 加载冻结推理图以进行张量优化时无法导入元图
- php - SQL 在查询中获取所有用户活动的总和
- c# - Entity Framework Core - ForeingKey 显示空值
- r - 创建一个新变量,它是一个变量以其他两个变量为条件的平均值(并维护数据集中的所有其他变量)
- xml - 如何根据条件跳过 XML 中的节点并将该值添加到具有匹配条件的节点中
- shell - 如何避免在ggsci中删除重复时出现提示