Xotl
Xotl

Reputation: 99

How to trigger Github Workflow after a check suite finishes?

I want to trigger a workflow only if a particular workflow finishes... does anyone know how to do that?

Some context:

Also there's the event check_suite that it's supposed to trigger a workflow: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#check-suite-event-check_suite

I tried this example:

on:
  check_suite:
    types: [rerequested, completed]

But my workflow never triggers, any ideas why? or any other idea on how can i achieve the above?.

Upvotes: 3

Views: 2917

Answers (2)

Xotl
Xotl

Reputation: 99

Updated answer:

Turns out that you can achieve that using the on: status event, but you need to manually trigger the status with a token that is not the one from the Github Actions.

You need to add something like this in order to trigger the status event after a workflow finishes:

      - name: Trigger status event
        run: >-
          curl -L -X POST 
          -H "Content-Type: application/json"
          -H "Authorization: token ${{ secrets.GITHUB_PAT}}"
          -d '{
            "state": "success",
            "target_url": "https://you-can-add-a.url/",
            "description": "All tests passed", "context": "your-custom/status-event"
          }'
          "https://api.github.com/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}"

And in your other workflow you can just add an if condition in case you have more than one status event that can trigger the workflow, something like this:

on: status

...

jobs:

...

  if: github.event.context == 'your-custom/status-event'

And that's it... That's how you can chain workflows.



Old answer:

Well, after asking at the github.community forum i got an answer.

Events raised from the Actions app do not trigger workflows. This restriction is currently in place in order to prevent a circular workflow execution.

Related links:

Edit: The same applies to check events.

Upvotes: 5

scthi
scthi

Reputation: 2481

Usually you would use steps. The "build" step is only executed if the previous "Test" step was successful.

If you really need to model it via jobs, than you can use needs.

Example:

jobs:
  job1:
  job2:
    needs: job1
  job3:
    needs: [job1, job2]

The check_suite event is only triggered by (external) integrations, like Netlify builds. Note: the event is also only triggered, if you workflow is already merged to your default branch (master).

Upvotes: 0

Related Questions