// Add this webhook in Gitea: // http://192.168.1.37:8080/gitea-webhook/post pipeline { agent { label 'rust_no_docker' } stages { stage('Checkout') { steps { checkout scm sh ''' set -e git submodule sync --recursive git submodule update --init --recursive ''' } } 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 ''' } } } post { success { publishChecks( conclusion: 'SUCCESS', name: 'Database Integrity', summary: 'All Ravenous databases passed integrity checks.', text: 'SQLite structural integrity and foreign-key checks completed successfully.', title: 'Database integrity successful' ) echo '✅ All Ravenous databases passed integrity checks.' } failure { 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.', title: 'Database integrity failed' ) echo '❌ A Ravenous database failed its integrity checks.' } unstable { publishChecks( conclusion: 'ACTION_REQUIRED', name: 'Database Integrity', summary: 'The Ravenous database integrity job is unstable.', text: 'Check the Jenkins build log.', title: 'Database integrity unstable' ) echo '⚠️ Ravenous database integrity CI is unstable.' } } }