Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependencies Between Workflows on Github Actions

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

name: deploy  on:   push:     tags:       - "*"  jobs:   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 requests. I don't want to duplicate jobs between workflows.

like image 906
Guillaume Vincent Avatar asked Oct 18 '19 19:10

Guillaume Vincent


People also ask

How do I trigger a workflow from another workflow in GitHub Actions?

If you do want to trigger a workflow from within a workflow run, you can use a personal access token instead of GITHUB_TOKEN to trigger events that require a token. You'll need to create a personal access token and store it as a secret.

Do Github action jobs run sequentially?

To run jobs sequentially, you can define dependencies on other jobs using the jobs. <job_id>. needs keyword. Each job runs in a runner environment specified by runs-on .

What are workflows in GitHub Actions?

Workflows. A workflow is a configurable automated process that will run one or more jobs. Workflows are defined by a YAML file checked in to your repository and will run when triggered by an event in your repository, or they can be triggered manually, or at a defined schedule.

Can you have multiple Github workflows?

You can have multiple files in the . github/workflows folder. All files will be read and run as independent tests.


1 Answers

Now it's possible to have dependencies between workflows on Github Actions using workflow_run.

Using this config, the Release workflow will work when the Run Tests workflow is completed.

name: Release on:   workflow_run:     workflows: ["Run Tests"]     branches: [main]     types:        - completed 
like image 159
Ahmed AbouZaid Avatar answered Oct 08 '22 10:10

Ahmed AbouZaid