Minor updates for PyPi build #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ main, master, develop ] | |
| pull_request: | |
| branches: [ main, master, develop ] | |
| permissions: | |
| contents: read | |
| checks: write | |
| pull-requests: write | |
| jobs: | |
| test: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] | |
| exclude: | |
| # Reduce Windows matrix to prevent timeouts | |
| - os: windows-latest | |
| python-version: '3.8' | |
| - os: windows-latest | |
| python-version: '3.9' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pytest pytest-cov pytest-asyncio pytest-timeout | |
| pip install -e . | |
| - name: Lint with flake8 | |
| run: | | |
| pip install flake8 | |
| # stop the build if there are Python syntax errors or undefined names | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| - name: Type check with mypy | |
| run: | | |
| pip install mypy types-setuptools | |
| mypy src/analyzeMFT --ignore-missing-imports || true | |
| - name: Test syntax compilation | |
| run: | | |
| echo "Testing syntax compilation of all Python files..." | |
| python -c " | |
| import os | |
| import py_compile | |
| import sys | |
| failed = [] | |
| for root, dirs, files in os.walk('.'): | |
| for file in files: | |
| if file.endswith('.py') and not file.startswith('.'): | |
| filepath = os.path.join(root, file) | |
| try: | |
| py_compile.compile(filepath, doraise=True) | |
| print(f'OK {filepath}') | |
| except Exception as e: | |
| print(f'FAIL {filepath}: {e}') | |
| failed.append(filepath) | |
| if failed: | |
| print(f'\\nSyntax check failed for {len(failed)} files') | |
| sys.exit(1) | |
| else: | |
| print(f'\\nAll Python files passed syntax check') | |
| " | |
| - name: Run unit tests with pytest (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| pytest tests/test_constants.py tests/test_config.py tests/test_validators.py tests/test_cli.py tests/test_file_writers.py -v --tb=short --timeout=30 --maxfail=3 | |
| - name: Run unit tests with pytest (Linux/macOS) | |
| if: runner.os != 'Windows' | |
| run: | | |
| pytest tests/ -v --tb=short --cov=src/analyzeMFT --cov-report=xml --cov-report=term-missing --timeout=30 -m "not slow and not integration" --maxfail=5 | |
| - name: Upload coverage reports to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage.xml | |
| flags: unittests | |
| name: codecov-umbrella | |
| fail_ci_if_error: false | |
| security: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install security tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install bandit safety | |
| - name: Run bandit security linter | |
| run: | | |
| bandit -r src/ -f json -o bandit-report.json --skip B101 || true | |
| bandit -r src/ --skip B101 || echo "Security scan completed with warnings" | |
| - name: Check for known security vulnerabilities | |
| run: | | |
| pip install -r requirements.txt | |
| safety check --json --output safety-report.json || true | |
| safety check | |
| integration: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install -e . | |
| - name: Run integration tests | |
| run: | | |
| echo "Running integration test suite..." | |
| pytest tests/test_integration.py -v --tb=short | |
| - name: Test CLI functionality | |
| run: | | |
| echo "Testing CLI functionality..." | |
| # Generate test MFT file using the test generator module | |
| python -c "from src.analyzeMFT.test_generator import create_test_mft; create_test_mft('test_sample.mft', 100)" | |
| # Test analysis | |
| python analyzeMFT.py -f test_sample.mft -o test_output.csv --csv | |
| # Verify output exists and has content | |
| if [ ! -f test_output.csv ]; then | |
| echo "Error: Output file not created" | |
| exit 1 | |
| fi | |
| lines=$(wc -l < test_output.csv) | |
| if [ $lines -lt 2 ]; then | |
| echo "Error: Output file appears empty (only $lines lines)" | |
| exit 1 | |
| fi | |
| echo "SUCCESS: CLI test passed - generated $lines lines of output" | |
| quality: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install quality tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install black isort pylint | |
| - name: Check code formatting with black | |
| run: | | |
| black --check --diff src/ tests/ || echo "Code formatting issues found (non-blocking)" | |
| - name: Check import sorting with isort | |
| run: | | |
| isort --check-only --diff src/ tests/ || echo "Import sorting issues found (non-blocking)" | |
| - name: Lint with pylint | |
| run: | | |
| pip install -r requirements.txt | |
| pip install -e . | |
| pylint src/analyzeMFT --exit-zero --score=yes --reports=yes |