Skip to content

Commit fdae3ae

Browse files
committed
chore: update CI workflows and project configuration
- Added new GitHub Actions workflows for code quality, complexity analysis, and dependency checks to enhance the CI process. - Updated the Makefile to include new targets for complexity analysis and dependency conflict checks, improving development workflow. - Modified the .gitignore file to exclude additional generated files and workflow configurations. - Enhanced the pyproject.toml to include new development dependencies for build and security checks. - Updated README.md to reflect changes in CI badges and documentation. - Adjusted version.py to dynamically read the package version, improving version management.
1 parent 4226ed6 commit fdae3ae

File tree

9 files changed

+276
-12
lines changed

9 files changed

+276
-12
lines changed

.github/workflows/code-quality.yml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
name: Code Quality
2+
3+
on:
4+
push:
5+
branches: [ main, dev/jmlr ]
6+
pull_request:
7+
branches: [ main, dev/jmlr ]
8+
9+
jobs:
10+
code-quality:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python 3.9
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: "3.9"
19+
20+
- name: Cache pip dependencies
21+
uses: actions/cache@v3
22+
with:
23+
path: ~/.cache/pip
24+
key: ${{ runner.os }}-pip-quality-${{ hashFiles('pyproject.toml') }}
25+
restore-keys: |
26+
${{ runner.os }}-pip-quality-
27+
${{ runner.os }}-pip-
28+
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install -e ".[dev, security, linting]"
33+
# pip install ruff mypy bandit safety
34+
35+
- name: Check code formatting with Black
36+
run: |
37+
black --check --diff torchsom/ tests/
38+
39+
- name: Check import sorting with isort
40+
run: |
41+
isort --check-only --diff torchsom/ tests/
42+
43+
- name: Lint with Ruff
44+
run: |
45+
ruff check torchsom/ tests/ --output-format=github
46+
47+
- name: Type checking with MyPy
48+
run: |
49+
mypy torchsom/ --ignore-missing-imports --strict
50+
continue-on-error: true
51+
52+
- name: Check for security issues with Bandit (library code)
53+
run: |
54+
bandit -r torchsom/ -f json -o bandit-report-library.json --skip B101,B311,B601
55+
continue-on-error: true
56+
57+
- name: Check for security issues with Bandit (tests)
58+
run: |
59+
bandit -r tests/ -f json -o bandit-report-tests.json --skip B101,B311,B601
60+
continue-on-error: true
61+
62+
# - name: Check for known security vulnerabilities
63+
# run: |
64+
# safety check --json --output safety-report.json
65+
# continue-on-error: true
66+
67+
- name: Upload security reports
68+
uses: actions/upload-artifact@v4
69+
if: always()
70+
with:
71+
name: security-reports
72+
path: |
73+
bandit-report-library.json
74+
bandit-report-tests.json
75+
# safety-report.json
76+
77+
docstring-quality:
78+
runs-on: ubuntu-latest
79+
steps:
80+
- uses: actions/checkout@v4
81+
82+
- name: Set up Python 3.9
83+
uses: actions/setup-python@v4
84+
with:
85+
python-version: "3.9"
86+
87+
- name: Cache pip dependencies
88+
uses: actions/cache@v3
89+
with:
90+
path: ~/.cache/pip
91+
key: ${{ runner.os }}-pip-quality-${{ hashFiles('pyproject.toml') }}
92+
restore-keys: |
93+
${{ runner.os }}-pip-quality-
94+
${{ runner.os }}-pip-
95+
96+
- name: Install dependencies
97+
run: |
98+
python -m pip install --upgrade pip
99+
pip install -e ".[dev, docs]"
100+
# pip install pydocstyle interrogate
101+
102+
- name: Check docstring style
103+
run: |
104+
pydocstyle torchsom/ --convention=google
105+
continue-on-error: true
106+
107+
- name: Check docstring coverage
108+
run: |
109+
interrogate torchsom/ --verbose --ignore-init-method --ignore-magic --ignore-module --fail-under=80
110+
continue-on-error: true
111+
112+
complexity-analysis:
113+
runs-on: ubuntu-latest
114+
steps:
115+
- uses: actions/checkout@v4
116+
117+
- name: Set up Python 3.9
118+
uses: actions/setup-python@v4
119+
with:
120+
python-version: "3.9"
121+
122+
- name: Cache pip dependencies
123+
uses: actions/cache@v3
124+
with:
125+
path: ~/.cache/pip
126+
key: ${{ runner.os }}-pip-quality-${{ hashFiles('pyproject.toml') }}
127+
restore-keys: |
128+
${{ runner.os }}-pip-quality-
129+
${{ runner.os }}-pip-
130+
131+
- name: Install dependencies
132+
run: |
133+
python -m pip install --upgrade pip
134+
pip install -e ".[dev, linting]"
135+
# pip install radon
136+
137+
- name: Analyze code complexity
138+
run: |
139+
radon cc torchsom/ --show-complexity --min B
140+
radon mi torchsom/ --show --min B
141+
continue-on-error: true
142+
143+
check-dependencies:
144+
runs-on: ubuntu-latest
145+
steps:
146+
- uses: actions/checkout@v4
147+
148+
- name: Set up Python 3.9
149+
uses: actions/setup-python@v4
150+
with:
151+
python-version: "3.9"
152+
153+
- name: Cache pip dependencies
154+
uses: actions/cache@v3
155+
with:
156+
path: ~/.cache/pip
157+
key: ${{ runner.os }}-pip-quality-${{ hashFiles('pyproject.toml') }}
158+
restore-keys: |
159+
${{ runner.os }}-pip-quality-
160+
${{ runner.os }}-pip-
161+
162+
- name: Install pip-tools
163+
run: |
164+
python -m pip install --upgrade pip
165+
pip install -e ".[security]"
166+
# pip install pip-tools
167+
168+
- name: Check for dependency conflicts
169+
run: |
170+
pip-compile pyproject.toml --dry-run --verbose
171+
continue-on-error: true

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build-and-deploy:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@v4
1212

1313
- name: Set up Python
1414
uses: actions/setup-python@v4

.github/workflows/release.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Release
2+
3+
on:
4+
# This workflow is triggered by a tag push like v0.1.0 from any branch
5+
push:
6+
tags:
7+
- 'v*'
8+
9+
jobs:
10+
test-before-release:
11+
uses: ./.github/workflows/test.yml
12+
with: {}
13+
secrets: inherit
14+
15+
release:
16+
runs-on: ubuntu-latest
17+
needs: test-before-release
18+
permissions:
19+
contents: write
20+
id-token: write
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v4
29+
with:
30+
python-version: "3.9"
31+
32+
- name: Cache pip dependencies
33+
uses: actions/cache@v3
34+
with:
35+
path: ~/.cache/pip
36+
key: ${{ runner.os }}-pip-release-${{ hashFiles('pyproject.toml') }}
37+
restore-keys: |
38+
${{ runner.os }}-pip-release-
39+
${{ runner.os }}-pip-
40+
41+
- name: Install build dependencies
42+
run: |
43+
python -m pip install --upgrade pip
44+
pip install build twine
45+
46+
- name: Build package
47+
run: |
48+
python -m build
49+
50+
- name: Check package
51+
run: |
52+
twine check dist/*
53+
54+
- name: Create Release
55+
uses: actions/create-release@v1.1.4
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
with:
59+
tag_name: ${{ github.ref_name }}
60+
release_name: Release ${{ github.ref }}
61+
draft: false
62+
prerelease: false
63+
64+
- name: Publish to PyPI
65+
uses: pypa/gh-action-pypi-publish@release/v1
66+
with:
67+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/test.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ jobs:
1717
python-version: ["3.9", "3.10", "3.11"]
1818
pytorch-version: ["2.7.0+cu126"]
1919
exclude:
20-
# Exclude some combinations to reduce CI load
20+
# Exclude some combinations to reduce CI load: macos doesn't work with CUDA, and ubuntu 3.9 triggers Codecov not available
21+
- os: ubuntu-latest
22+
python-version: "3.9"
2123
- os: macos-latest
2224
python-version: "3.9"
2325
- os: macos-latest
2426
python-version: "3.10"
2527
- os: macos-latest
2628
python-version: "3.11"
2729
steps:
28-
- uses: actions/checkout@v5
30+
- uses: actions/checkout@v4
2931
# with:
3032
# fetch-depth: 0
3133

@@ -100,7 +102,7 @@ jobs:
100102
python-version: ["3.10"]
101103

102104
steps:
103-
- uses: actions/checkout@v5
105+
- uses: actions/checkout@v4
104106

105107
- name: Set up Python ${{ matrix.python-version }}
106108
uses: actions/setup-python@v4
@@ -141,7 +143,7 @@ jobs:
141143
needs: test
142144
if: github.event_name == 'push'
143145
steps:
144-
- uses: actions/checkout@v5
146+
- uses: actions/checkout@v4
145147

146148
- name: Set up Python 3.10
147149
uses: actions/setup-python@v4

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
torchsom/logger.py
55
logos/
66

7+
.github/workflows/security.yml
8+
79
# Python
810
__pycache__/
911
*.py[cod]
@@ -13,6 +15,7 @@ __pycache__/
1315
build/
1416
develop-eggs/
1517
dist/
18+
dist_copy/
1619
downloads/
1720
eggs/
1821
.eggs/

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ help: ## Show this help message
1818

1919
install: ## Install development dependencies
2020
@echo "📦 Installing development dependencies..."
21-
pip install -e ".[dev]"
21+
pip install -e ".[dev, tests, security, linting, docs]"
2222
pip install pre-commit
2323
pre-commit install
2424

@@ -109,11 +109,22 @@ clean: ## Clean up generated files
109109
find . -type f -name "*.pyc" -delete
110110
@echo "✅ Cleanup completed!"
111111

112-
ci: format lint security docs ## Run CI pipeline (full CI simulation)
112+
complexity: ## Run complexity analysis: cc = cyclomatic complexity, mi = maintainability index
113+
@echo "🔍 Running complexity analysis..."
114+
radon cc torchsom/ --show-complexity --min B
115+
radon mi torchsom/ --show --min B
116+
@echo "✅ Complexity analysis completed!"
117+
118+
dependencies: ## Check for dependency conflicts: super super long
119+
@echo "🔍 Checking for dependency conflicts..."
120+
pip-compile pyproject.toml --dry-run --verbose
121+
@echo "✅ Dependency checks completed!"
122+
123+
ci: format lint security complexity docs ## Run CI pipeline (full CI simulation)
113124
@echo ""
114125
@echo "🎉 All checks passed (without tests)! Ready to push to GitHub!"
115126

116-
all: format lint security docs test ## Run everything (full CI simulation)
127+
all: format lint security complexity docs test ## Run everything (full CI simulation)
117128
@echo ""
118129
@echo "🎉 All checks passed! Ready to push to GitHub!"
119130

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
[![Python versions](https://img.shields.io/pypi/pyversions/torchsom.svg)](https://pypi.org/project/torchsom/)
77
[![PyTorch versions](https://img.shields.io/badge/PyTorch-2.7-EE4C2C.svg)](https://pytorch.org/)
88

9-
<!-- [![Tests](https://github.com/michelin/TorchSOM/workflows/Tests/badge.svg)](https://github.com/michelin/TorchSOM/actions/workflows/test.yml)
9+
[![Tests](https://github.com/michelin/TorchSOM/workflows/Tests/badge.svg)](https://github.com/michelin/TorchSOM/actions/workflows/test.yml)
1010
[![Code Quality](https://github.com/michelin/TorchSOM/workflows/Code%20Quality/badge.svg)](https://github.com/michelin/TorchSOM/actions/workflows/code-quality.yml)
11-
[![Security](https://github.com/michelin/TorchSOM/workflows/Security%20Scanning/badge.svg)](https://github.com/michelin/TorchSOM/actions/workflows/security.yml)
11+
<!-- [![Security](https://github.com/michelin/TorchSOM/workflows/Security%20Scanning/badge.svg)](https://github.com/michelin/TorchSOM/actions/workflows/security.yml)
1212
[![codecov](https://codecov.io/gh/michelin/TorchSOM/branch/main/graph/badge.svg)](https://codecov.io/gh/michelin/TorchSOM) -->
1313
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
1414
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dirty_template = "{tag}.post{ccount}+dirty" # Format when the working tree i
4444

4545
# Dynamically load the README from file
4646
[tool.setuptools.dynamic]
47-
readme = {file = "README.md"} # Long description for PyPI and docs
47+
readme = {file = "README.md", content-type = "text/markdown"} # Long description for PyPI and docs
4848

4949
# Package discovery configuration
5050
[tool.setuptools.packages.find]
@@ -61,6 +61,8 @@ dev = [
6161
"isort",
6262
"rich",
6363
"typing_extensions",
64+
"build",
65+
"twine",
6466
]
6567

6668
tests = [
@@ -85,6 +87,7 @@ security = [
8587
"bandit[toml]",
8688
"safety",
8789
"pip-audit",
90+
"pip-tools",
8891
]
8992

9093
linting = [

torchsom/version.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
"""Version of the torchsom package."""
22

3-
__version__ = "0.1.0"
3+
from importlib.metadata import PackageNotFoundError, version
4+
5+
try:
6+
__version__ = version("torchsom") # reads installed package version
7+
except PackageNotFoundError:
8+
__version__ = "0.0.0"
9+
10+
# __version__ = "0.1.0"

0 commit comments

Comments
 (0)