GitHub Actionsのworkflowとは? job、step、trigger
workflowは.github/workflows/にあるYAMLファイルにすぎず、こう言う: このイベントが起きたら、これらのjobをこれらのrunnerで実行せよ。
GitHub Actionsはworkflowを通してCI/CDを自動化する - イベントを、それがtriggerする作業に結びつける宣言的なYAMLファイルだ。4つの名詞(イベント、job、step、runner)を理解すると、モデル全体が腑に落ちる。
イベントがworkflowをtriggerする
workflowは、リッスンするイベントをon:ブロックで宣言する - push、pull request、スケジュール、または手動のdispatch。一致するイベントが発火すると、GitHubはworkflowをqueueに入れる。
Triggers
on:
push:
branches: [main]
pull_request:jobはrunnerで動く
workflowは1つ以上のjobを含む。各jobは新しいrunnerで動き、デフォルトではjobは並列に実行される。needs:を使って、あるjobを別のjobの完了まで待たせ、依存グラフを形成する。
stepが作業を行う
各jobは順序付きのstepのリストだ。stepはshellコマンドを実行する(run:)か、再利用可能なactionを呼び出す(uses:)。job内のstepは同じrunnerとファイルシステムを共有するため、前のstepが後のstepのために状態を用意する。
A minimal job
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm test全体を組み合わせる
イベント → workflow → job(runner上、場合により並列)→ step(順番に)。それ以外のすべて - matrix、cache、artifact、権限 - はこの中核の形の上に重なる。
重要なポイント
- workflowは
.github/workflows/のYAMLで、on:を介してイベントに結びつく。 - jobは新しいrunnerで動き、デフォルトでは並列に実行される。
- stepは順番に実行され、jobのrunnerとファイルシステムを共有する。
needs:は並列なjobを順序付きの依存グラフに変える。
関連ガイド
What Is CI/CD? A Plain-English IntroductionCI/CD is the practice of automatically building, testing, and shipping code on every change. Learn what conti…
What Is a Build Matrix? Testing Across Versions and PlatformsA build matrix runs the same job across many combinations - OS, language version, dependency set. Learn how m…
What Is a CI Runner? Managed vs Self-Hosted ExplainedA CI runner is the machine that executes your pipeline jobs. Learn how runners work, the difference between h…