ワークフロー ファイルを調べる

完了済み

GitHub Actions では、YAML 構文を使用してワークフローを定義します。 各ワークフローは、コード リポジトリの .github/workflowsという名前のディレクトリに個別の YAML ファイルとして格納されます。 次のワークフロー例は、コードがリポジトリにプッシュされるたびにトリガーされます。 ワークフローは、次の手順を実行します。

  1. プッシュされたコードをチェックアウトします。
  2. Node.jsをインストールします。
  3. Bash 自動テスト システム (Bats) テスト フレームワークをインストールします。
  4. Bats バージョンを出力するコマンドを実行します:bats -v。
name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
  check-bats-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm install -g bats
      - run: bats -v

ワークフロー ファイルについて

YAML 構文を使用してワークフロー ファイルを作成する方法を理解するために、このセクションでは前の例の各行について説明します。

# Optional - The name of the workflow as it will appear in the "Actions" tab of the GitHub repository. If this field is omitted, the name of the workflow file will be used instead.
name: learn-github-actions

# Optional - The name for workflow runs generated that appear in the list of workflow runs on your repository's "Actions" tab. This example uses an expression with the 'github' context to display the username of the actor that triggered the workflow run. 
run-name: ${{ github.actor }} is learning GitHub Actions

# Specifies the trigger for this workflow. This example uses the 'push' event, so a workflow run is triggered every time someone pushes a change to the repository or merges a pull request.
on: [push]

# Groups together all the jobs that run in the 'learn-github-actions' workflow.
jobs:

# Defines a job named 'check-bats-version'. The child keys will define properties of the job.
  check-bats-version:

# Configures the job to run on the latest version of an Ubuntu Linux runner. This means that the job will execute on a fresh virtual machine hosted by GitHub.
    runs-on: ubuntu-latest

# Groups together all the steps that run in the 'check-bats-version' job. Each item nested under this section is a separate action or shell script.
    steps:

# The 'uses' keyword specifies that this step will run 'v4' of the 'actions/checkout' action. This is an action that checks out your repository onto the runner, allowing you to run scripts or other actions against your code (such as build and test tools). You should use the checkout action any time your workflow will use the repository's code.
      - uses: actions/checkout@v4

# This step uses the 'actions/setup-node@v4' action to install the specified version of the Node.js. (This example uses version 20.) This puts both the 'node' and 'npm' commands in your PATH.
      - uses: actions/setup-node@v4
        with:
          node-version: '20'

# The 'run' keyword tells the job to execute a command on the runner. In this case, you are using 'npm' to install the 'bats' software testing package.
      - run: npm install -g bats

# The 'bats' command with a parameter that outputs the software version.
      - run: bats -v

ワークフロー実行のアクティビティを表示する

ワークフローがトリガーされると、ワークフローを実行するワークフロー実行が作成されます。 ワークフローの実行が開始されると、実行の進行状況の視覚化グラフが表示され、GitHub で各ステップのアクティビティが表示されます。 アクティビティを表示するには、次の手順に従います。

  1. リポジトリのメイン ページに移動します。

  2. リポジトリ名の下にある Actions を選択します。 アクション ボタンの場所を示すスクリーンショット。

  3. 左側のサイドバーで、表示するワークフローを選択します。

  4. ワークフロー実行の一覧から実行の名前を選択して、ワークフロー実行の概要を表示します。

  5. 左側のサイドバーまたは視覚化グラフで、表示するジョブを選択します。

  6. ステップを選択すると、詳細な結果が表示されます。

ワークフロー ファイル コンポーネントについて理解したら、開発者がさまざまなユース ケースに合わせてファイルをカスタマイズする方法を確認できます。