If condition in Github Actions for another Job

If condition in Github Actions for another Job

我的用例是,当 Pull Request Comments 中有触发词时触发文档构建。 我正在使用 pull-request-comment-trigger 来了解代码中是否存在 触发词

知道动作被触发后,我想运行 回购里面的一些命令。所以,我必须为此使用 actions/checkout

我的疑问是,在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'

我怎样才能做到这一点?

您可以将条件用于 checkout 步骤和以下步骤:

- 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
        
      ...