mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-29 04:26:20 +00:00
security: Add explicit permissions and security scanning workflow
- Add explicit permissions to all workflows (format, release, ci, test, label-issues, mark-answered) - Fix format.yml to have write permissions for PR creation - Add security.yml workflow for automated vulnerability scanning - Improve security posture with minimal permissions principle
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
# Development Scripts
|
||||
|
||||
Helper scripts for development, testing, and code quality checks.
|
||||
|
||||
## Available Scripts
|
||||
|
||||
### Setup Scripts
|
||||
|
||||
#### `setup-dev.sh` / `setup-dev.ps1`
|
||||
Sets up the development environment.
|
||||
|
||||
**Bash (Linux/macOS):**
|
||||
```bash
|
||||
bash .github/scripts/setup-dev.sh
|
||||
```
|
||||
|
||||
**PowerShell (Windows):**
|
||||
```powershell
|
||||
.github\scripts\setup-dev.ps1
|
||||
```
|
||||
|
||||
**What it does:**
|
||||
- Checks Python version
|
||||
- Creates virtual environment if needed
|
||||
- Installs package with dev dependencies
|
||||
- Sets up pre-commit hooks
|
||||
- Verifies installation
|
||||
|
||||
### Code Quality Scripts
|
||||
|
||||
#### `check-code.sh` / `check-code.ps1`
|
||||
Runs all code quality checks (formatting, linting, type checking).
|
||||
|
||||
**Bash:**
|
||||
```bash
|
||||
bash .github/scripts/check-code.sh
|
||||
```
|
||||
|
||||
**PowerShell:**
|
||||
```powershell
|
||||
.github\scripts\check-code.ps1
|
||||
```
|
||||
|
||||
**What it checks:**
|
||||
- Code formatting (black)
|
||||
- Import sorting (isort)
|
||||
- Linting (flake8)
|
||||
- Type checking (mypy - non-blocking)
|
||||
|
||||
#### `format-code.sh` / `format-code.ps1`
|
||||
Automatically formats code and sorts imports.
|
||||
|
||||
**Bash:**
|
||||
```bash
|
||||
bash .github/scripts/format-code.sh
|
||||
```
|
||||
|
||||
**PowerShell:**
|
||||
```powershell
|
||||
.github\scripts\format-code.ps1
|
||||
```
|
||||
|
||||
**What it does:**
|
||||
- Formats code with black
|
||||
- Sorts imports with isort
|
||||
|
||||
### Testing Scripts
|
||||
|
||||
#### `run-tests.sh` / `run-tests.ps1`
|
||||
Runs tests with coverage reporting.
|
||||
|
||||
**Bash:**
|
||||
```bash
|
||||
bash .github/scripts/run-tests.sh
|
||||
```
|
||||
|
||||
**PowerShell:**
|
||||
```powershell
|
||||
.github\scripts\run-tests.ps1
|
||||
```
|
||||
|
||||
**What it does:**
|
||||
- Runs pytest with coverage
|
||||
- Generates HTML and terminal coverage reports
|
||||
- Coverage report: `htmlcov/index.html`
|
||||
|
||||
## Quick Start
|
||||
|
||||
1. **Setup development environment:**
|
||||
```bash
|
||||
# Linux/macOS
|
||||
bash .github/scripts/setup-dev.sh
|
||||
|
||||
# Windows
|
||||
.github\scripts\setup-dev.ps1
|
||||
```
|
||||
|
||||
2. **Before committing, run checks:**
|
||||
```bash
|
||||
# Linux/macOS
|
||||
bash .github/scripts/check-code.sh
|
||||
|
||||
# Windows
|
||||
.github\scripts\check-code.ps1
|
||||
```
|
||||
|
||||
3. **If checks fail, format code:**
|
||||
```bash
|
||||
# Linux/macOS
|
||||
bash .github/scripts/format-code.sh
|
||||
|
||||
# Windows
|
||||
.github\scripts\format-code.ps1
|
||||
```
|
||||
|
||||
4. **Run tests:**
|
||||
```bash
|
||||
# Linux/macOS
|
||||
bash .github/scripts/run-tests.sh
|
||||
|
||||
# Windows
|
||||
.github\scripts\run-tests.ps1
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
- Python 3.10+
|
||||
- Virtual environment (created by setup script)
|
||||
- Dev dependencies installed (`pip install -e ".[dev]"`)
|
||||
|
||||
## Notes
|
||||
|
||||
- All scripts automatically activate the virtual environment if it exists
|
||||
- Scripts check for required directories before running
|
||||
- Error messages provide helpful guidance
|
||||
- Type checking (mypy) is non-blocking and won't fail the check
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# Code quality check script (PowerShell)
|
||||
# Runs formatting, import sorting, linting, and type checking
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
Write-Host "🔍 Running code quality checks..." -ForegroundColor Cyan
|
||||
|
||||
# Activate virtual environment if it exists
|
||||
if (Test-Path "venv") {
|
||||
& .\venv\Scripts\Activate.ps1
|
||||
}
|
||||
|
||||
# Check if directories exist
|
||||
if (-not (Test-Path "semantica")) {
|
||||
Write-Host "❌ semantica/ directory not found" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check formatting
|
||||
Write-Host "📝 Checking code formatting (black)..." -ForegroundColor Yellow
|
||||
try {
|
||||
black --check semantica/ 2>&1 | Out-Null
|
||||
Write-Host "✅ Black check passed" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "❌ Code formatting issues found" -ForegroundColor Red
|
||||
Write-Host " Run: black semantica/" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check import sorting
|
||||
Write-Host "📦 Checking import sorting (isort)..." -ForegroundColor Yellow
|
||||
try {
|
||||
isort --check-only semantica/ 2>&1 | Out-Null
|
||||
Write-Host "✅ isort check passed" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "❌ Import sorting issues found" -ForegroundColor Red
|
||||
Write-Host " Run: isort semantica/" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Lint with flake8
|
||||
Write-Host "🔎 Linting with flake8..." -ForegroundColor Yellow
|
||||
try {
|
||||
flake8 semantica/
|
||||
Write-Host "✅ flake8 check passed" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "❌ Linting issues found" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Type check with mypy (non-blocking)
|
||||
Write-Host "🔬 Type checking with mypy..." -ForegroundColor Yellow
|
||||
try {
|
||||
mypy semantica/ 2>&1 | Out-Null
|
||||
Write-Host "✅ mypy check passed" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "⚠️ Type checking issues found (non-blocking)" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "✅ All code quality checks passed!" -ForegroundColor Green
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
# Code quality check script
|
||||
# Runs formatting, import sorting, linting, and type checking
|
||||
|
||||
set -e
|
||||
|
||||
echo "🔍 Running code quality checks..."
|
||||
|
||||
# Activate virtual environment if it exists
|
||||
if [ -d "venv" ]; then
|
||||
source venv/bin/activate
|
||||
fi
|
||||
|
||||
# Check if directories exist
|
||||
if [ ! -d "semantica" ]; then
|
||||
echo "❌ semantica/ directory not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check formatting
|
||||
echo "📝 Checking code formatting (black)..."
|
||||
if black --check semantica/ 2>/dev/null; then
|
||||
echo "✅ Black check passed"
|
||||
else
|
||||
echo "❌ Code formatting issues found"
|
||||
echo " Run: black semantica/"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check import sorting
|
||||
echo "📦 Checking import sorting (isort)..."
|
||||
if isort --check-only semantica/ 2>/dev/null; then
|
||||
echo "✅ isort check passed"
|
||||
else
|
||||
echo "❌ Import sorting issues found"
|
||||
echo " Run: isort semantica/"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Lint with flake8
|
||||
echo "🔎 Linting with flake8..."
|
||||
if flake8 semantica/; then
|
||||
echo "✅ flake8 check passed"
|
||||
else
|
||||
echo "❌ Linting issues found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Type check with mypy (non-blocking)
|
||||
echo "🔬 Type checking with mypy..."
|
||||
if mypy semantica/ 2>/dev/null; then
|
||||
echo "✅ mypy check passed"
|
||||
else
|
||||
echo "⚠️ Type checking issues found (non-blocking)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "✅ All code quality checks passed!"
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# Code formatting script (PowerShell)
|
||||
# Formats code with black and sorts imports with isort
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
Write-Host "🎨 Formatting code..." -ForegroundColor Cyan
|
||||
|
||||
# Activate virtual environment if it exists
|
||||
if (Test-Path "venv") {
|
||||
& .\venv\Scripts\Activate.ps1
|
||||
}
|
||||
|
||||
# Check if directories exist
|
||||
if (-not (Test-Path "semantica")) {
|
||||
Write-Host "❌ semantica/ directory not found" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Format with black
|
||||
Write-Host "📝 Formatting with black..." -ForegroundColor Yellow
|
||||
black semantica/
|
||||
Write-Host "✅ Black formatting complete" -ForegroundColor Green
|
||||
|
||||
# Sort imports with isort
|
||||
Write-Host "📦 Sorting imports with isort..." -ForegroundColor Yellow
|
||||
isort semantica/
|
||||
Write-Host "✅ Import sorting complete" -ForegroundColor Green
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "✅ Code formatting complete!" -ForegroundColor Green
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
# Code formatting script
|
||||
# Formats code with black and sorts imports with isort
|
||||
|
||||
set -e
|
||||
|
||||
echo "🎨 Formatting code..."
|
||||
|
||||
# Activate virtual environment if it exists
|
||||
if [ -d "venv" ]; then
|
||||
source venv/bin/activate
|
||||
fi
|
||||
|
||||
# Check if directories exist
|
||||
if [ ! -d "semantica" ]; then
|
||||
echo "❌ semantica/ directory not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Format with black
|
||||
echo "📝 Formatting with black..."
|
||||
black semantica/
|
||||
echo "✅ Black formatting complete"
|
||||
|
||||
# Sort imports with isort
|
||||
echo "📦 Sorting imports with isort..."
|
||||
isort semantica/
|
||||
echo "✅ Import sorting complete"
|
||||
|
||||
echo ""
|
||||
echo "✅ Code formatting complete!"
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# Test runner script (PowerShell)
|
||||
# Runs tests with coverage reporting
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
Write-Host "🧪 Running tests..." -ForegroundColor Cyan
|
||||
|
||||
# Activate virtual environment if it exists
|
||||
if (Test-Path "venv") {
|
||||
& .\venv\Scripts\Activate.ps1
|
||||
}
|
||||
|
||||
# Check if tests directory exists
|
||||
if (-not (Test-Path "tests")) {
|
||||
Write-Host "⚠️ No tests directory found" -ForegroundColor Yellow
|
||||
Write-Host " Create tests/ directory and add test files" -ForegroundColor Yellow
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Check if test files exist
|
||||
$testFiles = Get-ChildItem -Path tests -Recurse -Include "test_*.py", "*_test.py" -ErrorAction SilentlyContinue
|
||||
if (-not $testFiles) {
|
||||
Write-Host "⚠️ No test files found" -ForegroundColor Yellow
|
||||
Write-Host " Add test files to tests/ directory" -ForegroundColor Yellow
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Run tests with coverage
|
||||
Write-Host "📊 Running pytest with coverage..." -ForegroundColor Yellow
|
||||
pytest `
|
||||
--cov=semantica `
|
||||
--cov-report=html `
|
||||
--cov-report=term-missing `
|
||||
--cov-report=xml `
|
||||
-v `
|
||||
tests/
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "✅ Tests complete!" -ForegroundColor Green
|
||||
Write-Host "📊 Coverage report: htmlcov/index.html" -ForegroundColor Cyan
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
# Test runner script
|
||||
# Runs tests with coverage reporting
|
||||
|
||||
set -e
|
||||
|
||||
echo "🧪 Running tests..."
|
||||
|
||||
# Activate virtual environment if it exists
|
||||
if [ -d "venv" ]; then
|
||||
source venv/bin/activate
|
||||
fi
|
||||
|
||||
# Check if tests directory exists
|
||||
if [ ! -d "tests" ]; then
|
||||
echo "⚠️ No tests directory found"
|
||||
echo " Create tests/ directory and add test files"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if test files exist
|
||||
if [ -z "$(find tests -name 'test_*.py' -o -name '*_test.py' 2>/dev/null)" ]; then
|
||||
echo "⚠️ No test files found"
|
||||
echo " Add test files to tests/ directory"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Run tests with coverage
|
||||
echo "📊 Running pytest with coverage..."
|
||||
pytest \
|
||||
--cov=semantica \
|
||||
--cov-report=html \
|
||||
--cov-report=term-missing \
|
||||
--cov-report=xml \
|
||||
-v \
|
||||
tests/
|
||||
|
||||
echo ""
|
||||
echo "✅ Tests complete!"
|
||||
echo "📊 Coverage report: htmlcov/index.html"
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
# Development environment setup script (PowerShell)
|
||||
# Sets up Python virtual environment and installs dependencies
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
Write-Host "🚀 Setting up development environment..." -ForegroundColor Cyan
|
||||
|
||||
# Check Python version
|
||||
try {
|
||||
$pythonVersion = python --version 2>&1
|
||||
Write-Host "📦 $pythonVersion" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "❌ Python not found. Please install Python 3.10 or higher" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Create virtual environment if it doesn't exist
|
||||
if (-not (Test-Path "venv")) {
|
||||
Write-Host "📦 Creating virtual environment..." -ForegroundColor Yellow
|
||||
python -m venv venv
|
||||
} else {
|
||||
Write-Host "✅ Virtual environment already exists" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Activate virtual environment
|
||||
Write-Host "🔌 Activating virtual environment..." -ForegroundColor Yellow
|
||||
& .\venv\Scripts\Activate.ps1
|
||||
|
||||
# Upgrade pip
|
||||
Write-Host "⬆️ Upgrading pip..." -ForegroundColor Yellow
|
||||
python -m pip install --upgrade pip
|
||||
|
||||
# Install project in editable mode with dev dependencies
|
||||
Write-Host "📥 Installing package with dev dependencies..." -ForegroundColor Yellow
|
||||
pip install -e ".[dev]"
|
||||
|
||||
# Install pre-commit hooks if available
|
||||
try {
|
||||
$precommit = Get-Command pre-commit -ErrorAction SilentlyContinue
|
||||
if ($precommit) {
|
||||
Write-Host "🪝 Installing pre-commit hooks..." -ForegroundColor Yellow
|
||||
pre-commit install
|
||||
} else {
|
||||
Write-Host "⚠️ pre-commit not found, skipping hooks installation" -ForegroundColor Yellow
|
||||
}
|
||||
} catch {
|
||||
Write-Host "⚠️ Pre-commit installation skipped" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Verify installation
|
||||
Write-Host "✅ Verifying installation..." -ForegroundColor Yellow
|
||||
try {
|
||||
python -c "import semantica; print(f'Semantica version: {semantica.__version__}')"
|
||||
Write-Host "✅ Installation verified" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "❌ Installation verification failed" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "✨ Development environment setup complete!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Next steps:" -ForegroundColor Cyan
|
||||
Write-Host " .\venv\Scripts\Activate.ps1 # Activate virtual environment" -ForegroundColor White
|
||||
Write-Host " pytest # Run tests" -ForegroundColor White
|
||||
Write-Host " black semantica/ # Format code" -ForegroundColor White
|
||||
Write-Host " .github\scripts\check-code.ps1 # Run all checks" -ForegroundColor White
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
# Development environment setup script
|
||||
# Sets up Python virtual environment and installs dependencies
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 Setting up development environment..."
|
||||
|
||||
# Check Python version
|
||||
if ! command -v python3 &> /dev/null; then
|
||||
echo "❌ Python 3 not found. Please install Python 3.10 or higher"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
python_version=$(python3 --version 2>&1 | awk '{print $2}')
|
||||
echo "📦 Python version: $python_version"
|
||||
|
||||
# Create virtual environment if it doesn't exist
|
||||
if [ ! -d "venv" ]; then
|
||||
echo "📦 Creating virtual environment..."
|
||||
python3 -m venv venv
|
||||
else
|
||||
echo "✅ Virtual environment already exists"
|
||||
fi
|
||||
|
||||
# Activate virtual environment
|
||||
echo "🔌 Activating virtual environment..."
|
||||
source venv/bin/activate
|
||||
|
||||
# Upgrade pip
|
||||
echo "⬆️ Upgrading pip..."
|
||||
python -m pip install --upgrade pip
|
||||
|
||||
# Install project in editable mode with dev dependencies
|
||||
echo "📥 Installing package with dev dependencies..."
|
||||
pip install -e ".[dev]"
|
||||
|
||||
# Install pre-commit hooks if available
|
||||
if command -v pre-commit &> /dev/null; then
|
||||
echo "🪝 Installing pre-commit hooks..."
|
||||
pre-commit install || echo "⚠️ Pre-commit installation skipped"
|
||||
else
|
||||
echo "⚠️ pre-commit not found, skipping hooks installation"
|
||||
fi
|
||||
|
||||
# Verify installation
|
||||
echo "✅ Verifying installation..."
|
||||
if python -c "import semantica; print(f'Semantica version: {semantica.__version__}')" 2>/dev/null; then
|
||||
echo "✅ Installation verified"
|
||||
else
|
||||
echo "❌ Installation verification failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "✨ Development environment setup complete!"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo " source venv/bin/activate # Activate virtual environment"
|
||||
echo " pytest # Run tests"
|
||||
echo " black semantica/ # Format code"
|
||||
echo " .github/scripts/check-code.sh # Run all checks"
|
||||
|
||||
Reference in New Issue
Block a user