GitHub工作流程:每个不同的git动作一项工作(按master,push标签...)

时间:2020-08-02 19:35:03

标签: github github-actions

我想设置我的工作流程以执行以下操作:

  • 在任何情况下(拉动请求,在任何分支上推送)
    • 结帐代码
    • 构建项目
    • 运行测试
    • 上传其他作业的工件
  • 仅当主控被按下时
    • 从以前的工作中下载工件
    • 推送GH页面
  • 仅在按下标签时
    • 从以前的工作中下载工件
    • 创建发行版
    • 将工件上传到发行版

在我的.github/workflows中,on指令适用于所有作业,因此在我的情况下不起作用。另一方面,action/upload-artifact仅在同一工作流程内工作。

实现上述工作流程的正确方法是什么?

on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v1
        with:
          submodules: true
      - name: Build
        run: make all
      - uses: actions/upload-artifact@v2
        with:
          name: build
          path: dist/
      - name: Deploy to GitHub Pages
        filters: # <-----<<<< What I would like to do
          branch: master                
        uses: JamesIves/github-pages-deploy-action@3.5.9
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN  }}
          BRANCH: gh-pages
          FOLDER: dist/html

1 个答案:

答案 0 :(得分:4)

您可以在步骤中添加条件,并仅跳过不需要的部分,请参见jobs.<id>.steps.if。至于要检查的内容,RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] RewriteCond %{ENV:HTTPS} !on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteRule ^(.+)\.php$ /$1 [R,L] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*?)/?$ /$1.php [NC,END] Options -Indexes 上下文是与当前正在运行的工作流程相关的各种数据的金矿。例如

github

以此类推。

请注意,mentioned in documentation部分只是冰山一角; github.event_name string The name of the event that triggered the workflow run. github.ref string The branch or tag ref that triggered the workflow run. github.head_ref string The head_ref or source branch of the pull request in a workflow run. 包含有用的东西。最好在某些测试工作流程中take a look,看看每个事件提供了什么。


类似的方法应该起作用:

github.event
- name: On any event (pull-request, push on any branches) 
  uses: some/action
- name: Only when master is pushed
  if:   github.event_name == 'push' && github.ref == 'refs/heads/master'
  uses: some/action
相关问题