Skip to content

Sequential Workflows Simple Example

olsido edited this page Aug 5, 2024 · 1 revision

Use Case

Sequential workflows ensure that one workflow runs only after another has completed. This is useful for workflows that depend on the successful completion of previous tasks, such as deploying an application after running tests.

Implementation

First Workflow (.github/workflows/sequential-workflows-first.yml)

name: First Workflow  # Name of the workflow

on:
  workflow_dispatch:  # This workflow can be manually triggered

jobs:
  first-workflow-job:  # Job to run in this workflow
    runs-on: ubuntu-latest  # Use the latest Ubuntu runner
    steps:
      - name: First Workflow Only Step  # Step to run in this job
        run: echo "This is the first workflow"  # Command to run

View on Gist       View in this repo

Second Workflow (.github/workflows/sequential-workflows-second.yml

name: Second Workflow  # Name of the workflow

on:
  workflow_run:  # This workflow is triggered by the completion of another workflow
    workflows: ["First Workflow"]  # The workflow that triggers this one
    types:
      - completed  # Trigger when the specified workflow is completed

jobs:
  second-workflow-job:  # Job to run in this workflow
    runs-on: ubuntu-latest  # Use the latest Ubuntu runner
    steps:
      - name: Second Workflow Only Step  # Step to run in this job
        run: echo "This is the second workflow"  # Command to run

View on Gist       View in this repo

This setup ensures that the second workflow runs only after the first workflow has completed. The workflow_run event is used to trigger the second workflow based on the completion of the first workflow. This is particularly useful for multi-step CI/CD processes where the order of execution is crucial.

Clone this wiki locally