|
1 | 1 | import os |
2 | | -import shutil |
3 | 2 | import subprocess |
4 | 3 | import re |
5 | 4 | import json |
| 5 | +import logging |
6 | 6 | from git import Repo |
7 | 7 |
|
8 | 8 | kb_file_path = './data/knowledge_base.json' |
@@ -32,21 +32,43 @@ def setup_repositories(): |
32 | 32 | for repo_name, repo_url in repos.items(): |
33 | 33 | clone_repository(repo_url, os.path.join(tmp_dir, repo_name)) |
34 | 34 |
|
| 35 | +def run_command(command, label): |
| 36 | + """Helper function to run a command and log its output""" |
| 37 | + process = subprocess.Popen( |
| 38 | + command, |
| 39 | + stdout=subprocess.PIPE, |
| 40 | + stderr=subprocess.PIPE, |
| 41 | + text=True, |
| 42 | + bufsize=1, |
| 43 | + universal_newlines=True |
| 44 | + ) |
| 45 | + |
| 46 | + # log stdout |
| 47 | + for line in iter(process.stdout.readline, ''): |
| 48 | + if line.strip(): |
| 49 | + logging.info(f"{label}: {line.rstrip()}") |
| 50 | + |
| 51 | + # log stderr |
| 52 | + for line in iter(process.stderr.readline, ''): |
| 53 | + if line.strip(): |
| 54 | + logging.error(f"{label}: {line.rstrip()}") |
| 55 | + |
| 56 | + # Wait for process to complete and check return code |
| 57 | + return_code = process.wait() |
| 58 | + if return_code != 0: |
| 59 | + raise subprocess.CalledProcessError(return_code, command) |
| 60 | + |
35 | 61 | def run_prebuild_script(): |
36 | 62 | """ Run the defang-docs repo prebuild script""" |
37 | 63 |
|
38 | | - subprocess.run( |
| 64 | + run_command( |
39 | 65 | ["npm", "-C", ".tmp/defang-docs", "install"], |
40 | | - check=True, |
41 | | - stdout=subprocess.PIPE, |
42 | | - stderr=subprocess.PIPE |
| 66 | + "npm install" |
43 | 67 | ) |
44 | 68 |
|
45 | | - subprocess.run( |
| 69 | + run_command( |
46 | 70 | ["npm", "-C", ".tmp/defang-docs", "run", "prebuild"], |
47 | | - check=True, |
48 | | - stdout=subprocess.PIPE, |
49 | | - stderr=subprocess.PIPE |
| 71 | + "npm run prebuild" |
50 | 72 | ) |
51 | 73 |
|
52 | 74 | def parse_markdown(): |
|
0 commit comments