diff --git a/Jenkinsfile b/Jenkinsfile index deff535..8db56ef 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,10 @@ pipeline { agent { label 'rust_no_docker' } + environment { + VENV = '.venv' + } + stages { stage('Checkout') { steps { @@ -18,166 +22,51 @@ pipeline { } } + stage('Setup Python') { + steps { + sh ''' + set -eu + + if ! command -v uv >/dev/null 2>&1; then + echo "uv not found — installing it..." + + if ! command -v cargo-binstall >/dev/null 2>&1; then + echo "cargo-binstall not found — installing it..." + cargo install cargo-binstall + fi + + cargo binstall --no-confirm uv + else + echo "uv already installed." + fi + + echo "Using:" + uv --version + + rm -rf "${VENV}" + + echo "Creating virtual environment..." + uv venv "${VENV}" + + echo "Installing CI dependencies..." + uv pip install \ + --python "${VENV}/bin/python" \ + -r requirements-ci.txt + + echo + echo "Python:" + "${VENV}/bin/python" --version + ''' + } + } + stage('Check Database Integrity') { steps { sh ''' set -eu - python3 <<'PY' -import sqlite3 -import subprocess -import sys -from pathlib import Path - - -def tracked_databases(): - result = subprocess.run( - ["git", "ls-files"], - check=True, - capture_output=True, - text=True, - ) - - extensions = {".db", ".sqlite", ".sqlite3"} - - return [ - Path(filename) - for filename in result.stdout.splitlines() - if Path(filename).suffix.lower() in extensions - ] - - -def check_database(path: Path) -> bool: - print("=" * 70) - print(f"Checking: {path}") - print("=" * 70) - - try: - # Open read-only: CI must never modify the database being checked. - uri = f"{path.resolve().as_uri()}?mode=ro" - connection = sqlite3.connect(uri, uri=True) - - except sqlite3.Error as error: - print(f"✗ Cannot open database: {error}", file=sys.stderr) - return False - - success = True - - try: - cursor = connection.cursor() - - # ------------------------------------------------------------- - # SQLite quick structural check - # ------------------------------------------------------------- - print(" quick_check ... ", end="", flush=True) - - result = cursor.execute("PRAGMA quick_check").fetchall() - - if result == [("ok",)]: - print("OK") - else: - print("FAILED") - success = False - - for row in result: - print(f" {row[0]}", file=sys.stderr) - - # ------------------------------------------------------------- - # Full integrity check - # ------------------------------------------------------------- - print(" integrity_check ... ", end="", flush=True) - - result = cursor.execute("PRAGMA integrity_check").fetchall() - - if result == [("ok",)]: - print("OK") - else: - print("FAILED") - success = False - - for row in result: - print(f" {row[0]}", file=sys.stderr) - - # ------------------------------------------------------------- - # Foreign key consistency - # ------------------------------------------------------------- - print(" foreign_key_check ... ", end="", flush=True) - - foreign_key_errors = cursor.execute( - "PRAGMA foreign_key_check" - ).fetchall() - - if not foreign_key_errors: - print("OK") - else: - print("FAILED") - success = False - - for row in foreign_key_errors: - print( - " " - f"table={row[0]}, " - f"rowid={row[1]}, " - f"parent={row[2]}, " - f"fk={row[3]}", - file=sys.stderr, - ) - - except sqlite3.Error as error: - print(f"✗ SQLite error: {error}", file=sys.stderr) - success = False - - finally: - connection.close() - - if success: - print(f"✓ {path} is healthy") - else: - print(f"✗ {path} failed integrity checks", file=sys.stderr) - - print() - - return success - - -databases = tracked_databases() - -if not databases: - print( - "ERROR: no tracked SQLite databases found.", - file=sys.stderr, - ) - sys.exit(1) - -print("Databases to check:") - -for database in databases: - print(f" - {database}") - -print() - -failed = [] - -for database in databases: - if not check_database(database): - failed.append(database) - - -print("=" * 70) - -if failed: - print("DATABASE INTEGRITY CHECK FAILED") - print() - - for database in failed: - print(f" ✗ {database}") - - sys.exit(1) - -print( - f"✓ All {len(databases)} database(s) passed integrity checks." -) -PY + "${VENV}/bin/python" \ + tools/check_databases.py ''' } } @@ -189,7 +78,7 @@ PY conclusion: 'SUCCESS', name: 'Database Integrity', summary: 'All Ravenous databases passed integrity checks.', - text: 'SQLite structural integrity and foreign-key checks completed successfully.', + text: 'SQLite integrity and foreign-key validation completed successfully.', title: 'Database integrity successful' ) @@ -200,12 +89,12 @@ PY publishChecks( conclusion: 'FAILURE', name: 'Database Integrity', - summary: 'At least one Ravenous database failed an integrity check.', - text: 'Check the Jenkins log for SQLite integrity or foreign-key errors.', + summary: 'At least one Ravenous database failed validation.', + text: 'Check the Jenkins log for database integrity or environment errors.', title: 'Database integrity failed' ) - echo '❌ A Ravenous database failed its integrity checks.' + echo '❌ Ravenous database integrity CI failed.' } unstable { @@ -219,5 +108,11 @@ PY echo '⚠️ Ravenous database integrity CI is unstable.' } + + always { + sh ''' + rm -rf .venv + ''' + } } } \ No newline at end of file