Cover Image for [Rust] GitHub Actions で monorepo の CI 環境を整える

[Rust] GitHub Actions で monorepo の CI 環境を整える

概要

Rust は簡単に monorepo が試せて良い。 ただ、GitHub Actions で CI 環境を構築する上で Rust かつ monorepo 用のCI環境構築経験がないので素振りしておく。

ディレクトリ構成

Rustの monorepo に関しては Cargoのワークスペース が詳しいので説明を省くとして、sample-a/b 二つの repo がある状態で sample-a に対してCI を設定する

├── Cargo.lock
├── Cargo.toml
├── ./.github/workflows
├── ./sample-a
└── ./sample-b

やること

以下のように GitHub Actions 用の設定ファイルを用意する

# .github/workflows/sample-a.yml
on:  
  push:  
    branches:  
      - main  
    paths:  
      - 'sample-a/**'
      - '.github/workflows/sample-a.yml'  
  
defaults:  
  run:  
    working-directory: './sample-a'  
  
jobs:  
  build-test:  
    runs-on: ubuntu-latest  
    steps:  
      - uses: actions/checkout@v2  
      - uses: actions-rs/toolchain@v1  
        with:  
          profile: minimal  
          toolchain: stable  
          components: rustfmt, clippy  
      - name: build  
        run: 'cargo build'  
      - name: test  
        run: 'cargo test'
  • sample-a ディレクトリの中に変更があるか、この設定ファイル自体に変更があった場合に実行する
  • デフォルトで sample-a ディレクトリ内でactionを実行する
  • Rust の CI 環境は actions-rs/toolchain@v1 を使う
  • cargo buildcargo test を実行する

参考