コンテンツへスキップ
LatchkeyLatchkey home

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 What is a GitHub Actions Workflow? Jobs, Steps, and triggers?
GitHub Actions automates CI/CD through workflows - declarative YAML files that bind events to the work they trigger. Understanding the four nouns (event, job, step, runner) makes the whole model click.
Events trigger workflows?
A workflow declares the events it listens for in its on: block - a push, a pull request, a schedule, or a manual dispatch. When a matching event fires, GitHub queues the workflow.
Jobs run on runners?
A workflow contains one or more jobs. Each job runs on a fresh runner and, by default, jobs run in parallel. Use needs: to make one job wait for another, forming a dependency graph.
Steps do the work?
Each job is an ordered list of steps. A step either runs a shell command (run:) or invokes a reusable action (uses:). Steps in a job share the same runner and filesystem, so earlier steps set up state for later ones.

関連ガイド