How to Create Workflow Dependencies in GitHub Actions

I’m working with a monorepo that has two separate GitHub Actions workflows and I need one to depend on the other.

First workflow - .github/workflows/ci.yml:

name: ci

on: [push, pull_request]

jobs:
  run-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: execute tests
        run: |
          npm install
          npm run test

Second workflow - .github/workflows/release.yml:

name: release

on:
  push:
    tags:
      - "v*"

jobs:
  publish-release:
    runs-on: ubuntu-latest
    needs: run-tests
    steps:
      - uses: actions/checkout@v2
      - name: publish release
        run: |
          npm run build
          npm publish
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

The problem is I get this error when trying to reference a job from another workflow:

### ERROR 12:45:32Z

- Workflow file is invalid: Invalid workflow configuration. At least one job must exist without dependencies.

My goal: I want the CI workflow to run on all pushes and PRs, but when tags are pushed, I want the release workflow to only run after the CI workflow completes successfully. How can I make workflows depend on each other without duplicating jobs?

you can’t link jobs in diffrent workflows. try merging them into one or use the workflow_run trigger for the release workflow to start after ci finishes. hope this helps!

Yeah, workflow_run trigger is your answer. Hit this same problem last year with our deployment setup. Just change your release workflow to trigger when CI finishes instead of trying to reference jobs across workflows. Use on: workflow_run: workflows: ["ci"] types: [completed] branches: [main] and add if: ${{ github.event.workflow_run.conclusion == 'success' }} to check the workflow actually passed. Keeps everything separate but gives you the dependency you want. Only catch is workflow_run doesn’t pass context like tags automatically - you’ll need to pull that from the triggering workflow’s details.