-
Notifications
You must be signed in to change notification settings - Fork 2
Add CI #12
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
Merged
Add CI #12
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: ["master"] | ||
| pull_request: | ||
| branches: ["master"] | ||
|
|
||
| env: | ||
| CARGO_TERM_COLOR: always | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| - uses: Swatinem/rust-cache@v2 | ||
| - name: Build | ||
| run: cargo build --verbose --all-features | ||
|
|
||
| checks: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| components: rustfmt, clippy | ||
| - uses: Swatinem/rust-cache@v2 | ||
| - name: Format | ||
| run: cargo fmt -- --check --verbose | ||
| - name: Lint | ||
| run: cargo clippy --all-targets -- -D warnings | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| macro_rules! cargo { | ||
| ($arg:literal $(, $fmt_args:expr),* $(,)?) => {{ | ||
| let cmd_arg = format!($arg, $($fmt_args),*); | ||
| let args = cmd_arg.split_whitespace(); | ||
|
|
||
| println!("cargo {}", cmd_arg); | ||
|
|
||
| let status = std::process::Command::new("cargo") | ||
| .args(args) | ||
| .status() | ||
| .expect("failed to execute process"); | ||
|
|
||
| assert!(status.success(), "command 'cargo {}' failed", cmd_arg); | ||
| }}; | ||
| } | ||
|
|
||
| fn main() { | ||
| let exe_path = std::env::current_exe().expect("current exe"); | ||
|
|
||
| let mut manifest_path = exe_path.parent().expect("exe parent").to_path_buf(); | ||
| while std::fs::read_dir(&manifest_path) | ||
| .expect("read dir") | ||
| .find(|entry| entry.as_ref().expect("entry").file_name() == "Cargo.toml") | ||
| .is_none() | ||
| { | ||
| manifest_path = manifest_path.parent().expect("parent").to_path_buf(); | ||
| } | ||
|
|
||
| let coverage_path = manifest_path.join("coverage"); | ||
| let examples_path = manifest_path.join("examples"); | ||
| let lcov_path = coverage_path.join("lcov.info"); | ||
| let lcov_path_str = lcov_path.to_str().expect("lcov path"); | ||
| let badge_path = coverage_path.join("badge.json"); | ||
| let model_path = examples_path.join("model.ply"); | ||
| let model_path_str = model_path.to_str().expect("model path"); | ||
| let output_path = coverage_path.join("output.ply"); | ||
| let output_path_str = output_path.to_str().expect("output path"); | ||
|
|
||
| println!("Running coverage..."); | ||
|
|
||
| cargo!("llvm-cov clean --workspace"); | ||
|
|
||
| println!("Running 'modify' example"); | ||
| cargo!( | ||
| "llvm-cov run --example modify -- -m {model_path_str} -o {output_path_str} --rgb-or-hsv 0.1 0.9 0.8 --alpha 0.7 --contrast -1.0 --exposure 0.5 --gamma 1.2" | ||
| ); | ||
|
|
||
| println!("Running 'modify' example with '--override-rgb' flag"); | ||
| cargo!( | ||
| "llvm-cov run --example modify -- -m {model_path_str} -o {output_path_str} --override-rgb --rgb-or-hsv 0.7 0.9 0.8 --alpha 0.7 --contrast -1.0 --exposure 0.5 --gamma 1.2" | ||
| ); | ||
|
|
||
| println!("Running 'modify-selection' example"); | ||
| cargo!( | ||
| "llvm-cov run --example modify-selection -- -m {model_path_str} -o {output_path_str} -p 0.5 1.0 0.5 -r 0.2 0.0 0.0 1.0 -s 1 1 1 --repeat 2 --offset 2.0 0.0 0.0 --contrast -1.0" | ||
| ); | ||
|
|
||
| println!("Running 'modify-selection' example with '--shape Box' flag"); | ||
| cargo!( | ||
| "llvm-cov run --example modify-selection -- -m {model_path_str} -o {output_path_str} -p 0.5 1.0 0.5 -r 0.2 0.0 0.0 1.0 -s 1 1 1 --shape Box --repeat 2 --offset 2.0 0.0 0.0 --contrast -1.0" | ||
| ); | ||
|
|
||
| println!("Running 'filter-selection' example"); | ||
| cargo!( | ||
| "llvm-cov run --example filter-selection -- -m {model_path_str} -o {output_path_str} -p 0.5 1.0 0.5 -r 0.2 0.0 0.0 1.0 -s 1 1 1 --repeat 2 --offset 2.0 0.0 0.0" | ||
| ); | ||
|
|
||
| println!("Running 'filter-selection' example with '--shape Box' flag"); | ||
| cargo!( | ||
| "llvm-cov run --example filter-selection -- -m {model_path_str} -o {output_path_str} -p 0.5 1.0 0.5 -r 0.2 0.0 0.0 1.0 -s 1 1 1 --shape Box --repeat 2 --offset 2.0 0.0 0.0" | ||
| ); | ||
|
|
||
| println!("Running 'custom-modify-selection' example"); | ||
| cargo!( | ||
| "llvm-cov run --example custom-modify-selection -- -m {model_path_str} -o {output_path_str} -p 0.5 0.0 0.2 -r 2.0" | ||
| ); | ||
|
|
||
| println!("Running doctests"); | ||
| // `--doctests` flag is currently unstable | ||
| // cargo!("llvm-cov --no-report --doctests"); | ||
| cargo!("test --doc"); | ||
|
|
||
| println!("Running tests"); | ||
| cargo!("llvm-cov --no-report nextest --all-features"); | ||
|
|
||
| println!("Generating coverage report"); | ||
| cargo!("llvm-cov report --lcov --output-path {lcov_path_str}"); | ||
|
|
||
| println!("Generating badge"); | ||
|
|
||
| let lcov = std::fs::read_to_string(&lcov_path).expect("read lcov.info"); | ||
| let mut total: u64 = 0; | ||
| let mut covered: u64 = 0; | ||
|
|
||
| for line in lcov.lines() { | ||
| if !line.starts_with("DA:") { | ||
| continue; | ||
| } | ||
|
|
||
| let mut parts = line[3..].split(','); | ||
| let _line_number = parts.next(); | ||
| let hits_str = parts.next(); | ||
|
|
||
| let Some(hits_str) = hits_str else { | ||
| continue; | ||
| }; | ||
| let Ok(hits) = hits_str.parse::<u64>() else { | ||
| continue; | ||
| }; | ||
|
|
||
| total += 1; | ||
| if hits != 0 { | ||
| covered += 1; | ||
| } | ||
| } | ||
|
|
||
| let badge_percentage: u64 = if total == 0 { | ||
| 100 | ||
| } else { | ||
| ((covered as f32 / total as f32) * 100.0).round() as u64 | ||
| }; | ||
|
|
||
| let badge_color = if badge_percentage >= 80 { | ||
| "brightgreen" | ||
| } else if badge_percentage >= 50 { | ||
| "yellow" | ||
| } else { | ||
| "red" | ||
| }; | ||
|
|
||
| let badge_json = format!( | ||
| r#" | ||
| {{ | ||
| "schemaVersion": 1, | ||
| "label": "coverage", | ||
| "message": "{badge_percentage}%", | ||
| "color": "{badge_color}" | ||
| }} | ||
| "# | ||
| ); | ||
| std::fs::write(&badge_path, badge_json.trim().to_owned() + "\n").expect("write badge.json"); | ||
|
|
||
| println!("Cleaning up"); | ||
| std::fs::remove_file(&output_path).expect("remove output.ply"); | ||
|
|
||
| println!("Done"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,72 +1,9 @@ | ||
| $BASE_DIR = $PSScriptRoot | ||
| $EXAMPLES_PATH = "$BASE_DIR/../examples" | ||
| $LCOV_PATH = "$BASE_DIR/lcov.info" | ||
| $TARGET_DIR = "$PSScriptRoot\..\target\coverage" | ||
|
|
||
| echo "Running coverage..." | ||
|
|
||
| cargo llvm-cov clean --workspace | ||
|
|
||
| echo "Running 'modify' example" | ||
| cargo llvm-cov run --example modify -- -m "$EXAMPLES_PATH/model.ply" -o "$BASE_DIR/output.ply" --rgb-or-hsv 0.1 0.9 0.8 --alpha 0.7 --contrast "-1.0" --exposure 0.5 --gamma 1.2 | ||
|
|
||
| echo "Running 'modify' example with '--override-rgb' flag" | ||
| cargo llvm-cov run --example modify -- -m "$EXAMPLES_PATH/model.ply" -o "$BASE_DIR/output.ply" --override-rgb --rgb-or-hsv 0.7 0.9 0.8 --alpha 0.7 --contrast "-1.0" --exposure 0.5 --gamma 1.2 | ||
|
|
||
| echo "Running 'modify-selection' example" | ||
| cargo llvm-cov run --example modify-selection -- -m "$EXAMPLES_PATH/model.ply" -o "$BASE_DIR/output.ply" -p 0.5 1.0 0.5 -r 0.2 0.0 0.0 1.0 -s 1 1 1 --repeat 2 --offset 2.0 0.0 0.0 --contrast "-1.0" | ||
|
|
||
| echo "Running 'modify-selection' example with '--shape Box' flag" | ||
| cargo llvm-cov run --example modify-selection -- -m "$EXAMPLES_PATH/model.ply" -o "$BASE_DIR/output.ply" -p 0.5 1.0 0.5 -r 0.2 0.0 0.0 1.0 -s 1 1 1 --shape Box --repeat 2 --offset 2.0 0.0 0.0 --contrast "-1.0" | ||
|
|
||
| echo "Running 'filter-selection' example" | ||
| cargo llvm-cov run --example filter-selection -- -m "$EXAMPLES_PATH/model.ply" -o "$BASE_DIR/output.ply" -p 0.5 1.0 0.5 -r 0.2 0.0 0.0 1.0 -s 1 1 1 --repeat 2 --offset 2.0 0.0 0.0 | ||
|
|
||
| echo "Running 'filter-selection' example with '--shape Box' flag" | ||
| cargo llvm-cov run --example filter-selection -- -m "$EXAMPLES_PATH/model.ply" -o "$BASE_DIR/output.ply" -p 0.5 1.0 0.5 -r 0.2 0.0 0.0 1.0 -s 1 1 1 --shape Box --repeat 2 --offset 2.0 0.0 0.0 | ||
|
|
||
| echo "Running 'custom-modify-selection' example" | ||
| cargo llvm-cov run --example custom-modify-selection -- -m "$EXAMPLES_PATH/model.ply" -o "$BASE_DIR/output.ply" -p 0.5 0.0 0.2 -r 2.0 | ||
|
|
||
| # `--doctests` flag is currently unstable | ||
| # echo "Running doctests" | ||
| # cargo llvm-cov --no-report --doctests | ||
| cargo test --doc # Run doctests without tracking coverage | ||
|
|
||
| echo "Running tests" | ||
| cargo llvm-cov --no-report nextest | ||
|
|
||
| echo "Generating coverage report" | ||
| cargo llvm-cov report --lcov --output-path "$LCOV_PATH" | ||
|
|
||
| echo "Generating badge" | ||
| $total = 0 | ||
| $covered = 0 | ||
| Select-String -Path "$LCOV_PATH" -Pattern "DA:" | ForEach-Object { | ||
| if ($_ -match "DA:\d+,(\d+)") { | ||
| $total++ | ||
| if ($matches[1] -ne "0") { | ||
| $covered++ | ||
| } | ||
| } | ||
| if (!(Test-Path -Path $TARGET_DIR)) { | ||
| New-Item -ItemType Directory -Path $TARGET_DIR | Out-Null | ||
| } | ||
|
|
||
| $badge_percentage = if ($total -eq 0) { 100 } else { [math]::Round(($covered / $total) * 100) } | ||
| $badge_color = if ($badge_percentage -ge 80) { | ||
| "brightgreen" | ||
| } elseif ($badge_percentage -ge 50) { | ||
| "yellow" | ||
| } else { | ||
| "red" | ||
| } | ||
|
|
||
| "{ | ||
| `"schemaVersion`": 1, | ||
| `"label`": `"coverage`", | ||
| `"message`": `"$badge_percentage%`", | ||
| `"color`": `"$badge_color`" | ||
| }" | Out-File -FilePath "$BASE_DIR/badge.json" -Encoding ascii | ||
|
|
||
| echo "Cleaning up" | ||
| rm "$BASE_DIR/output.ply" | ||
|
|
||
| echo "Done" | ||
| rustc "$PSScriptRoot\coverage.rs" -o "$TARGET_DIR\coverage.exe" | ||
| & "$TARGET_DIR\coverage.exe" | ||
| Remove-Item "$TARGET_DIR\coverage.exe" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/usr/bin/env sh | ||
| set -eu | ||
|
|
||
| SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) | ||
| TARGET_DIR="$SCRIPT_DIR/../target/coverage" | ||
|
|
||
| mkdir -p "$TARGET_DIR" | ||
|
|
||
| OUT_BIN="$TARGET_DIR/coverage" | ||
|
|
||
| cleanup() { | ||
| rm -f "$OUT_BIN" | ||
| } | ||
| trap cleanup 0 | ||
|
|
||
| rustc "$SCRIPT_DIR/coverage.rs" -o "$OUT_BIN" | ||
| "$OUT_BIN" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.