如何解决GitHub动作:仅对某些请求请求基础分支运行步骤
从很长一段时间以来,我一直在从事GitHub Actions的工作,并且我们有一个指定的工作流程。工作流程已使用yaml编写。
我正在尝试为if
设置一些github.ref
条件,并且在运行时跳过了yaml块。
这意味着-如果对X分支提出了pull请求-该代码块应运行。
类似这样的东西:
- name: Branch name check - Running only for DEV branch..
if: ${{contains(github.ref,'DEV*')}}
uses: mathrix-education/sonar-scanner@master
with:
version: 4.2.0.1873 # required
typescript: false
scan: true
有人可以帮我吗?
解决方法
使用以下命令检查拉取请求的基础:
if: ${{contains(github.base_ref,'DEV')}}
github.ref
将包含类似refs/pull/1/merge
的请求请求。
在构建github工作流程时,我们遇到了类似的事情。我们正在工作的条件:
- 我们希望第1步仅在推送或拉取请求上运行才能开发。
- 我们希望第2步仅对主请求请求执行。
- 步骤必须在单个工作流程中。yaml。
经过研究,以下是我们提出的内容。我发现Github Actions非常灵活,具有许多Gitlab和Bitbucket没有的选项。但这也是不利的一面,有时会使理解变得更加复杂。
---
name: workflow
on:
push:
branches: [develop]
pull_request:
branches: [develop,master]
types: [closed]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v1
- name: step 1
if: github.ref == 'refs/heads/develop' || github.event.pull_request.base.ref == 'develop'
run: echo "Hello develop"
- name: step 2
if: github.event.pull_request.base.ref == 'master'
run: echo "Hello master"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。