【问题标题】:GitHub workflow : one job for each different git actions (push on master, push tags...)GitHub 工作流程:每个不同的 git 操作(推送主服务器、推送标签……)
【发布时间】:2020-11-22 23:29:04
【问题描述】:

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

  • 在任何事件上(拉请求,推任何分支)
    • 结帐代码
    • 构建项目
    • 运行测试
    • 为其他作业上传工件
  • 仅当主服务器被推送时
    • 从以前的作业下载工件
    • 推送 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

【问题讨论】:

    标签: github github-actions


    【解决方案1】:

    您可以为您的步骤添加条件并简单地跳过不需要的部分,请参阅jobs.&lt;id&gt;.steps.if。至于要检查的什么github 上下文是与当前运行的工作流相关的各种数据的金矿。例如

    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.
    

    等等。

    请注意,mentioned in documentation 部分只是冰山一角; github.event 包含有用的东西墙。最好在一些测试工作流中take a look,看看每个事件提供了什么。


    类似的东西应该可以工作:

    - 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
    
    - name: Only when a tag is pushed 
      if:   github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
      uses: some/action
    

    【讨论】:

      猜你喜欢
      • 2022-10-07
      • 2011-05-15
      • 2020-03-27
      • 2021-08-05
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-17
      相关资源
      最近更新 更多