msse-ai-engineering / dev-tools /local-ci-check.sh
Tobias Pasquale
fix: Remove trailing whitespace and add end-of-file newlines
1589e06
#!/bin/bash
# Local CI/CD Pipeline Check Script
# This script mirrors the GitHub Actions CI/CD pipeline for local testing
# Run this before pushing to ensure your code will pass CI/CD checks
set -e # Exit on first error
echo "πŸ” Starting Local CI/CD Pipeline Check..."
echo "========================================"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print section headers
print_section() {
echo -e "\n${BLUE}πŸ“‹ $1${NC}"
echo "----------------------------------------"
}
# Function to print success
print_success() {
echo -e "${GREEN}βœ… $1${NC}"
}
# Function to print error
print_error() {
echo -e "${RED}❌ $1${NC}"
}
# Function to print warning
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
# Track if any checks failed
FAILED=0
print_section "Code Formatting Check (Black)"
echo "Running: black --check ."
if black --check .; then
print_success "Black formatting check passed"
else
print_error "Black formatting check failed"
echo "πŸ’‘ Fix with: black ."
FAILED=1
fi
print_section "Import Sorting Check (isort)"
echo "Running: isort --check-only ."
if isort --check-only .; then
print_success "Import sorting check passed"
else
print_error "Import sorting check failed"
echo "πŸ’‘ Fix with: isort ."
FAILED=1
fi
print_section "Linting Check (flake8)"
echo "Running: flake8 --max-line-length=88 --exclude venv"
if flake8 --max-line-length=88 --exclude venv; then
print_success "Linting check passed"
else
print_error "Linting check failed"
echo "πŸ’‘ Fix manually or with: autopep8 --in-place --aggressive --aggressive ."
FAILED=1
fi
print_section "Python Tests"
echo "Running: ./venv/bin/python -m pytest -v"
if [ -f "./venv/bin/python" ]; then
if ./venv/bin/python -m pytest -v; then
print_success "All tests passed"
else
print_error "Tests failed"
echo "πŸ’‘ Fix failing tests before pushing"
FAILED=1
fi
else
print_warning "Virtual environment not found, skipping tests"
echo "πŸ’‘ Run tests with: ./venv/bin/python -m pytest -v"
fi
print_section "Git Status Check"
if [ -n "$(git status --porcelain)" ]; then
print_warning "Uncommitted changes detected:"
git status --porcelain
echo "πŸ’‘ Consider committing your changes"
else
print_success "Working directory clean"
fi
# Final result
echo ""
echo "========================================"
if [ $FAILED -eq 0 ]; then
print_success "πŸŽ‰ All CI/CD checks passed! Ready to push."
echo ""
echo "Your code should pass the GitHub Actions pipeline."
echo "You can now safely run: git push origin $(git branch --show-current)"
else
print_error "🚨 CI/CD checks failed!"
echo ""
echo "Please fix the issues above before pushing."
echo "This will prevent CI/CD pipeline failures on GitHub."
exit 1
fi