Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rust ci #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions actions/rust/code-quality/format/action.yaml
Original file line number Diff line number Diff line change
@@ -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
...
21 changes: 21 additions & 0 deletions actions/rust/code-quality/hack/action.yaml
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this effectively doing? Even by quickly checking their readme it's not clear https://github.com/taiki-e/cargo-hack

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its is supposed to:

  • Ensure that proj compiles with each feature individually enabled.
  • Detects missing imports/dependencies

I am currently adding all other ations as well that make sense, there is a possibility that some might have overlaping functionality, that we can decide once this PR is ready and tested with all other actions as well.

Lemme know know if there are anything I'm missing:

shell: bash
run: cargo hack --feature-powerset check
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider using --each-feature for large feature sets

If your project has many features, using --feature-powerset could generate a large number of combinations, potentially impacting CI time. Consider using --each-feature instead if this becomes an issue.

Suggested change
run: cargo hack --feature-powerset check
run: cargo hack --each-feature check

...
31 changes: 31 additions & 0 deletions actions/rust/code-quality/lint/action.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
...
25 changes: 25 additions & 0 deletions actions/rust/code-quality/msrv/action.yaml
Original file line number Diff line number Diff line change
@@ -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
...
18 changes: 18 additions & 0 deletions actions/rust/code-quality/semver/action.yaml
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Add a comment explaining the semver check

Consider adding a comment explaining what the cargo-semver-checks action does. This would improve the self-documentation of the workflow for maintainers who might not be familiar with it.

    - name: Run cargo-semver-checks
      # Checks for unintentional breaking changes in public API
      uses: obi1kenobi/cargo-semver-checks-action@v2

...
57 changes: 57 additions & 0 deletions actions/rust/code-test/integration-test/action.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
...
28 changes: 28 additions & 0 deletions actions/rust/code-test/minimal-version-test/action.yaml
Original file line number Diff line number Diff line change
@@ -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
...
57 changes: 57 additions & 0 deletions actions/rust/code-test/unit-test/action.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
...