Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triggering a new workflow from another workflow?

Can I trigger a new workflow from another workflow?

I'm trying to run a workflow after the first workflow has pushed a new release and it seems to ignore it.

like image 947
bArmageddon Avatar asked Dec 29 '25 01:12

bArmageddon


2 Answers

As described here, you can trigger another workflow using the workflow_run event.

For example we could think of two workflow definitions like this (the only prerequisite is, that both reside in the same repository - but I am sure, there's also an event for other repos as well):

release.yml

name: CI release

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Release artifact
      run: ...

do-something-different.yml

name: Do anything after the release of the first workflow

on:
  workflow_run:
    workflows: ["CI release"]
    types:
      - completed

jobs:
  notify:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Do something
        run: ...

A crucial point here is that the name: CI release definition of the first yaml file must exactly match the workflow_run: workflows: ["CI release"] definition in the second yaml file. Another point is that this approach needs to be done on the default branch (which is mostly main or master) as the docs state:

Note: This event will only trigger a workflow run if the workflow file is on the default branch.

like image 193
jonashackt Avatar answered Dec 30 '25 22:12

jonashackt


Found the answer here:

An action in a workflow run can't trigger a new workflow run. For example, if an action pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.

EDIT: The quote above might be confusing. When I add a Personal Access Token (PAT) to the checkout action with repo permissions granted (and not repository's GITHUB_TOKEN), the following commands DO trigger other workflows:

        - name: Checkout Repo
          uses: actions/checkout@v2
          with:
              token: ${{ secrets.PAT_TOKEN }}

(In my case, running semnatic-release after this checkout, which creates a new release with a new tag - did trigger another workflow that runs only if a tag was created)

like image 20
bArmageddon Avatar answered Dec 30 '25 23:12

bArmageddon