World map

 

BM: Baca dalam Bahasa Melayu

World 7: Robots: Actions & CI/CD

Reusable workflows

You will learn: how to write a workflow once and call it from many repos.

The problem

bash
ls */.github/workflows
blog/.github/workflows:
test.yml
diary/.github/workflows:
test.yml
shop/.github/workflows:
test.yml
Three project folders, blog, diary and shop. Each has its own copy of test.yml.

You have three sites. Each has the same 40-line test workflow. Found a bug in it? Fix it three times. Ugh.

Watch

Write the recipe once, in one shared repo. Other workflows call it. That is a reusable workflow: A workflow other workflows can call, made with on: workflow_call.. Which trigger makes it callable?

Pick one answer.

Watch

Tap the line that calls the shared workflow.

0 of 1 found

To call it, a job says uses: with the file’s path. It goes in a job, not a step. The caller job has no runs-on and no steps.

Watch

Send plain settings with with:. Send keys with secrets:. Sort each one.

Drag a card into a box. Or tap the card, then tap the box.

      Check

      Good idea, or needs work? Swipe each one.

      Swipe right for good, left for needs work. Or use the buttons.

      1 / 4

      One shared test workflow for all three sites

      One shared test workflow for all three sites

      Check

      You push to the diary repo. Put what happens in order.

      First step at the top. Put these in order. Use the arrows, or drag.

      • The shared jobs run with your inputs
      • Its test job calls shared/test.yml
      • A ✓ or ✗ lands on your commit
      • The diary's workflow starts

      You did it!

      You can now share one workflow across many repos.

      Go deeper (optional)

      A composite action is a smaller cousin. It bundles steps, and you use it as a step. A reusable workflow bundles whole jobs. Its file must sit right in .github/workflows/, not in a subfolder. In the same repo, call it as ./.github/workflows/test.yml.