githubcontinuous-integrationcontinuous-deploymentgithub-actions

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.


Solution

  • 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
    
    jobs:
      on-success:
        runs-on: ubuntu-latest
        if: ${{ github.event.workflow_run.conclusion == 'success' }}
        steps:
          - run: echo 'The Run Tests workflow passed'