Skip to content

Commit

Permalink
Added GitHub Actions workflow for automated testing and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
selectdimensions committed Nov 17, 2024
1 parent a0f64ed commit 545e066
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
87 changes: 87 additions & 0 deletions .github/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
30 changes: 30 additions & 0 deletions test_venv_creator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
import os
from create_venv import VenvCreator

@pytest.fixture
def venv_creator():
return VenvCreator()

def test_init(venv_creator):
assert hasattr(venv_creator, 'os_type')
assert hasattr(venv_creator, 'is_windows')
assert hasattr(venv_creator, 'is_linux')

def test_find_python_installations(venv_creator):
installations = venv_creator.find_python_installations()
assert isinstance(installations, list)
assert len(installations) > 0

def test_get_python_version(venv_creator):
python_path = "python" # assumes python is in PATH
version = venv_creator.get_python_version(python_path)
assert isinstance(version, str)
assert "Python" in version

def test_set_dependencies_folder(venv_creator, tmp_path):
# Test with valid path
assert venv_creator.set_dependencies_folder(str(tmp_path)) == True

# Test with invalid path
assert venv_creator.set_dependencies_folder("/nonexistent/path") == False

0 comments on commit 545e066

Please sign in to comment.