工作流之间对Github操作的依赖关系

工作流之间对Github操作的依赖关系,github,continuous-integration,continuous-deployment,github-actions,Github,Continuous Integration,Continuous Deployment,Github Actions,我有一个具有两个工作流的monorepo: .github/workflows/test.yml name: test on: [push, pull_request] jobs: test-packages: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: test packages run: | yarn install

我有一个具有两个工作流的monorepo:

.github/workflows/test.yml

name: test

on: [push, pull_request]

jobs:
  test-packages:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: test packages
        run: |
          yarn install
          yarn test
...
  deploy-packages:
    runs-on: ubuntu-latest
    needs: test-packages
    steps:
      - uses: actions/checkout@v1
      - name: deploy packages
        run: |
          yarn deploy
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
...
.github/workflows/deploy.yml

name: test

on: [push, pull_request]

jobs:
  test-packages:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: test packages
        run: |
          yarn install
          yarn test
...
  deploy-packages:
    runs-on: ubuntu-latest
    needs: test-packages
    steps:
      - uses: actions/checkout@v1
      - name: deploy packages
        run: |
          yarn deploy
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
...
这不起作用,我无法引用其他工作流中的作业:

### ERRORED 19:13:07Z

- Your workflow file was invalid: The pipeline is not valid. The pipeline must contain at least one job with no dependencies.
是否有办法在工作流之间创建依赖关系?


我想要的是在标签上运行
test.yml
然后
deploy.yml
,并且
test.yml
仅在推拉请求时运行。我不想在工作流之间复制作业。

更新:现在可以使用创建对工作流的依赖关系。看

有没有办法在工作流之间创建依赖关系

我认为目前这是不可能的。也许这是他们将来会增加的一项功能。就我个人而言,我认为像CircleCI的orbs这样的功能更有可能被添加到共享工作流的公共部分

对于另一种解决方案,将其全部放在同一个工作流中(如以下所示)对您有用吗?
deploypackages
作业仅在推送以
v
开头的标记时执行

name: my workflow
on: [push, pull_request]
jobs:
  test-packages:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: test packages
        run: echo "Running tests"
  deploy-packages:
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    needs: test-packages
    steps:
      - uses: actions/checkout@v1
      - name: deploy packages
        run: echo "Deploying packages"

现在可以使用在Github操作上的工作流之间建立依赖关系

使用此配置,
发布
工作流将在
运行测试
工作流完成时工作

name: Release
on:
  workflow_run:
    workflows: ["Run Tests"]
    branches: [main]
    types: 
      - completed
正如它在自述文件中声明的那样,当前似乎是解决此缺失功能的最佳解决方案:


值得一看@Ahmed的答案,因为它现在看起来是可行的。关键
需要
是我的解决方案!谢谢。重要的是要知道,您示例中的
发布
工作流将在
运行测试
工作流完成时运行,无论成功与否。如果工作流结果很重要(通常很重要),则需要检查
github.event.workflow\u run.conclusion
。这里有更多的细节:这个动作看起来像是在等待一个超时,而不是在让简洁的作业开始之前等待工作流完成。