Skip to content

Commit

Permalink
Add project tools
Browse files Browse the repository at this point in the history
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
  • Loading branch information
wiktor-k committed Apr 5, 2024
1 parent b4c97eb commit 5e67ce4
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 179 deletions.
3 changes: 3 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[codespell]
skip = .cargo,.git,target,Cargo.lock
ignore-words-list = crate,ser
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: wiktor-k
177 changes: 0 additions & 177 deletions .github/workflows/ci.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/misc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Misc

on:
pull_request:
push:
tags:
- 'v*'
branches: [ main ]
workflow_dispatch:

concurrency:
group: misc-${{ github.ref }}
cancel-in-progress: true

jobs:
code-coverage:
name: Code coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install code coverage tool
uses: actions-rs/install@v0.1
with:
crate: cargo-tarpaulin
version: latest
- name: Collect code coverage
run: cargo tarpaulin --out Xml
- name: Upload code coverage
uses: codecov/codecov-action@v2

valgrind:
name: Valgrind
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install valgrind
run: sudo apt-get install valgrind
- name: Install cargo-valgrind
uses: actions-rs/install@v0.1
with:
crate: cargo-valgrind
version: latest
- name: Run valgrind tests
run: cargo valgrind test
86 changes: 86 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: CI

on:
pull_request:
push:
tags:
- 'v*'
branches: [ main ]
workflow_dispatch:

concurrency:
group: rust-${{ github.ref }}
cancel-in-progress: true

jobs:
check-spelling:
name: Check spelling
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cargo install --locked just
- run: sudo apt-get install -y codespell
- name: Check spelling
run: just spelling

formatting:
name: Check formatting
strategy:
matrix:
include:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: cargo install --locked just
- run: rustup install nightly
- run: rustup component add rustfmt --toolchain nightly
- name: Check formatting
run: just formatting

tests:
name: Unit tests
strategy:
matrix:
include:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: cargo install --locked just
- name: Run unit tests
run: just tests

deps:
name: Check dependencies
strategy:
matrix:
include:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: cargo install --locked just cargo-deny
- name: Run dependencies check
run: just dependencies

lints:
name: Clippy lints
strategy:
matrix:
include:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: cargo install --locked just
- name: Check for lints
run: just lints
66 changes: 66 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env -S just --working-directory . --justfile
# Since this is a first recipe it's being run by default.
# Faster checks need to be executed first for better UX. For example

# codespell is very fast. cargo fmt does not need to download crates etc.
check: spelling formatting lints dependencies tests

# Checks common spelling mistakes
spelling:
codespell

# Checks source code formatting
formatting:
just --unstable --fmt --check
# We're using nightly to properly group imports, see .rustfmt.toml
cargo +nightly fmt -- --check
# Lints the source code
lints:
cargo clippy --all -- -D warnings
# Checks for issues with dependencies
dependencies:
cargo deny check
# Runs all unit tests. By default ignored tests are not run. Run with `ignored=true` to run only ignored tests
tests:
cargo test --all
# Checks for commit messages
check-commits REFS='main..':
#!/usr/bin/env bash
set -euo pipefail
for commit in $(git rev-list "{{ REFS }}"); do
MSG="$(git show -s --format=%B "$commit")"
CODESPELL_RC="$(mktemp)"
git show "$commit:.codespellrc" > "$CODESPELL_RC"
if ! grep -q "Signed-off-by: " <<< "$MSG"; then
printf "Commit %s lacks \"Signed-off-by\" line.\n" "$commit"
printf "%s\n" \
" Please use:" \
" git rebase --signoff main && git push --force-with-lease" \
" See https://developercertificate.org/ for more details."
exit 1;
elif ! codespell --config "$CODESPELL_RC" - <<< "$MSG"; then
printf "The spelling in commit %s needs improvement.\n" "$commit"
exit 1;
else
printf "Commit %s is good.\n" "$commit"
fi
done
# Fixes common issues. Files need to be git add'ed
fix:
#!/usr/bin/env bash
if ! git diff-files --quiet ; then
echo "Working tree has changes. Please stage them: git add ."
exit 1
fi

codespell --write-changes
just --unstable --fmt
cargo clippy --fix --allow-staged

# fmt must be last as clippy's changes may break formatting
cargo +nightly fmt
File renamed without changes.
Loading

0 comments on commit 5e67ce4

Please sign in to comment.