mvp-factory-openhands/test-scripts/build_and_test.py

110 lines
2.9 KiB
Python

#!/usr/bin/env python3
import subprocess
import os
import sys
def run_command(command, cwd=None, description=""):
"""Run a command and return success status"""
print(f"\n{description}")
print(f"Running: {command}")
try:
result = subprocess.run(
command,
shell=True,
cwd=cwd,
capture_output=True,
text=True,
check=False
)
if result.stdout:
print("STDOUT:", result.stdout)
if result.stderr:
print("STDERR:", result.stderr)
success = result.returncode == 0
if success:
print(f"{description} completed successfully")
else:
print(f"{description} failed with return code {result.returncode}")
return success, result
except Exception as e:
print(f"✗ Exception occurred: {e}")
return False, None
def main():
print('=== Building and Testing phase3-test project ===')
base_dir = '/home/bam'
repo_dir = os.path.join(base_dir, 'phase3-test')
repo_url = 'https://git.oky.sh/gitadmin/phase3-test.git'
# Step 1: Clone the repository
if os.path.exists(repo_dir):
print(f"\nRemoving existing project directory: {repo_dir}")
try:
import shutil
shutil.rmtree(repo_dir)
print("✓ Existing directory removed")
except Exception as e:
print(f"✗ Failed to remove directory: {e}")
success, _ = run_command(
f'git clone {repo_url}',
cwd=base_dir,
description="Cloning repository from git.oky.sh"
)
if not success:
print("Failed to clone repository. Exiting.")
sys.exit(1)
# Step 2: Check out main branch and show latest commit
print(f"\nChecking out main branch in {repo_dir}")
run_command('git checkout main', cwd=repo_dir, description="Checkout main branch")
success, result = run_command(
'git log -1 --pretty=format:"%s"',
cwd=repo_dir,
description="Getting latest commit"
)
if success and result:
commit_msg = result.stdout.strip()
print(f"Latest commit: \"{commit_msg}\"")
# Step 3: Install dependencies
run_command(
'npm install',
cwd=repo_dir,
description="Installing npm dependencies"
)
# Step 4: Run tests
print("\n" + "="*50)
print("RUNNING TESTS")
print("="*50)
run_command(
'npm test',
cwd=repo_dir,
description="Running test suite"
)
# Step 5: Build project
print("\n" + "="*50)
print("BUILDING PROJECT")
print("="*50)
run_command(
'npm run build',
cwd=repo_dir,
description="Building project"
)
print("\n=== Build and test process completed ===")
if __name__ == "__main__":
main()