From 6d66890ffa4c7530b57cc10ed52731c92e37b7a2 Mon Sep 17 00:00:00 2001 From: max-ishere <47008271+max-ishere@users.noreply.github.com> Date: Wed, 7 Feb 2024 18:08:41 +0200 Subject: [PATCH] ci: Split cargo checks into separate files & jobs Separating into different jobs and files allows for more detailed failures in the CI overview as well as separate badges in the readme --- .editorconfig | 9 ++++ .github/workflows/cargo-build.yml | 40 +++++++++++++++ .github/workflows/cargo-lint.yml | 58 ++++++++++++++++++++++ .github/workflows/cargo-test.yml | 42 ++++++++++++++++ .github/workflows/cargo.yml | 82 ------------------------------- 5 files changed, 149 insertions(+), 82 deletions(-) create mode 100644 .github/workflows/cargo-build.yml create mode 100644 .github/workflows/cargo-lint.yml create mode 100644 .github/workflows/cargo-test.yml delete mode 100644 .github/workflows/cargo.yml diff --git a/.editorconfig b/.editorconfig index 15c2b1e..dfdbb6b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,4 +5,13 @@ tab_width = 2 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true +max_line_length = 120 + +[*.yml] +indent_style = space +indent_size = 2 +tab_width = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true max_line_length = 120 \ No newline at end of file diff --git a/.github/workflows/cargo-build.yml b/.github/workflows/cargo-build.yml new file mode 100644 index 0000000..d3ca866 --- /dev/null +++ b/.github/workflows/cargo-build.yml @@ -0,0 +1,40 @@ +name: Build + +on: + push: + paths: + - '**.rs' + - '.github/workflows/**.yml' + pull_request: + paths: + - '**.rs' + - '.github/workflows/**.yml' + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + target: + - --lib + - --bins + - --examples + + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: target/ + key: cargo-build-${{ hashFiles('Cargo.lock') }} + restore-keys: | + cargo-build-${{ hashFiles('Cargo.lock') }} + cargo-build- + cargo- + + - name: build + run: cargo build --release ${{ matrix.target }} --keep-going --verbose diff --git a/.github/workflows/cargo-lint.yml b/.github/workflows/cargo-lint.yml new file mode 100644 index 0000000..5c7f1b7 --- /dev/null +++ b/.github/workflows/cargo-lint.yml @@ -0,0 +1,58 @@ +name: Linter + +on: + push: + paths: + - '**.rs' + - '.github/workflows/**.yml' + pull_request: + paths: + - '**.rs' + - '.github/workflows/**.yml' + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + clippy: + runs-on: ubuntu-latest + strategy: + matrix: + target: + - --lib + - --bins + - --examples + - --tests + + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: target/ + key: cargo-lint-${{ hashFiles('Cargo.lock') }} + restore-keys: | + cargo-lint-${{ hashFiles('Cargo.lock') }} + cargo-lint- + cargo- + + - name: clippy + run: cargo clippy --no-deps ${{ matrix.target }} --verbose -- -Dwarnings + + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: target/ + key: cargo-lint-${{ hashFiles('Cargo.lock') }} + restore-keys: | + cargo-lint-${{ hashFiles('Cargo.lock') }} + cargo-lint- + cargo- + + - name: fmt + run: cargo fmt --all --check --verbose diff --git a/.github/workflows/cargo-test.yml b/.github/workflows/cargo-test.yml new file mode 100644 index 0000000..ed00165 --- /dev/null +++ b/.github/workflows/cargo-test.yml @@ -0,0 +1,42 @@ +name: Tests + +on: + push: + paths: + - '**.rs' + - '.github/workflows/**.yml' + pull_request: + paths: + - '**.rs' + - '.github/workflows/**.yml' + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + target: + - --lib + - --bins + - --examples + - --tests + - --doc + + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: target/ + key: cargo-test-${{ hashFiles('Cargo.lock') }} + restore-keys: | + cargo-test-${{ hashFiles('Cargo.lock') }} + cargo-test- + cargo- + + - name: test + run: cargo test --no-fail-fast ${{ matrix.target }} --verbose diff --git a/.github/workflows/cargo.yml b/.github/workflows/cargo.yml deleted file mode 100644 index 7585cab..0000000 --- a/.github/workflows/cargo.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: Check project with cargo tooling - -on: - push: - paths: - - '**.rs' - - '.github/workflows/**.yml' - pull_request: - paths: - - '**.rs' - - '.github/workflows/**.yml' - workflow_dispatch: - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - name: Build - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - uses: actions/cache/restore@v4 - with: - path: target/ - key: build-${{ hashFiles('Cargo.lock') }} - - - name: build - run: cargo build --release --all-targets --keep-going --verbose - - - uses: actions/cache/save@v4 - with: - path: target/ - key: build-${{ hashFiles('Cargo.lock') }} - - test: - name: Test - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - uses: actions/cache/restore@v4 - with: - path: target/ - key: test-${{ hashFiles('Cargo.lock') }} - - - name: test - run: cargo test --no-fail-fast --all-targets --verbose - - - name: test docs - run: cargo test --no-fail-fast --doc --verbose - - - uses: actions/cache/save@v4 - with: - path: target/ - key: test-${{ hashFiles('Cargo.lock') }} - - lint: - name: Lint - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - uses: actions/cache/restore@v4 - with: - path: target/ - key: lint-${{ hashFiles('Cargo.lock') }} - - - name: check - run: cargo clippy --no-deps --all-targets --verbose - - - name: check - run: cargo fmt --all --check --verbose - - - uses: actions/cache/save@v4 - with: - path: target/ - key: lint-${{ hashFiles('Cargo.lock') }}