Skip to content

Commit

Permalink
Merge pull request #100 from nyx-space/99-port-test-suite-to-github
Browse files Browse the repository at this point in the history
Add github workflow with coverage
  • Loading branch information
ChristopherRabotin authored Feb 9, 2023
2 parents 8f4c104 + b5e6635 commit d5ea50d
Show file tree
Hide file tree
Showing 60 changed files with 507 additions and 361 deletions.
20 changes: 11 additions & 9 deletions .github/ISSUE_TEMPLATE/stakeholder-need.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,35 @@ assignees: ''

# High level description

**Note: only the high level description needs to be filled out to report an issue or to request a new feature.**

## New feature
_If this is a new feature, describe the need you have either with use cases or examples. If this is a bug report, file a bug report instead._
Describe the need you have either with use cases or examples.

# Requirements
The purpose of this section is to fill out the [Requirements](https://quality.nyxspace.com/process/requirements/) of the QA process.

Requirements answer the question: what does the system need to do? It does not answer the question of how does the system do this?
What does the system need to do?

## Test plans
How do we test that these requirements are fulfilled correctly? What are some edge cases we should be aware of when developing the test code.

How do we test that these requirements are fulfilled correctly? What are some edge cases we should be aware of when developing the test code?

# Design

This is the [design](https://quality.nyxspace.com/process/design/) section. Each subsection has its own subsection in the quality assurance document.
Succinctly explain the idea behind the design.

## Algorithm demonstration

If this issue requires a change in an algorithm, it should be described here. This algorithm should be described thoroughly enough to be used as documentation. This section may also simply refer to an algorithm in the literature or in another piece of software that has been validated. The quality of that reference will be determined case by case.

## API definition

Define how the Nyx APIs will be affect by this: what are new functions available, do any previous function change their definition, why call these functions by that name, etc.

Try to add an ASCII diagram of how this should work.

## High level architecture

Document, discuss, and optionally upload design diagram into this section.

## Detailed design

The detailed design **will* be used in the documentation of how Nyx works.

_Feel free to fill out additional QA sections here, but these will typically be determined during the development, including the release in which this issue will be tackled._
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
time: "11:00"
open-pull-requests-limit: 10
183 changes: 183 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
name: Rust testing, coverage, lint

on:
push:
branches:
- master
tags:
- "*"
pull_request:
workflow_dispatch:

env:
RUST_BACKTRACE: 1

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check

tests:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust:
- { version: "1.64", name: MSRV }
- { version: stable, name: stable }

runs-on: ${{ matrix.os }}
name: Tests (${{ matrix.os }}, ${{ matrix.rust.name }})
needs: [check]
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install ${{ matrix.rust.name }} toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust.version }}
override: true

- name: Set up cargo cache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- name: Unit Test (debug)
run: cargo test --lib

- name: All integration tests (release)
run: cargo test --release --test "*"

scenario-check:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust:
- { version: "1.64", name: MSRV }
- { version: stable, name: stable }

runs-on: ${{ matrix.os }}
name: Scenarios (${{ matrix.os }}, ${{ matrix.rust.name }})
needs: [tests]

steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install ${{ matrix.rust.name }} toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust.version }}
override: true

- name: All integration tests (release)
run: |
cargo run --release -- data/simple-scenario.toml --all
# Check that when we do a unit conversion it's correct
# NOTE: We don't do that with km output because the unit conversion leads to some rounding issues
diff ./data/scenario-run-cm.csv ./data/scenario-run-m.csv
cargo run --release -- data/simple-od-scenario.toml
cargo run --release -- "data/od_validation/*" -a
cargo run --release -- data/iss-example.toml -s iss_cond
lints:
name: Lints
runs-on: ubuntu-latest
needs: [tests]

steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings

audit:
name: Security Audit
runs-on: ubuntu-latest
needs: [lints]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Install cargo-audit
run: cargo install cargo-audit

- name: Audit code
run: cargo audit

release:
name: Release
runs-on: ubuntu-latest
needs: [check, tests, scenario-check, lints, audit]

if: github.ref_type == 'tag'
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy

- name: Publish to crates.io
env:
TOKEN: ${{ secrets.CRATESIO_API_TOKEN }}
run: |
cargo login $TOKEN
cargo publish
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ thiserror = "1.0"


[features]
broken-donotuse = ["levenberg-marquardt"]
# broken-donotuse = ["levenberg-marquardt"]

[profile.dev]
opt-level = 0
Expand Down
5 changes: 2 additions & 3 deletions src/bin/nyxcli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ fn main() -> Result<(), ParsingError> {

let exec_all = matches.is_present("all");
// Try to deserialize the scenario
let scenario: ScenarioSerde;
match s.try_into() {
Ok(s) => scenario = s,
let scenario: ScenarioSerde = match s.try_into() {
Ok(s) => s,
Err(e) => return Err(ParsingError::LoadingError(e.to_string())),
};

Expand Down
8 changes: 4 additions & 4 deletions src/cosmic/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::NyxError;
use std::convert::TryFrom;

/// Defines the default celestial bodies in the provided de438 XB.
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[allow(clippy::upper_case_acronyms)]
pub enum Bodies {
SSB,
Expand Down Expand Up @@ -106,15 +106,15 @@ impl TryFrom<Vec<usize>> for Bodies {
7 => Ok(Self::UranusBarycenter),
8 => Ok(Self::NeptuneBarycenter),
9 => Ok(Self::PlutoBarycenter),
_ => Err(NyxError::ObjectNotFound(format!("{:?}", ephem_path))),
_ => Err(NyxError::ObjectNotFound(format!("{ephem_path:?}"))),
},
2 if ephem_path[0] == 3 => match ephem_path[1] {
// This only support the Earth system
0 => Ok(Self::Earth),
1 => Ok(Self::Luna),
_ => Err(NyxError::ObjectNotFound(format!("{:?}", ephem_path))),
_ => Err(NyxError::ObjectNotFound(format!("{ephem_path:?}"))),
},
_ => Err(NyxError::ObjectNotFound(format!("{:?}", ephem_path))),
_ => Err(NyxError::ObjectNotFound(format!("{ephem_path:?}"))),
}
}
}
8 changes: 3 additions & 5 deletions src/cosmic/bplane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ pub fn try_achieve_b_plane(
loop {
if attempt_no > max_iter {
return Err(NyxError::MaxIterReached(format!(
"Error norm of {} km after {} iterations",
prev_b_plane_err, max_iter
"Error norm of {prev_b_plane_err} km after {max_iter} iterations",
)));
}

Expand All @@ -341,7 +340,7 @@ pub fn try_achieve_b_plane(
if b_plane_err.norm() >= prev_b_plane_err {
// If the error is not going down, we'll raise an error
return Err(NyxError::CorrectionIneffective(
format!("Delta-V correction is ineffective at reducing the B-Plane error:\nprev err norm: {:.3} km\tcur err norm: {:.3} km", prev_b_plane_err, b_plane_err.norm())
format!("Delta-V correction is ineffective at reducing the B-Plane error:\nprev err norm: {prev_b_plane_err:.3} km\tcur err norm: {:.3} km", b_plane_err.norm())
));
}
prev_b_plane_err = b_plane_err.norm();
Expand All @@ -368,8 +367,7 @@ pub fn try_achieve_b_plane(
loop {
if attempt_no > max_iter {
return Err(NyxError::MaxIterReached(format!(
"Error norm of {} km after {} iterations",
prev_b_plane_err, max_iter
"Error norm of {prev_b_plane_err} km after {max_iter} iterations",
)));
}

Expand Down
Loading

0 comments on commit d5ea50d

Please sign in to comment.