簡體   English   中英

如果 Github 中的條件適用於另一個作業

[英]If condition in Github Actions for another Job

我的用例是,當 Pull Request Comments 中有觸發詞時觸發文檔構建。 我正在使用pull-request-comment-trigger來了解代碼中是否存在觸發詞

在知道觸發了 Action 之后,我想在 repo 中運行一些命令。 所以,我必須為此使用操作/結帳

我的疑問是,在run命令中,只有 Shell 命令有效,對吧? 如果上述條件滿足,我想再做一份工作。

我當前的 Yaml 文件

name: Testing GH Actions

on:
  pull_request:
    types: [opened]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: khan/pull-request-comment-trigger@master
        id: check
        with:
          trigger: "AppajiC"
          reaction: rocket
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
      - run:
        # Generally Anything here runs if below condition satisfies.
        # I want to run another job here, which uses actions/checkout@v2 action
        if: steps.check.outputs.triggered == 'true'

我怎樣才能做到這一點?

您可以將條件用於結帳步驟和以下步驟:

- name: Checkout
  uses: actions/checkout@v2
  if: steps.check.outputs.triggered == 'true'

- name: Following step1
  if: steps.check.outputs.triggered == 'true'

...

或者,您可以創建一個新作業並使用該 if 條件一次:

jobs:
  deploy:
    runs-on: ubuntu-latest
    outputs:
      deploy-status: ${{ steps.check.outputs.triggered }}
    steps:
      - uses: khan/pull-request-comment-trigger@master
        id: check
        with:
          trigger: 'AppajiC'
          reaction: rocket
        env:
          GITHUB_TOKEN: ${{ github.token }}

  # this job will only run if steps.check.outputs.triggered == 'true'
  # you just need to write the if once
  after-deploy:
    runs-on: ubuntu-latest
    needs: [deploy]
    if: needs.deploy.outputs.deploy-status == 'true'
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        
      ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM