Github 操作作业被跳过

Github Actions Job being skipped

对某些 CI/CD 使用 Github 操作。

目前,我遇到了奇怪的行为,尽管条件已满足,但我的作业仍被跳过。 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

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

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

如果 UI 告诉用户它被跳过的原因就好了!

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

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