From d466f18e7b323bd77a2c419290654c8027354b50 Mon Sep 17 00:00:00 2001 From: Qinxuan Chen Date: Fri, 21 Jun 2024 15:13:20 +0800 Subject: [PATCH] ci: improve github workflows (#190) * ci: improve github workflows - split test workflow into lint and test parts - add cache and sccache - use stable toolchain for rustfmt and clippy * remove useless env --- .github/workflows/lint.yml | 54 ++++++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 42 +++++++++++++++++++---------- .rustfmt.toml | 4 --- 3 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..3644720 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,54 @@ +name: Lint + +on: + push: + branches: ["master"] + paths-ignore: + - "**/README.md" + pull_request: + paths-ignore: + - "**/README.md" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: true + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Cache cargo registry & git sources + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/ + ~/.cargo/git/db/ + key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }} + ${{ runner.os }}-cargo-lint- + ${{ runner.os }}-cargo- + + - name: Run sccache + uses: mozilla-actions/sccache-action@v0.0.5 + + - name: Install toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: 1.78.0 + components: rustfmt, clippy + + - name: Check format + run: cargo fmt --all -- --check + + - name: Check clippy + run: cargo clippy --all-targets --all-features -- -D warnings diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 57d63e8..25fefea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,32 +6,46 @@ on: paths-ignore: - "**/README.md" pull_request: - branches: ["master"] - -env: - CARGO_TERM_COLOR: always + paths-ignore: + - "**/README.md" concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +env: + CARGO_TERM_COLOR: always + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: true + jobs: build: runs-on: ubuntu-latest steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Cache cargo registry & git sources + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/ + ~/.cargo/git/db/ + key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }} + ${{ runner.os }}-cargo-test- + ${{ runner.os }}-cargo- + + - name: Run sccache + uses: mozilla-actions/sccache-action@v0.0.5 + - name: Install toolchain uses: dtolnay/rust-toolchain@stable with: - toolchain: nightly-2024-02-09 + toolchain: 1.78.0 components: rustfmt, clippy - - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Check format - run: cargo +nightly-2024-02-09 fmt --all -- --check - - name: Check clippy - run: cargo +nightly-2024-02-09 clippy --all-targets --all-features -- -D warnings - - name: Build - run: cargo build --verbose + - name: Run tests run: cargo test --verbose diff --git a/.rustfmt.toml b/.rustfmt.toml index 14f3e14..6953a45 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,6 +1,2 @@ reorder_imports = true max_width = 120 - -ignore = [ - "vendor/*", -] \ No newline at end of file