Skip to content

Commit

Permalink
Add GitHub Actions workflows
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Mayer <[email protected]>
  • Loading branch information
sunsided committed Jun 23, 2024
1 parent 9ec6c0f commit 95e6b5d
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[codespell]
ignore-words-list = crate
skip = .git,*.lock
19 changes: 19 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Codespell

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Codespell
uses: codespell-project/actions-codespell@v2
91 changes: 91 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
name: Rust

on:
push:
branches: [ "main" ]
paths:
- 'Cargo.toml'
- 'Cargo.lock'
- 'src/**'
- '.github/workflows/rust.yml'
pull_request:
branches: [ "main" ]
paths:
- 'Cargo.toml'
- 'Cargo.lock'
- 'src/**'
- '.github/workflows/rust.yml'

env:
CARGO_TERM_COLOR: always

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check format
run: cargo fmt --check
- name: Clippy
run: cargo clippy

docs:
name: Build documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build documentation
run: cargo doc

codecov:
needs: lint
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Generate code coverage
run: cargo llvm-cov nextest --features=std,unsafe --package marg-orientation --lcov --output-path lcov.info
- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: true

build-std:
needs:
- lint
- docs
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run doctests
run: cargo test --doc --verbose --package marg-orientation --no-default-features --features=std

build-others:
needs:
- codecov
- build-std
name: Build and Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, windows-latest ]
steps:
- uses: actions/checkout@v4
- name: Run tests
run: cargo test --package marg-orientation --verbose --features=std
- name: Run doctests
run: cargo test --doc --package marg-orientation --verbose --features=std
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "marg-orientation"
description = "A MARG (Magnetic, Angular Rate, and Gravity) orientation estimator"
version = "0.1.0"
version = "0.0.1"
authors = ["Markus Mayer"]
homepage = "https://github.com/sunsided/marg-orientation"
repository = "https://github.com/sunsided/marg-orientation"
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ type OwnedObservation<T> = RegularObservation<
>;

#[cfg(test)]
#[cfg(feature = "std")]
mod tests {
use super::*;
use crate::accelerometer_reading::AccelerometerReading;
Expand Down
31 changes: 9 additions & 22 deletions src/num_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub trait ArcSin<T> {
fn arcsin(self) -> Self::Output;
}

#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg(feature = "std")]
impl ArcTan<f32> for f32 {
type Output = f32;

Expand All @@ -36,6 +38,8 @@ impl ArcTan<f32> for f32 {
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg(feature = "std")]
impl ArcTan<f64> for f64 {
type Output = f64;

Expand All @@ -45,6 +49,8 @@ impl ArcTan<f64> for f64 {
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg(feature = "std")]
impl ArcSin<f32> for f32 {
type Output = f32;

Expand All @@ -54,6 +60,8 @@ impl ArcSin<f32> for f32 {
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg(feature = "std")]
impl ArcSin<f64> for f64 {
type Output = f64;

Expand Down Expand Up @@ -85,29 +93,8 @@ where
}
}

#[cfg_attr(docsrs, doc(cfg(not(feature = "std"))))]
#[cfg(not(feature = "std"))]
impl DetectGimbalLock<f32> for f32 {
#[inline]
fn close_to_zenith_or_nadir(&self, tolerance: f32) -> bool {
let a = (*self - f32::ZENITH).abs();
let b = (*self - f32::NADIR).abs();
a <= tolerance || b.abs() <= tolerance
}
}

#[cfg_attr(docsrs, doc(cfg(not(feature = "std"))))]
#[cfg(not(feature = "std"))]
impl DetectGimbalLock<f64> for f64 {
#[inline]
fn close_to_zenith_or_nadir(&self, tolerance: f64) -> bool {
let a = (*self - f64::ZENITH).abs();
let b = (*self - f64::NADIR).abs();
a <= tolerance || b.abs() <= tolerance
}
}

#[cfg(test)]
#[cfg(feature = "std")]
mod tests {
use super::*;

Expand Down

0 comments on commit 95e6b5d

Please sign in to comment.