From 761e2c53f9fd29148eb15e88096bf2e938a7067b Mon Sep 17 00:00:00 2001 From: umi Date: Mon, 23 Mar 2026 18:22:20 +0800 Subject: [PATCH] feat: add code quality check script and license config --- .licenserc.yaml | 33 ++++++++++++++++ Makefile | 16 ++++++++ dev/check.sh | 102 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 .licenserc.yaml create mode 100755 dev/check.sh diff --git a/.licenserc.yaml b/.licenserc.yaml new file mode 100644 index 0000000..563882e --- /dev/null +++ b/.licenserc.yaml @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +header: + license: + spdx-id: Apache-2.0 + copyright-owner: Apache Software Foundation + + paths-ignore: + - "LICENSE" + - "NOTICE" + - ".gitattributes" + - "**/*.json" + - "target" + - "Cargo.lock" + - ".github/*.md" + - "bindings/go/**/go.mod" + - "bindings/go/**/go.sum" + comment: on-failure diff --git a/Makefile b/Makefile index 1e18aa7..b2a95cc 100644 --- a/Makefile +++ b/Makefile @@ -36,3 +36,19 @@ docker-up: # Stop and remove Docker containers, networks, and volumes. docker-down: docker compose -f dev/docker-compose.yaml down -v + +# Code quality checks +check: + ./dev/check.sh + +check-fix: + ./dev/check.sh --fix + +check-fmt: + cargo fmt --all -- --check + +check-clippy: + cargo clippy --all-targets --all-features --workspace -- -D warnings + +test: + cargo test --workspace diff --git a/dev/check.sh b/dev/check.sh new file mode 100755 index 0000000..daf724e --- /dev/null +++ b/dev/check.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" +AUTO_FIX=false + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --fix) + AUTO_FIX=true + shift + ;; + *) + echo "Unknown option: $1" + echo "Usage: $0 [--fix]" + exit 1 + ;; + esac +done + +cd "$PROJECT_ROOT" + +echo "========================================" +echo "Running code checks for paimon-rust" +echo "========================================" + +# 1. Check license headers +echo "" +echo "[1/4] Checking license headers..." +if command -v license-eye &> /dev/null; then + license-eye header check + echo "✓ License check passed" +else + echo "⚠ Failed to check license headers. license-eye not installed, skipping license check" +fi + +# 2. Check code formatting (with auto-fix) +echo "" +echo "[2/4] Checking code formatting (cargo fmt)..." +if ! cargo fmt --all -- --check; then + if [ "$AUTO_FIX" = true ]; then + echo "Fixing formatting issues..." + cargo fmt --all + echo "✓ Format fixed" + else + echo "✗ Format check failed. Run with --fix to auto-fix, or run 'cargo fmt --all' manually." + exit 1 + fi +else + echo "✓ Format check passed" +fi + +# 3. Run clippy (with auto-fix) +echo "" +echo "[3/4] Running clippy..." +if ! cargo clippy --all-targets --all-features --workspace -- -D warnings 2>&1; then + if [ "$AUTO_FIX" = true ]; then + echo "Attempting to fix clippy issues..." + cargo clippy --fix --allow-dirty --allow-staged --all-targets --all-features --workspace + echo "✓ Clippy fixes applied. Re-running clippy..." + if ! cargo clippy --all-targets --all-features --workspace -- -D warnings; then + echo "✗ Some clippy issues could not be auto-fixed. Please fix manually." + exit 1 + fi + echo "✓ Clippy check passed after fixes" + else + echo "✗ Clippy check failed. Run with --fix to auto-fix, or fix manually." + exit 1 + fi +else + echo "✓ Clippy check passed" +fi + +# 4. Run tests +echo "" +echo "[4/4] Running tests..." +cargo test --workspace --lib +echo "✓ Tests passed" + +echo "" +echo "========================================" +echo "All checks passed! ✓" +echo "========================================"