diff --git a/.github/actions/cache_cargo/action.yaml b/.github/actions/cache_cargo/action.yaml new file mode 100644 index 0000000..ecb5c2a --- /dev/null +++ b/.github/actions/cache_cargo/action.yaml @@ -0,0 +1,16 @@ +name: cache_cargo +description: "Cache .cargo registry" + +runs: + using: "composite" + steps: + - name: Cache .cargo registry + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- \ No newline at end of file diff --git a/.github/workflows/rust_ci.yaml b/.github/workflows/rust_ci.yaml new file mode 100644 index 0000000..362263a --- /dev/null +++ b/.github/workflows/rust_ci.yaml @@ -0,0 +1,72 @@ +name: Rust CI + +on: + push: + branches: + - main + - enhancement** + - bug** + paths: + - 'src/**' + - 'tests/**' + - 'Cargo.**' + pull_request: + branches: + - main + + +jobs: + build_cache: + name: Cache Rust ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + # os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest] + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Cache cargo directory + uses: ./.github/actions/cache_cargo + - name: Set toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: rustfmt, clippy + - name: Build + run: cargo build + + fmt_clippy: + name: format and clippy + runs-on: ubuntu-latest + needs: build_cache + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Cache cargo directory + uses: ./.github/actions/cache_cargo + - name: Check + run: cargo check + - name: Format code + run: cargo fmt --all -- --check + - name: Clippy + run: cargo clippy --all-targets --all-features -- -D warnings --no-deps + + test: + name: cargo test + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + # os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest] + needs: build_cache + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Cache cargo directory + uses: ./.github/actions/cache_cargo + - name: Run tests + run: cargo test -- --nocapture +