工作流之间对Github动作的依赖性


9

我有一个带有两个工作流程的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
...

.github/workflows/deploy.yml

  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仅在推和拉请求上运行。我不想在工作流之间重复作业。

Answers:


3

有没有一种方法可以在工作流程之间创建依赖关系?

我认为目前尚不可能。也许这是他们将来会添加的功能。就个人而言,我认为很可能会添加CircleCI之类的功能来共享工作流的常见部分。

对于替代解决方案,是否可以像下面的工作一样将它们全部放在同一工作流程中?deploy-packages仅当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"
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.