Skip to content

Commit 314eba1

Browse files
committed
fix: resolve Rust formatting issue and implement comprehensive code quality automation
**Immediate Fix:** - Fix spacing around division operator in power function test: 1.0/3.0 1.0 / 3.0 - Resolve cargo fmt formatting error that caused CI pipeline failure - All Rust tests now pass with proper formatting **Comprehensive Code Quality Automation:** - Add automated Rust formatting (cargo fmt) and linting (cargo clippy) to CI pipeline - Create dedicated Code Quality workflow (.github/workflows/code-quality.yml) - Implement pre-commit hooks configuration (.pre-commit-config.yaml) - Add cross-platform integration testing for all Python versions (3.8-3.13) **Developer Experience Improvements:** - Create development environment setup script (scripts/setup_dev_environment.py) - Add comprehensive Makefile with common development commands - Include security scanning (cargo audit, safety, bandit) - Add YAML validation and documentation quality checks **Quality Standards Implemented:** - Rust: cargo fmt + cargo clippy with warnings as errors - Python: black + isort + flake8 + mypy + safety + bandit - YAML: yamllint validation for workflow files - Markdown: markdownlint for documentation - Git: semantic commit message templates and validation **Automated Workflow Enhancements:** - Add formatting and linting checks before version analysis - Ensure code quality gates prevent malformed code from reaching production - Include security audits and dependency vulnerability scanning - Cross-platform compatibility testing on Ubuntu, Windows, macOS **Benefits:** - Prevents formatting issues like the division operator spacing error - Automated code quality enforcement in CI/CD pipeline - Consistent code style across all contributors - Early detection of security vulnerabilities and code quality issues - Streamlined developer workflow with make commands and pre-commit hooks This resolves the immediate pipeline failure and establishes robust code quality automation to prevent similar issues in the future.
1 parent 660d002 commit 314eba1

8 files changed

Lines changed: 996 additions & 12 deletions

File tree

.github/workflows/auto-release.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ jobs:
3636
run: |
3737
git config --local user.email "action@github.com"
3838
git config --local user.name "GitHub Action"
39+
40+
- name: Set up Rust
41+
uses: dtolnay/rust-toolchain@stable
42+
with:
43+
components: rustfmt, clippy
44+
45+
- name: Check Rust formatting
46+
run: cargo fmt --all -- --check
47+
48+
- name: Run Rust linting
49+
run: cargo clippy --all-targets --all-features -- -D warnings
3950

4051
- name: Analyze commits and determine version bump
4152
id: version_check
@@ -122,7 +133,15 @@ jobs:
122133

123134
- name: Set up Rust
124135
uses: dtolnay/rust-toolchain@stable
125-
136+
with:
137+
components: rustfmt, clippy
138+
139+
- name: Check Rust formatting
140+
run: cargo fmt --all -- --check
141+
142+
- name: Run Rust linting
143+
run: cargo clippy --all-targets --all-features -- -D warnings
144+
126145
- name: Install maturin
127146
run: pip install maturin
128147

.github/workflows/code-quality.yml

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
name: Code Quality
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
env:
10+
PYTHON_VERSION: '3.11'
11+
12+
jobs:
13+
rust-quality:
14+
name: Rust Code Quality
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Rust
21+
uses: dtolnay/rust-toolchain@stable
22+
with:
23+
components: rustfmt, clippy
24+
25+
- name: Cache Rust dependencies
26+
uses: actions/cache@v4
27+
with:
28+
path: |
29+
~/.cargo/bin/
30+
~/.cargo/registry/index/
31+
~/.cargo/registry/cache/
32+
~/.cargo/git/db/
33+
target/
34+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-cargo-
37+
38+
- name: Check Rust formatting
39+
run: cargo fmt --all -- --check
40+
41+
- name: Run Rust linting (Clippy)
42+
run: cargo clippy --all-targets --all-features -- -D warnings
43+
44+
- name: Run Rust tests
45+
run: cargo test --verbose
46+
47+
- name: Check for unused dependencies
48+
run: |
49+
cargo install cargo-machete --locked
50+
cargo machete
51+
52+
python-quality:
53+
name: Python Code Quality
54+
runs-on: ubuntu-latest
55+
56+
steps:
57+
- uses: actions/checkout@v4
58+
59+
- name: Set up Python
60+
uses: actions/setup-python@v5
61+
with:
62+
python-version: ${{ env.PYTHON_VERSION }}
63+
64+
- name: Cache Python dependencies
65+
uses: actions/cache@v4
66+
with:
67+
path: ~/.cache/pip
68+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt', '**/pyproject.toml') }}
69+
restore-keys: |
70+
${{ runner.os }}-pip-
71+
72+
- name: Install Python dependencies
73+
run: |
74+
python -m pip install --upgrade pip
75+
pip install black isort flake8 mypy pytest
76+
pip install -e python/
77+
78+
- name: Check Python formatting (Black)
79+
run: black --check --diff python/ tests/
80+
81+
- name: Check Python import sorting (isort)
82+
run: isort --check-only --diff python/ tests/
83+
84+
- name: Run Python linting (Flake8)
85+
run: flake8 python/ tests/
86+
87+
- name: Run Python type checking (MyPy)
88+
run: mypy python/demopy/ --ignore-missing-imports
89+
continue-on-error: true # MyPy can be strict, make it non-blocking initially
90+
91+
- name: Run Python tests
92+
run: |
93+
export PYTHONPATH="${PYTHONPATH}:$(pwd)/python"
94+
pytest tests/ -v
95+
96+
yaml-quality:
97+
name: YAML and Config Quality
98+
runs-on: ubuntu-latest
99+
100+
steps:
101+
- uses: actions/checkout@v4
102+
103+
- name: Set up Python
104+
uses: actions/setup-python@v5
105+
with:
106+
python-version: ${{ env.PYTHON_VERSION }}
107+
108+
- name: Install YAML linter
109+
run: pip install yamllint
110+
111+
- name: Check YAML files
112+
run: |
113+
yamllint .github/workflows/ || true
114+
yamllint .pre-commit-config.yaml || true
115+
116+
- name: Validate GitHub Actions workflows
117+
run: |
118+
# Check workflow syntax
119+
for workflow in .github/workflows/*.yml; do
120+
echo "Validating $workflow"
121+
python -c "
122+
import yaml
123+
import sys
124+
try:
125+
with open('$workflow', 'r') as f:
126+
yaml.safe_load(f)
127+
print('✅ $workflow is valid')
128+
except Exception as e:
129+
print('❌ $workflow is invalid: {e}')
130+
sys.exit(1)
131+
"
132+
done
133+
134+
security-scan:
135+
name: Security Scan
136+
runs-on: ubuntu-latest
137+
138+
steps:
139+
- uses: actions/checkout@v4
140+
141+
- name: Run Rust security audit
142+
run: |
143+
cargo install cargo-audit --locked
144+
cargo audit
145+
continue-on-error: true # Don't fail the build on security advisories initially
146+
147+
- name: Set up Python
148+
uses: actions/setup-python@v5
149+
with:
150+
python-version: ${{ env.PYTHON_VERSION }}
151+
152+
- name: Run Python security scan
153+
run: |
154+
pip install safety bandit
155+
# Check for known security vulnerabilities in dependencies
156+
safety check || true
157+
# Check for common security issues in Python code
158+
bandit -r python/ || true
159+
continue-on-error: true
160+
161+
documentation:
162+
name: Documentation Quality
163+
runs-on: ubuntu-latest
164+
165+
steps:
166+
- uses: actions/checkout@v4
167+
168+
- name: Check Markdown files
169+
run: |
170+
# Install markdownlint
171+
npm install -g markdownlint-cli
172+
# Check markdown files (non-blocking initially)
173+
markdownlint *.md || true
174+
markdownlint docs/ || true
175+
176+
- name: Check for broken links
177+
run: |
178+
# Install link checker
179+
npm install -g markdown-link-check
180+
# Check for broken links in markdown files
181+
find . -name "*.md" -not -path "./target/*" -not -path "./.venv/*" | xargs -I {} markdown-link-check {} || true
182+
continue-on-error: true
183+
184+
integration-test:
185+
name: Integration Test
186+
runs-on: ${{ matrix.os }}
187+
strategy:
188+
matrix:
189+
os: [ubuntu-latest, windows-latest, macos-latest]
190+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
191+
192+
steps:
193+
- uses: actions/checkout@v4
194+
195+
- name: Set up Python
196+
uses: actions/setup-python@v5
197+
with:
198+
python-version: ${{ matrix.python-version }}
199+
200+
- name: Set up Rust
201+
uses: dtolnay/rust-toolchain@stable
202+
203+
- name: Install maturin
204+
run: pip install maturin
205+
206+
- name: Build and test package
207+
run: |
208+
maturin build --release
209+
pip install target/wheels/*.whl
210+
python -c "
211+
import demopy
212+
print('✅ Package imports successfully')
213+
print('Version:', demopy.__version__)
214+
print('Functions:', demopy.__all__)
215+
216+
# Test all functions
217+
print('hello():', demopy.hello())
218+
print('add(5, 7):', demopy.add(5, 7))
219+
print('multiply(2.5, 4.0):', demopy.multiply(2.5, 4.0))
220+
print('sum_list([1,2,3]):', demopy.sum_list([1,2,3]))
221+
print('reverse_string(\"test\"):', demopy.reverse_string('test'))
222+
print('power(2, 3):', demopy.power(2, 3))
223+
print('✅ All functions work correctly')
224+
"
225+
shell: bash

.pre-commit-config.yaml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Pre-commit hooks configuration for demopy_gb_jj
2+
# Install with: pip install pre-commit && pre-commit install
3+
4+
repos:
5+
# Rust formatting and linting
6+
- repo: local
7+
hooks:
8+
- id: cargo-fmt
9+
name: Cargo format
10+
description: Format Rust code with cargo fmt
11+
entry: cargo fmt --all --
12+
language: system
13+
files: \.rs$
14+
pass_filenames: false
15+
16+
- id: cargo-clippy
17+
name: Cargo clippy
18+
description: Lint Rust code with cargo clippy
19+
entry: cargo clippy --all-targets --all-features -- -D warnings
20+
language: system
21+
files: \.rs$
22+
pass_filenames: false
23+
24+
- id: cargo-test
25+
name: Cargo test
26+
description: Run Rust tests
27+
entry: cargo test
28+
language: system
29+
files: \.rs$
30+
pass_filenames: false
31+
32+
# Python formatting and linting
33+
- repo: https://github.com/psf/black
34+
rev: 24.10.0
35+
hooks:
36+
- id: black
37+
name: Black Python formatter
38+
description: Format Python code with Black
39+
files: \.py$
40+
args: [--line-length=88]
41+
42+
- repo: https://github.com/pycqa/isort
43+
rev: 5.13.2
44+
hooks:
45+
- id: isort
46+
name: isort Python import sorter
47+
description: Sort Python imports with isort
48+
files: \.py$
49+
args: [--profile=black]
50+
51+
- repo: https://github.com/pycqa/flake8
52+
rev: 7.1.1
53+
hooks:
54+
- id: flake8
55+
name: Flake8 Python linter
56+
description: Lint Python code with flake8
57+
files: \.py$
58+
args: [--max-line-length=88, --extend-ignore=E203,W503]
59+
60+
# General file formatting
61+
- repo: https://github.com/pre-commit/pre-commit-hooks
62+
rev: v5.0.0
63+
hooks:
64+
- id: trailing-whitespace
65+
name: Trim trailing whitespace
66+
description: Remove trailing whitespace
67+
68+
- id: end-of-file-fixer
69+
name: Fix end of files
70+
description: Ensure files end with a newline
71+
72+
- id: check-yaml
73+
name: Check YAML
74+
description: Validate YAML files
75+
files: \.(yaml|yml)$
76+
77+
- id: check-toml
78+
name: Check TOML
79+
description: Validate TOML files
80+
files: \.toml$
81+
82+
- id: check-merge-conflict
83+
name: Check for merge conflicts
84+
description: Check for merge conflict markers
85+
86+
- id: check-added-large-files
87+
name: Check for large files
88+
description: Prevent large files from being committed
89+
args: [--maxkb=1000]
90+
91+
# Markdown formatting
92+
- repo: https://github.com/igorshubovych/markdownlint-cli
93+
rev: v0.42.0
94+
hooks:
95+
- id: markdownlint
96+
name: Markdown lint
97+
description: Lint Markdown files
98+
files: \.md$
99+
args: [--fix]
100+
101+
# Configuration for specific tools
102+
default_language_version:
103+
python: python3
104+
105+
# Skip certain hooks for specific files
106+
exclude: |
107+
(?x)^(
108+
\.venv/.*|
109+
target/.*|
110+
\.git/.*|
111+
__pycache__/.*|
112+
\.pytest_cache/.*
113+
)$

0 commit comments

Comments
 (0)