1+ # Name of the GitHub Actions workflow
2+ name : Python Virtual Environment Setup CI
3+
4+ # Define when this workflow should run
5+ on :
6+ push :
7+ branches : [ main ] # Trigger on pushes to main branch
8+ pull_request :
9+ branches : [ main ] # Trigger on pull requests to main branch
10+
11+ # Define the jobs to run
12+ jobs :
13+ # First job: testing across different OS and Python versions
14+ test :
15+ # Dynamic OS selection based on matrix strategy
16+ runs-on : ${{ matrix.os }}
17+ strategy :
18+ matrix :
19+ # Define test matrix: will run tests on all combinations of these
20+ os : [ubuntu-latest, windows-latest, macos-latest] # Test on all major OS
21+ python-version : ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13'] # Test on multiple Python versions
22+
23+ steps :
24+ # Step 1: Check out the repository code
25+ - uses : actions/checkout@v3
26+
27+ # Step 2: Set up Python environment
28+ - name : Set up Python ${{ matrix.python-version }}
29+ uses : actions/setup-python@v4
30+ with :
31+ python-version : ${{ matrix.python-version }}
32+
33+ # Step 3: Install required Python packages
34+ - name : Install dependencies
35+ run : |
36+ python -m pip install --upgrade pip # Upgrade pip to latest version
37+ pip install pytest pytest-cov flake8 # Install testing and linting tools
38+
39+ # Step 4: Run code quality checks with flake8
40+ - name : Lint with flake8
41+ run : |
42+ # Check for specific critical errors
43+ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
44+ # Check overall code quality
45+ flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
46+
47+ # Step 5: Create a test virtual environment
48+ - name : Create test virtual environment
49+ run : |
50+ python -m venv test_venv
51+
52+ # Step 6: Run tests with coverage reporting
53+ - name : Test VenvCreator
54+ run : |
55+ pytest --cov=. --cov-report=xml # Run tests and generate coverage report
56+
57+ # Step 7: Upload coverage reports to Codecov
58+ - name : Upload coverage to Codecov
59+ uses : codecov/codecov-action@v3
60+ with :
61+ file : ./coverage.xml # Coverage report file
62+ flags : unittests # Tag these results as unit tests
63+ fail_ci_if_error : true # Fail if upload to Codecov fails
64+
65+ # Second job: security scanning
66+ security :
67+ runs-on : ubuntu-latest # Security checks only need to run on one OS
68+ steps :
69+ # Step 1: Check out the repository code
70+ - uses : actions/checkout@v3
71+
72+ # Step 2: Set up Python environment
73+ - name : Set up Python
74+ uses : actions/setup-python@v4
75+ with :
76+ python-version : ' 3.10' # Use Python 3.10 for security checks
77+
78+ # Step 3: Install security scanning tools
79+ - name : Install security scanning tools
80+ run : |
81+ pip install bandit safety # bandit for code scanning, safety for dependency checking
82+
83+ # Step 4: Run security scans
84+ - name : Run security scan
85+ run : |
86+ bandit -r . # Recursively scan all Python files for security issues
87+ safety check # Check dependencies for known security vulnerabilities
0 commit comments