Triggering Workflows in GitHub Actions

Sep 9, 2024

Triggering GitHub Actions Workflow from Another Workflow

Introduction

  • Topic: How to trigger GitHub Actions workflows from another workflow.
  • Purpose: Useful for scenarios where actions depend on each other.
  • Methods discussed: Repository dispatch and Python script.
  • Reference: Article link in the video description.

Use Cases

  1. Triggering on Failure: Trigger Workflow 2 when Workflow 1 fails.
  2. Dependency Management: Ensure Workflow 2 completes before starting Workflow 1.

Methods of Triggering Workflows

  • Repository Dispatch: Allows triggering workflows based on specified event types.
    • Example: If multiple workflows exist, specify event types (e.g., Workflow 2) to differentiate triggers.

Setup Overview

  • Two workflows: Workflow 1 (triggering) and Workflow 2 (triggered).
  • Key components to configure in Workflow 1:
    • Workflow name of Workflow 2.
    • GitHub account and repository details.
    • Personal Access Token (PAT).

Workflow 1 Configuration

  • Sample workflow available publicly for review.
  • Important configuration details:
    • Name of Workflow 2 (to be triggered).
    • Account name and repository.
    • PAT for authentication.
  • Python Script: Handles the API call to trigger Workflow 2 with relevant payload details.
    • Payload example: baseline number and revision number.

Workflow 2 Configuration

  • Needs to accept repository dispatch calls:
    • Configure event type to match the call from Workflow 1 (e.g., Workflow 2).
  • Handle payload data using github.event.client_payload to access passed values.

Testing the Setup

  • Once both workflows are configured, initiate Workflow 1:
    • Run Workflow 1 which should trigger Workflow 2 automatically.
    • Check results and ensure the values from Workflow 1 are printed in Workflow 2.

Conclusion

  • Summary of demo and steps to set up workflows.
  • Viewers encouraged to ask questions in the comment section.
  • Reminder to like, share, and subscribe to the channel.