工作流之间对Github动作的依赖性 [英] Dependencies Between Workflows on Github Actions
问题描述
我有一个带有两个工作流程的monorepo:
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.
是否可以在工作流之间创建依赖关系?
我要运行的是 test.yml
然后运行 deploy.yml
在标签上,而 test.yml
仅在推和拉请求中。我不想在工作流之间重复作业。
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.
推荐答案
有没有办法创建一个工作流程之间的依赖关系?
Is there a way to create a dependency between workflows?
我认为目前尚不可能。也许这是他们将来会添加的功能。就我个人而言,我认为很可能会添加CircleCI之类的功能来共享工作流的公用部分。
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.
对于替代解决方案,确实可以将所有功能都放在同一位置像下面的工作流程适合您?仅在按下以 v
开头的标签时,才会执行 deploy-packages
作业。
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"
这篇关于工作流之间对Github动作的依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!