GitHub Actionsとは:GitHubが提供するCICDツール
定義ファイル(ワークフローファイル):yml形式で、.github/workflow下に置かれる。
例:repository/.github/workflow/<ワークフロー名>.yml
ワークフローファイルコード例(yml):
name: workflow
on:
pull_request:
branches:
- master
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.2
- name: Install dependencies
run: dotnet restore
- name: Run Build
run: dotnet build --configuration Release
- name: Run Test
run: dotnet test --verbosity normal
解説:
name: workflow
ワークフロー名(任意の名前、何でもよい)
on:
pull_request:
branches:
- master
どのタイミングでジョブが動き出すか、この例だとmasterブランチにプルリクエストされたタイミング
jobs: ci:
jobs以降にジョブが定義されていく、ここではciというジョブが定義されている
ci:
runs-on: ubuntu-latest
ciジョブの定義のruns-on:どのような環境でテストするかが定義されている
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.2
- name: Install dependencies
run: dotnet restore
- name: Run Build
run: dotnet build --configuration Release
- name: Run Test
run: dotnet test --verbosity normal
ciジョブのsteps:ジョブ内でタスクを実行する単位
name:ステップの名前(任意、無くても可)
uses:他actionsの参照
run:コマンドベースで実行する箇所
下記個別に抜粋
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v2:レポジトリをpullするアクション、レポジトリが指定されている場合はそのレポジトリを使用して、指定されていない場合は作業レポジトリからとなる。
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.2
uses: actions/setup-dotnet@v1:dotnet cliを使用できるようにする。
with:
dotnet-version: 2.2:.netバージョンの指定
- name: Install dependencies
run: dotnet restore
run: dotnet restore (ソリューションファイル名):dotnet restoreコマンドで必要パッケージのインストール
- name: Run Build
run: dotnet build --configuration Release
run: dotnet build (ソリューションファイル名) –configuration Release:dotnet buildコマンドでリリースビルド
- name: Run Test
run: dotnet test --verbosity normal
run: dotnet test –verbosity normal:dotnet testコマンドでユニットテスト(–verbosity:コマンドの詳細レベル)