Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
CI: add rust tools + CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro committed Jun 24, 2022
1 parent 1cae32f commit 2889794
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

# top-most EditorConfig file
root = true

[*]
end_of_line=lf
charset=utf-8
indent_style=space
indent_size=4
tab_width=4
trim_trailing_whitespace=true
insert_final_newline = true

[*.md]
# double whitespace at end of line denotes a line break in Markdown
trim_trailing_whitespace = false

[*.yml]
indent_size = 2

[*.{rs,toml}]
indent_style=tab
indent_size=tab
max_line_length=100
6 changes: 6 additions & 0 deletions .git_hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -o errexit
set -o pipefail

cat "${1}" | "${HOME}/.cargo/bin/conventional_commits_linter" --from-stdin --allow-angular-type-only
35 changes: 35 additions & 0 deletions .git_hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

echo "Pre Commit Hook"
echo -e "\n# taplo format"

taplo format

echo -e "\n# cargo fmt"

diff=$(cargo +nightly fmt -- --check)
result=$?

if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some code style issues, run `cargo fmt` first.
EOF
exit 1
fi

echo -e "\n# cargo clippy"

diff=$(cargo clippy --bins --tests --examples --all -- -D warnings)
result=$?

if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some code style issues, run `cargo clippy` first.
EOF
exit 1
fi

echo ""


exit 0
19 changes: 19 additions & 0 deletions .git_hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

echo "Pre Push Hook"

echo -e "\n# cargo test"

diff=$(cargo test)
result=$?

if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some test failing, run `cargo test` first.
EOF
exit 1
fi

echo ""

exit 0
26 changes: 26 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Configuration file for Rustfmt
# https://rust-lang.github.io/rustfmt

version = "Two"

# Basic
hard_tabs = true
max_width = 100

# Imports
imports_granularity = "Crate"

# Consistency
newline_style = "Unix"

# Format comments
comment_width = 100
wrap_comments = true

# Misc
chain_width = 80
match_arm_blocks = false
match_block_trailing_comma = true
reorder_impl_items = true
trailing_semicolon = false
use_field_init_shorthand = true
8 changes: 8 additions & 0 deletions .taplo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Taplo is a TOML formater
# https://taplo.tamasfe.dev/

exclude = []

[formatting]
align_entries = true
reorder_keys = true
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"editorconfig.editorconfig",
"matklad.rust-analyzer"
]
}
4 changes: 4 additions & 0 deletions scripts/install_git_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!bin/bash

rm -rf .git/hooks
ln -s $PWD/.git_hooks .git/hooks
6 changes: 6 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!bin/bash

cargo install taplo-cli grcov
cargo install conventional_commits_linter --version 0.9.0
rustup component add llvm-tools-preview

27 changes: 27 additions & 0 deletions scripts/test_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

rm -rf ./target/debug/coverage/*
rm -rf ./target/debug/profraw/*

# Nightly Rust is required to use grcov for Rust coverage.
# Alternatively, you can export `RUSTC_BOOTSTRAP=1`, which basically turns your stable rustc into a Nightly one.
export RUSTC_BOOTSTRAP=1
export RUSTFLAGS="-Zinstrument-coverage"

cargo build

# Ensure each test runs gets its own profile information by defining the LLVM_PROFILE_FILE environment variable
# (%p will be replaced by the process ID, and %m by the binary signature)
export LLVM_PROFILE_FILE="./target/debug/profraw/%p-%m.profraw"

cargo test

# In the CWD, you will see a `.profraw` file has been generated.
# This contains the profiling information that grcov will parse, alongside with your binaries.


# Generate html report
grcov . --binary-path ./target/debug -s src -t html --branch --ignore-not-existing --ignore "/*" -o ./target/debug/coverage/

# Consult the coverage
open ./target/debug/coverage/index.html
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
println!("Hello, world!");
println!("Hello, world!");
}

0 comments on commit 2889794

Please sign in to comment.