Is there any way to trigger a specific Github action workflow by commit message value?

Viewed 2225

Is there any way to trigger a specific Github action workflow by commit-message value? For example, if I push with the commit message "smoke_test", only (one specific workflow ) smoke test workflow should trigger from a set of workflows. Please help, thanks!

2 Answers

Yes, there is. You can inspect trigger event if commit message contains specific keyword.

Here's an example:

name: Smoke tests
on: push

jobs:
 test:
   runs-on: [ ubuntu-latest ]
   steps:
     - name: Run smoke tests
       if: contains(github.event.head_commit.message, 'smoke_test')
       run: |
         echo 'Running smoke tests!'

Alternative to skipping step/job by checking commit message (after workflow started to run) is using paths: to check if specific file is changed in that commit, instead of commit message content. This way your workflow never starts to run, unlike the other approach:

on:
  push:
    paths:
      - '**trigger_file.txt'

You can combine both approaches, to make trigger explicit

Related