Dependencies Between Workflows on Github Actions

☆樱花仙子☆ 提交于 2020-06-23 05:50:06

问题


I have a monorepo with two workflows:

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

This doesn't work, I can't reference a job in another workflow:

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

Is there a way to create a dependency between workflows?

What I want is to run test.yml then deploy.yml on tags, and test.yml only on push and pull request. I don't want to duplicate jobs between workflows.


回答1:


Is there a way to create a dependency between workflows?

I don't think this is possible at the moment. Perhaps it's a feature they will add in future. Personally, I think it's more likely that a feature like CircleCI's orbs will get added to share common sections of workflows.

For an alternative solution, does putting it all in the same workflow like the following work for you? The deploy-packages job will only execute if a tag starting with v is being pushed.

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"


来源:https://stackoverflow.com/questions/58457140/dependencies-between-workflows-on-github-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!