GitHub Actions で Rust の CI 環境構築
どうも、たくチャレ(@takuchalle)です。
Rust
のコードのCI
環境を構築しました。
設定ファイルを見てもらえば分かると思いますが、以下のことを行っています。
- チェックアウト
- (あれば)キャッシュの復元
- cargo などのツールチェインをインストール
- cargo fmt でコーディングスタイル違反のチェック
- cargo clippy で静的解析
- cargo test でテスト実行
プロジェクト固有の設定は特にないので、下記設定をコピペで済むと思います。
name: test
on: [push]
jobs:
test:
name: run test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- uses: actions-rs/cargo@v1
with:
command: clippy
- uses: actions-rs/cargo@v1
with:
command: test
args: --release --all-features
ここではまだcargo clippy
で静的解析でWarning
が出ても fail にするようにしていません。
Warning
でも fail したい場合は以下のように-- -D warnings
を指定してください。
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
参考サイト
Read other posts