Wait for a workflow to complete before starting another

Hi,
I want to use Github actions for my lerna.js based monorepo CI/CD process. My repo contains some packages and some services. The ideal flow would be:
(1) for each changed package,  bump it’s version and publish packages to an npm registry (this is done using lerna publish)
(2) after all packages have been published start the deployment of the changed services

In order to achieve this I need to have the (2) workflow wait for the (1) workflow to complete

My first try to achieve this was to have workflow (1) to create a new commit, and have workflow (2) trigger on files changed in that commit, however it seems that the workflow will not trigger when I commit from an action. 

Is there any way to achieve this using Github actions?

Thanks!

I believe the issue is that workflows won’t trigger from actions taken using the Github Actions token provided to a workflow.  If you create a distinct Github token, expose it to your Workflow 1 as a secret, and execute the commit using that, it should trigger subsequent workflows, since it will be indistinguishable from other non-Actions related commits. 

2 Likes

Ohh, so thats the trick. Works like a charm! thanks!

is there any documentation/examples on how to do this? cc @alexpusch

There is a workflow_run event which you may use:

name: Deploy services

on:
  workflow_run:
    workflows:
      - Publish packages
    types: 
      - completed
    branches:
      - main

the Publish packages is the workflow names that we want to trigger? @Simran-B

After debugging, finally I’m able to run the second workflow (triggered after workflow 1 completed) with below steps:

  1. disable caching, mentioned here
  2. use custom token, also mentioned in this thread from @jherico
  3. update workflow yaml configuration in master/main or default branch instead, mentioned here

I haven’t tried it myself, but based on the documentation example I assume that it’s indeed the workflow name value.

On https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#workflow_run I read

The workflow started by the workflow_run event is able to access the secrets and write tokens used by the original workflow.

does “is able” mean “is only able”?