Example overview
この記事では、サンプルのワークフローを使ってGitHub ActionsのCIの主な機能の一部を紹介しています。 When this workflow is triggered, it tests your code using a matrix of test combinations with npm test
.
以下の図は、ワークフローのステップとそれらがジョブの中で実行される様子を、高レベルの視点から描いています。
Features used in this example
サンプルのワークフローは、GitHub Actionsの以下の機能を紹介しています:
機能 | Implementation |
---|---|
UIからワークフローを手動で実行: | workflow_dispatch |
自動的に実行されるワークフローのトリガー: | pull_request |
定期的な間隔でワークフローを実行: | schedule |
トークンの権限を設定: | permissions |
同時に実行できるワークフローの実行もしくはジョブ数を制御: | concurrency |
Running the job on different runners, depending on the repository: | runs-on |
特定の条件を満たさないかぎりジョブを実行しないようにする: | if |
Using a matrix to create different test configurations: | matrix |
リポジトリをランナーにクローン: | actions/checkout |
ノード をランナーにインストール: | actions/setup-node |
Caching dependencies: | actions/cache |
ワークフローの例
以下のワークフローは、GitHub Docs Engineeringチームが作成しました。 github/docs
リポジトリ内のこのファイルの最新バージョンをレビューするには、次を参照してください。 test.yml
.
ノート: このワークフローの各行は「例を理解する」の次のセクションで説明されています。
|
Understanding the example
以下の表は、これらの機能がそれぞれGitHub Actionsワークフローの作成時にどのように使われるかを説明しています。
コード | Explanation |
---|---|
|
GitHubリポジトリの"Actions"タブに表示されるワークフローの名前。 |
|
The |
|
Add the |
|
Add the |
|
Add the |
|
Modifies the default permissions granted to |
|
Creates a concurrency group for specific events, and uses the |
|
Cancels any currently running job or workflow in the same concurrency group. |
|
Groups together all the jobs that run in the workflow file. |
|
Defines a job with the ID |
|
Configures the job to run on a GitHub-hosted runner or a self-hosted runner, depending on the repository running the workflow. In this example, the job will run on a self-hosted runner if the repository is named |
|
Sets the maximum number of minutes to let the job run before it is automatically canceled. For more information, see |
|
This section defines the build matrix for your jobs. |
|
Setting |
|
Creates a matrix named |
|
Groups together all the steps that will run as part of the |
|
The |
|
If the current repository is the |
|
If the current repository is the |
|
If the current repository is the |
|
This step runs a command to check out LFS objects from the repository. |
|
This step uses the |
|
This step runs a shell command that uses an output from the previous step to create a file containing the list of files changed in the pull request. |
|
This step uses the |
|
This step runs the |
|
This step uses the |
|
This step runs the build script. |
|
This step runs the tests using |
次のステップ
- GitHub Actionsの概念について学ぶには、「GitHub Actionsを理解する」を参照してください。
- 基本的なワークフローを作成するためのステップバイステップのガイドについては「GitHub Actionsのクイックスタート」を参照してください。
- GitHub Actionsの基本に慣れたなら、ワークフローとその機能について「ワークフローについて」で学べます。