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
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.
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.
Bahasa Melayu
Anda ada tiga laman. Setiap satu ada workflow ujian yang sama, 40 baris. Jumpa pepijat di dalamnya? Baiki tiga kali. Penatnya.
Tulis resipi sekali, dalam satu repo kongsi. Workflow lain panggil resipi itu. Itulah reusable workflow (workflow boleh guna semula). Trigger mana yang buat ia boleh dipanggil?
Untuk memanggil, job tulis uses: dengan laluan fail itu. Ia duduk dalam job, bukan step. Job pemanggil tiada runs-on dan tiada steps.
Hantar tetapan biasa dengan with:. Hantar kunci dengan secrets:. Susun setiap satu.
Idea baik, atau perlu dibaiki? Leret setiap satu.
Anda push ke repo diary. Susun apa yang berlaku.
Kini anda boleh kongsi satu workflow dengan banyak repo.
You finished this before. Practice is always welcome!
Official docs: Reuse workflows · Workflow syntax: on.workflow_call
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?