Github Actions 作业被跳过

Mat*_*art 12 continuous-integration github github-actions

使用 Github Actions 进行某些 CI/CD。

目前,我遇到了奇怪的行为,尽管满足了条件,但我的工作却被跳过。deploy-api有两个条件,如果代码被推送到 master 并且test-api成功。但即使我们满足了这些条件,它仍然被跳过。

jobs:
  test-api:
    name: Run tests on API
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: Get dependencies
        run: npm install
        working-directory: ./api
      - name: Run tests
        run: npm run test
        working-directory: ./api

  deploy-api:
    needs: test-api # other job must finish
    if: github.ref == 'refs/heads/master' && needs.test-api.status == 'success' #only run if it's a commit to master AND previous success
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如图所示,尽管推送在主分支上(如顶部所示)并且前一个作业成功,但第二个作业被跳过。

我在代码中遗漏了什么吗?有谁知道可以使用的解决方法?

如果 UI 告诉用户为什么它被跳过,那就太好了!

riQ*_*iQQ 8

在表达式中使用needs.test-api.result == 'success'(没有.status) if

请参阅https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#needs-context