From 9ee26597c3e9365170bb9f3c0d51c9988f15a400 Mon Sep 17 00:00:00 2001 From: Javed Habib Date: Mon, 2 Sep 2024 01:05:52 +0530 Subject: [PATCH] feat: add rust ci --- actions/rust/code-quality/format/action.yaml | 19 +++++++ actions/rust/code-quality/hack/action.yaml | 21 +++++++ actions/rust/code-quality/lint/action.yaml | 31 ++++++++++ actions/rust/code-quality/msrv/action.yaml | 25 ++++++++ actions/rust/code-quality/semver/action.yaml | 18 ++++++ .../code-test/integration-test/action.yaml | 57 +++++++++++++++++++ .../minimal-version-test/action.yaml | 28 +++++++++ actions/rust/code-test/unit-test/action.yaml | 57 +++++++++++++++++++ 8 files changed, 256 insertions(+) create mode 100644 actions/rust/code-quality/format/action.yaml create mode 100644 actions/rust/code-quality/hack/action.yaml create mode 100644 actions/rust/code-quality/lint/action.yaml create mode 100644 actions/rust/code-quality/msrv/action.yaml create mode 100644 actions/rust/code-quality/semver/action.yaml create mode 100644 actions/rust/code-test/integration-test/action.yaml create mode 100644 actions/rust/code-test/minimal-version-test/action.yaml create mode 100644 actions/rust/code-test/unit-test/action.yaml diff --git a/actions/rust/code-quality/format/action.yaml b/actions/rust/code-quality/format/action.yaml new file mode 100644 index 0000000..214c63b --- /dev/null +++ b/actions/rust/code-quality/format/action.yaml @@ -0,0 +1,19 @@ +--- +name: Formatting Check +description: Checks that the code is formatted according to rustfmt + +runs: + using: composite + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Install stable + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - name: Check formatting + shell: bash + run: cargo fmt --check +... \ No newline at end of file diff --git a/actions/rust/code-quality/hack/action.yaml b/actions/rust/code-quality/hack/action.yaml new file mode 100644 index 0000000..a083d9f --- /dev/null +++ b/actions/rust/code-quality/hack/action.yaml @@ -0,0 +1,21 @@ +name: Hack +description: Check feature flag combinations with cargo-hack + +runs: + using: composite + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + submodules: true + + - name: Install stable Rust + uses: dtolnay/rust-toolchain@stable + + - name: Install cargo-hack + uses: taiki-e/install-action@cargo-hack + + - name: Run cargo hack + shell: bash + run: cargo hack --feature-powerset check +... \ No newline at end of file diff --git a/actions/rust/code-quality/lint/action.yaml b/actions/rust/code-quality/lint/action.yaml new file mode 100644 index 0000000..6b5d0b5 --- /dev/null +++ b/actions/rust/code-quality/lint/action.yaml @@ -0,0 +1,31 @@ +--- +name: Clippy Lint Check +description: Checks that the code does not contain any Clippy warnings + +inputs: + toolchain: + description: The Rust toolchain to use + required: false + default: stable + github_token: + description: The GitHub token to use + required: true + +runs: + using: composite + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Install ${{ inputs.toolchain }} + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ inputs.toolchain }} + components: clippy + + - name: cargo clippy + uses: giraffate/clippy-action@v1 + with: + reporter: 'github-pr-check' + github_token: ${{ inputs.github_token }} +... \ No newline at end of file diff --git a/actions/rust/code-quality/msrv/action.yaml b/actions/rust/code-quality/msrv/action.yaml new file mode 100644 index 0000000..a17992a --- /dev/null +++ b/actions/rust/code-quality/msrv/action.yaml @@ -0,0 +1,25 @@ +--- +name: MSRV +description: Check minimal supported Rust version + +inputs: + msrv: + description: The minimal supported Rust version + required: false + default: "1.56.1" + +runs: + using: composite + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Install minimal supported Rust version + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ inputs.msrv }} + + - name: Run cargo check with msrv ${{ inputs.msrv }} + shell: bash + run: cargo +${{ inputs.msrv }} check +... \ No newline at end of file diff --git a/actions/rust/code-quality/semver/action.yaml b/actions/rust/code-quality/semver/action.yaml new file mode 100644 index 0000000..e774546 --- /dev/null +++ b/actions/rust/code-quality/semver/action.yaml @@ -0,0 +1,18 @@ +--- +name: Semver +description: Check semantic versioning with cargo-semver-checks + +runs: + using: composite + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Install stable Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - name: Run cargo-semver-checks + uses: obi1kenobi/cargo-semver-checks-action@v2 +... \ No newline at end of file diff --git a/actions/rust/code-test/integration-test/action.yaml b/actions/rust/code-test/integration-test/action.yaml new file mode 100644 index 0000000..ba0b8bc --- /dev/null +++ b/actions/rust/code-test/integration-test/action.yaml @@ -0,0 +1,57 @@ +--- +name: Integration Test +description: Run the integration test suite and upload coverage to Codecov + +inputs: + toolchain: + description: Rust toolchain to test against + required: false + default: stable + github_token: + description: GitHub token to use + required: true + codecov_token: + description: Codecov token to upload coverage + required: true + +runs: + using: composite + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Install Rust toolchain ${{ inputs.toolchain }} + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ inputs.toolchain }} + + - name: Generate lockfile if missing + shell: bash + if: hashFiles('Cargo.lock') == '' + run: cargo generate-lockfile + + - name: Run integration tests with ${{ inputs.toolchain }} Rust + shell: bash + run: cargo test --test '*' --locked --all-features --all-targets + + - name: Install stable Rust and LLVM tools + uses: dtolnay/rust-toolchain@stable + with: + components: llvm-tools-preview + + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@cargo-llvm-cov + + - name: Run cargo llvm-cov + shell: bash + run: cargo llvm-cov --tests --locked --all-features --lcov --output-path lcov.info + + - name: Upload coverage report + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true + token: ${{ inputs.codecov_token }} + env_vars: OS,RUST,TOOLCHAIN=${{ inputs.toolchain }} + flags: integration-test + name: coverage-integration-${{ inputs.toolchain }} +... \ No newline at end of file diff --git a/actions/rust/code-test/minimal-version-test/action.yaml b/actions/rust/code-test/minimal-version-test/action.yaml new file mode 100644 index 0000000..6e26fcd --- /dev/null +++ b/actions/rust/code-test/minimal-version-test/action.yaml @@ -0,0 +1,28 @@ +--- +name: Minimal Dependency Version Test +description: Run the test suite with minimal versions of dependencies + +runs: + using: composite + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Install stable Rust + uses: dtolnay/rust-toolchain@stable + + - name: Install nightly Rust + uses: dtolnay/rust-toolchain@nightly + + - name: Set default Rust to stable + shell: bash + run: rustup default stable + + - name: Update cargo with minimal versions + shell: bash + run: cargo +nightly update -Zminimal-versions + + - name: Run tests with minimal versions + shell: bash + run: cargo test --locked --all-features --all-targets +... \ No newline at end of file diff --git a/actions/rust/code-test/unit-test/action.yaml b/actions/rust/code-test/unit-test/action.yaml new file mode 100644 index 0000000..d25600e --- /dev/null +++ b/actions/rust/code-test/unit-test/action.yaml @@ -0,0 +1,57 @@ +--- +name: Unit Test +description: Run the unit test suite and upload coverage to Codecov + +inputs: + toolchain: + description: Rust toolchain to test against + required: false + default: stable + github_token: + description: GitHub token to use + required: true + codecov_token: + description: Codecov token to upload coverage + required: true + +runs: + using: composite + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Install stable Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ inputs.toolchain }} + + - name: Generate lockfile if missing + shell: bash + if: hashFiles('Cargo.lock') == '' + run: cargo generate-lockfile + + - name: Run unit tests with ${{ inputs.toolchain }} Rust + shell: bash + run: cargo test --lib --locked --all-features --all-targets + + - name: Install stable Rust and LLVM tools + uses: dtolnay/rust-toolchain@stable + with: + components: llvm-tools-preview + + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@cargo-llvm-cov + + - name: Run cargo llvm-cov + shell: bash + run: cargo llvm-cov --lib --locked --all-features --lcov --output-path lcov.info + + - name: Upload coverage report + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true + token: ${{ inputs.codecov_token }} + flags: unit-test + env_vars: OS,RUST,TOOLCHAIN=${{ inputs.toolchain }} + name: coverage-unit-${{ inputs.toolchain }} +... \ No newline at end of file