Skip to content

Commit c4b4a0a

Browse files
authored
211 (#321)
* #211 feat: add real-world examples directory with 4 comprehensive examples Created examples/ directory with real-world service examples demonstrating masterror integration with popular frameworks: - axum-rest-api: Full REST API with RFC 7807 Problem Details, domain errors, metadata attachment, and 11 integration tests - sqlx-database: Database error handling patterns including connection errors, constraint violations, and transactions - custom-domain-errors: Payment processing domain with derive macro usage, showcasing authentication, validation, and external service errors - basic-async: Async error handling with tokio, timeout conversion, and error propagation patterns All examples include: - Comprehensive README.md documentation - Runnable source code with cargo run - Integration tests where applicable - SPDX license headers - publish = false in Cargo.toml Updated: - examples/README.md: Index of all examples with running instructions - README.template.md: Added Examples section with table - README.md: Regenerated from template - Cargo.toml: Added 4 examples as workspace members Closes #211 * #211 fix: add Unicode-3.0 to allowed licenses for ICU dependencies * #211 chore: add cargo deny to pre-commit hook and install script Added cargo deny check to pre-commit hook to catch license issues locally before CI. This prevents CI failures like the Unicode-3.0 license issue. Changes: - Added cargo deny check (advisories, bans, licenses, sources) to pre-commit - Created .github/scripts/pre-commit (version-controlled hook) - Created .github/scripts/install-hooks.sh (automated installation) - Updated deny.toml to allow OSI-approved licenses: - Unicode-3.0 (ICU dependencies) - BSD-3-Clause (encoding_rs, matchit) - Zlib (foldhash) Pre-commit now runs all CI checks locally: - rustfmt (nightly) - REUSE compliance - clippy (all features, all targets) - tests (all features) - cargo audit - cargo deny (NEW) - catches license issues before CI - README.md generation This significantly reduces CI failures by catching issues locally.
1 parent 0e416e3 commit c4b4a0a

File tree

22 files changed

+2279
-4
lines changed

22 files changed

+2279
-4
lines changed

.github/scripts/install-hooks.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# SPDX-FileCopyrightText: 2025 RAprogramm <[email protected]>
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
set -euo pipefail
7+
8+
REPO_ROOT="$(git rev-parse --show-toplevel)"
9+
HOOKS_DIR="$REPO_ROOT/.git/hooks"
10+
PRE_COMMIT_SCRIPT="$REPO_ROOT/.github/scripts/pre-commit"
11+
12+
if [ ! -f "$PRE_COMMIT_SCRIPT" ]; then
13+
echo "Error: pre-commit script not found at $PRE_COMMIT_SCRIPT"
14+
exit 1
15+
fi
16+
17+
echo "Installing pre-commit hook..."
18+
cp "$PRE_COMMIT_SCRIPT" "$HOOKS_DIR/pre-commit"
19+
chmod +x "$HOOKS_DIR/pre-commit"
20+
21+
echo "✅ Pre-commit hook installed successfully!"
22+
echo ""
23+
echo "The hook will run the following checks before each commit:"
24+
echo " - rustfmt (nightly)"
25+
echo " - REUSE compliance"
26+
echo " - clippy (all features, all targets)"
27+
echo " - tests (all features)"
28+
echo " - cargo audit"
29+
echo " - cargo deny (advisories, bans, licenses, sources)"
30+
echo " - README.md generation"

.github/scripts/pre-commit

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
# SPDX-FileCopyrightText: 2025 RAprogramm <[email protected]>
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
set -euo pipefail
7+
8+
echo "🔧 Ensuring nightly rustfmt is available..."
9+
if ! rustup toolchain list | grep -q "^nightly"; then
10+
rustup toolchain install nightly >/dev/null
11+
fi
12+
rustup component add rustfmt --toolchain nightly >/dev/null
13+
14+
echo "🧹 Checking formatting with rustfmt..."
15+
cargo +nightly fmt --all -- --check
16+
17+
echo "📜 Checking REUSE compliance..."
18+
if command -v reuse &> /dev/null; then
19+
reuse lint
20+
else
21+
echo "⚠️ Warning: reuse tool not installed, skipping license compliance check"
22+
echo " Install with:"
23+
echo " - Arch Linux: paru -S reuse (or sudo pacman -S reuse)"
24+
echo " - pip: pip install reuse"
25+
fi
26+
27+
echo "🔍 Running clippy (all features, all targets)..."
28+
cargo clippy --workspace --all-targets --all-features -- -D warnings
29+
30+
echo "🧪 Running tests (all features)..."
31+
cargo test -vv
32+
33+
echo "🛡️ Running cargo audit..."
34+
if ! command -v cargo-audit >/dev/null 2>&1; then
35+
cargo install --locked cargo-audit >/dev/null
36+
fi
37+
cargo audit
38+
39+
echo "🔒 Running cargo deny..."
40+
if ! command -v cargo-deny >/dev/null 2>&1; then
41+
echo "Installing cargo-deny..."
42+
cargo install --locked cargo-deny --version 0.18.4 >/dev/null
43+
fi
44+
cargo deny check advisories bans licenses sources
45+
46+
# Uncomment if you want to validate SQLx offline data
47+
# echo "📦 Validating SQLx prepare..."
48+
# cargo sqlx prepare --check --workspace
49+
50+
# same deterministic env
51+
export TZ=UTC
52+
export LC_ALL=C.UTF-8
53+
export NO_COLOR=1
54+
export CARGO_TERM_COLOR=never
55+
export SOURCE_DATE_EPOCH=0
56+
57+
# Generate
58+
./.github/scripts/gen_readme.sh
59+
60+
# Stage README if changed
61+
if ! git diff --quiet -- README.md; then
62+
git add README.md
63+
fi
64+
65+
echo "✅ All checks passed!"
66+

0 commit comments

Comments
 (0)