Skip to content

Commit

Permalink
Add project tools
Browse files Browse the repository at this point in the history
Signed-off-by: Wiktor Kwapisiewicz <[email protected]>
  • Loading branch information
wiktor-k committed Apr 5, 2024
1 parent b4c97eb commit 057e4cb
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 139 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 .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: wiktor-k
183 changes: 46 additions & 137 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,170 +8,79 @@ on:
branches: [ main ]
workflow_dispatch:

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

jobs:
# Use the following command to fix words locally:
# codespell --ignore-words-list "crate" --skip "*/target" --write-changes
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
uses: codespell-project/actions-codespell@master
with:
ignore_words_list: "crate"
skip: "*/target"
run: just spelling

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

tests:
name: Unit tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
toolchain: stable
target: i686-unknown-linux-gnu
- os: ubuntu-latest
toolchain: stable
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
toolchain: beta
target: i686-unknown-linux-gnu
- os: ubuntu-latest
toolchain: beta
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
toolchain: nightly
target: i686-unknown-linux-gnu
- os: ubuntu-latest
toolchain: nightly
target: x86_64-unknown-linux-gnu
- os: macos-latest
toolchain: stable
target: x86_64-apple-darwin
- os: macos-latest
toolchain: stable
target: x86_64-apple-ios
- os: macos-latest
toolchain: beta
target: x86_64-apple-darwin
- os: macos-latest
toolchain: beta
target: x86_64-apple-ios
- os: macos-latest
toolchain: nightly
target: x86_64-apple-darwin
- os: macos-latest
toolchain: nightly
target: x86_64-apple-ios
- os: windows-latest
toolchain: stable-msvc
target: i686-pc-windows-msvc
- os: windows-latest
toolchain: stable-msvc
target: x86_64-pc-windows-msvc
- os: windows-latest
toolchain: beta-msvc
target: i686-pc-windows-msvc
- os: windows-latest
toolchain: beta-msvc
target: x86_64-pc-windows-msvc
- os: windows-latest
toolchain: nightly-msvc
target: i686-pc-windows-msvc
- os: windows-latest
toolchain: nightly-msvc
target: x86_64-pc-windows-msvc
- os: windows-latest
toolchain: stable-gnu
target: i686-pc-windows-gnu
- os: windows-latest
toolchain: stable-gnu
target: x86_64-pc-windows-gnu
- os: windows-latest
toolchain: beta-gnu
target: i686-pc-windows-gnu
- os: windows-latest
toolchain: beta-gnu
target: x86_64-pc-windows-gnu
- os: windows-latest
toolchain: nightly-gnu
target: i686-pc-windows-gnu
- os: windows-latest
toolchain: nightly-gnu
target: x86_64-pc-windows-gnu
steps:
- uses: actions-rs/toolchain@v1
name: Install toolchain
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.target }}
override: true
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose --all
- name: Test
run: cargo test --verbose --all -- --nocapture
- name: Generate docs
run: cargo doc

code-coverage:
name: Code coverage
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Install code coverage tool
uses: actions-rs/[email protected]
with:
crate: cargo-tarpaulin
version: latest
- name: Collect code coverage
run: cargo tarpaulin --out Xml
- name: Upload code coverage
uses: codecov/codecov-action@v2
- uses: actions/checkout@v4
- run: cargo install --locked just
- name: Run unit tests
run: just tests

valgrind:
name: Valgrind
runs-on: ubuntu-latest
deps:
name: Check dependencies
strategy:
matrix:
include:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Install valgrind
run: sudo apt-get install valgrind
- name: Install cargo-valgrind
uses: actions-rs/[email protected]
with:
crate: cargo-valgrind
version: latest
- name: Run valgrind tests
run: cargo valgrind test
- uses: actions/checkout@v4
- run: cargo install --locked just cargo-deny
- name: Run unit tests
run: just dependencies

lints:
name: Clippy lints
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
include:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: cargo install --locked just
- name: Check for lints
run: cargo clippy -- -D warnings
- name: Check for test lints
run: cargo clippy --tests -- -D warnings
run: just lints
40 changes: 40 additions & 0 deletions .github/workflows/misc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Misc

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

jobs:
code-coverage:
name: Code coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install code coverage tool
uses: actions-rs/[email protected]
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/[email protected]
with:
crate: cargo-valgrind
version: latest
- name: Run valgrind tests
run: cargo valgrind test
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 057e4cb

Please sign in to comment.