How do I specify job dependency running in another workflow?

I’ve this workflow:

name: Testing
on: [push, pull_request]

jobs:
  testing:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Setup Environment (Using NodeJS 12.x)
        uses: actions/setup-node@v1
        with:
          node-version: 12.x

      - name: install dependencies
        run: npm install

      - name: Run unit tests and collect coverage
        run: npm run test:unit

Now, I would like to create another workflow (deploy.yml) to deploy my application on Netlify.

How can specify that this deploy depends of the successfully run of “testing” job ?

“testing” and “deploy” are in different workflows files.

name: Deploy
on:
  push:
    branches:
      - master
jobs:
deploy:
# ... ??? ...

Thanks.

6 Likes

You cant.

What you can do is to use the same workflow file and then use conditions to trigger or not a specific job.

If you want to run a job only when there is a push to master branch you can do it like this:

jobs:
   deploy:
       if: github.event_name == 'push' && github.ref == 'refs/heads/master'

Another option for deployments is to create a tag when you are ready to deploy and then having a seperate workflow that is listening to the push tag event and trigger your deploy.

8 Likes

Will this be a feature that will be added in the future?

26 Likes

I think it should be supported!

3 Likes

I would love to have such a feature. Perhaps it is simple (for GitHub) to implement, by adding another “on” event trigger?

on:
  workflow_complete:
workflow: Test
    types: [success]

jobs:
  ...

or

on:
  workflow_success:
    workflow: Test

Seems like a must have for “test then deploy” flow, where it makes sense to separate the two workflows instead of toying around with conditions and have everything as one pile of YAML mess.

10 Likes

This solution would cause a problem if you are using matrix. It will run for every matrix item basically.

This really needs to be solved. I can’t believe this doesn’t work!

It’s a pretty common requirement.

  1. I need to run tests in a matrix.

 2. I also want to deploy only on master, but only if all tests pass.

Right now this is basically impossible.

6 Likes

When will this be supported?

3 Likes

I have try this code,

on:
  workflow_success:
    workflow: Test

but it does not work , and show me

`workflow_success` is not a valid event name

Same here, I’m facing the same problem. On every master push I need to test different JDK versions and then I publish a package snapshot, but i don’t know how to solve it.

2 Likes