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