Skip to content

Commit

Permalink
Add project tools
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktor-k committed Apr 16, 2024
1 parent 90cc757 commit 0a11152
Show file tree
Hide file tree
Showing 17 changed files with 600 additions and 9 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
10 changes: 10 additions & 0 deletions .github/workflows/dco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: DCO

on: pull_request

jobs:
check:
name: Developer Certificate of Origin
runs-on: ubuntu-latest
steps:
- uses: tisonkun/[email protected]
93 changes: 93 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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
libs: libpcsclite
- 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
libs: libpcsclite
- os: macos-latest
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: sudo apt-get update && sudo apt-get install -y ${{ matrix.libs }}
if: ${{ matrix.libs }}
- 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
libs: libpcsclite
- os: macos-latest
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: sudo apt-get update && sudo apt-get install -y ${{ matrix.libs }}
if: ${{ matrix.libs }}
- run: cargo install --locked just
- name: Check for lints
run: just lints
70 changes: 70 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/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 docs 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 --all -- --check

# Lints the source code
lints:
cargo clippy --workspace --no-deps --all-targets -- -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

# Build docs for this crate only
docs:
cargo doc --no-deps

# 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 --all
5 changes: 5 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CHECK: https://github.com/rust-lang/rustfmt/issues/5083 state == open
group_imports = "StdExternalCrate"

# CHECK: https://github.com/rust-lang/rustfmt/issues/3348 state == open
format_code_in_doc_comments = true
76 changes: 76 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributing

Thanks for taking the time to contribute to this project!

All changes need to:

- pass basic checks, including tests, formatting and lints,
- be signed-off.

## Basic checks

We are using standard Rust ecosystem tools including `rustfmt` and `clippy` with one minor difference.
Due to a couple of `rustfmt` features being available only in nightly (see the `.rustfmt.toml` file) nightly `rustfmt` is necessary.

All of these details are captured in a `.justfile` and can be checked by running [`just`'](https://just.systems/).

To run all checks locally before sending them to CI you can set your git hooks directory:

```sh
git config core.hooksPath scripts/hooks/
```

## Developer Certificate of Origin

The sign-off is a simple line at the end of the git commit message, which certifies that you wrote it or otherwise have the right to pass it on as a open-source patch.

The rules are pretty simple: if you can [certify the below][DCO]:

```
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
```

then you just add a line saying

Signed-off-by: Random J Developer <[email protected]>

using your name.

If you set your `user.name` and `user.email`, you can sign your commit automatically with [`git commit --signoff`][GSO].

To sign-off your last commit:

git commit --amend --signoff

[DCO]: https://developercertificate.org
[GSO]: https://git-scm.com/docs/git-commit#git-commit---signoff

If you want to fix multiple commits use:

git rebase --signoff main

To check if your commits are correctly signed-off locally use `just check-commits`.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "age-plugin-openpgp-card"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0 OR MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
Loading

0 comments on commit 0a11152

Please sign in to comment.