Skip to content

Commit a24b9ca

Browse files
committed
Refactor CI clone step to read PACKAGES config
1 parent eb29555 commit a24b9ca

3 files changed

Lines changed: 73 additions & 18 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,7 @@ jobs:
3636
python -m ipykernel install --user --name python3 --display-name "Python 3"
3737
3838
- name: Clone PathSim repositories
39-
run: |
40-
git clone https://github.com/pathsim/pathsim.git ../pathsim || { echo "Failed to clone pathsim"; exit 1; }
41-
git clone https://github.com/pathsim/pathsim-chem.git ../pathsim-chem || { echo "Failed to clone pathsim-chem"; exit 1; }
42-
git clone https://github.com/pathsim/pathsim-vehicle.git ../pathsim-vehicle || { echo "Failed to clone pathsim-vehicle"; exit 1; }
43-
git clone https://github.com/pathsim/pathsim-flight.git ../pathsim-flight || echo "Skipping pathsim-flight (not available)"
44-
git clone https://github.com/pathsim/pathsim-rf.git ../pathsim-rf || echo "Skipping pathsim-rf (not available)"
45-
46-
- name: Fetch all tags
47-
run: |
48-
for repo in pathsim pathsim-chem pathsim-vehicle pathsim-flight pathsim-rf; do
49-
if [ -d "../$repo" ]; then
50-
git -C ../$repo fetch --tags
51-
latest_tag=$(git -C ../$repo describe --tags --abbrev=0 2>/dev/null || echo 'no tags')
52-
echo "✓ $repo: latest_tag=$latest_tag"
53-
else
54-
echo "⊘ $repo: not cloned, skipping"
55-
fi
56-
done
39+
run: python scripts/clone-repos.py
5740

5841
# Build all versions (API, notebooks, outputs, figures, roadmaps)
5942
# Uses smart caching: historical versions only built once, latest always rebuilt

scripts/clone-repos.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python3
2+
"""Clone all PathSim package repositories declared in lib.config.PACKAGES.
3+
4+
Idempotent: skips clone when target directory already exists.
5+
Required repos that fail to clone produce a non-zero exit; optional repos
6+
(``required: False``) only emit a warning. Tags are fetched after each clone
7+
and the latest tag is logged.
8+
"""
9+
10+
from __future__ import annotations
11+
12+
import subprocess
13+
import sys
14+
from pathlib import Path
15+
16+
SCRIPT_DIR = Path(__file__).resolve().parent
17+
sys.path.insert(0, str(SCRIPT_DIR))
18+
19+
from lib.config import PACKAGES, ROOT_DIR # noqa: E402
20+
21+
22+
def clone(github_repo: str, dest: Path, required: bool) -> bool:
23+
if dest.exists():
24+
print(f"✓ {dest.name}: already present")
25+
return True
26+
url = f"https://github.com/{github_repo}.git"
27+
print(f" Cloning {github_repo}{dest} ...")
28+
result = subprocess.run(["git", "clone", url, str(dest)])
29+
if result.returncode == 0:
30+
return True
31+
if required:
32+
print(f"✗ Failed to clone {github_repo} (required)")
33+
return False
34+
print(f"⊘ Skipping {github_repo} (not available)")
35+
return True
36+
37+
38+
def fetch_tags(dest: Path) -> None:
39+
if not dest.exists():
40+
return
41+
subprocess.run(["git", "-C", str(dest), "fetch", "--tags"], check=False)
42+
result = subprocess.run(
43+
["git", "-C", str(dest), "describe", "--tags", "--abbrev=0"],
44+
capture_output=True, text=True,
45+
)
46+
latest = result.stdout.strip() if result.returncode == 0 and result.stdout.strip() else "no tags"
47+
print(f" {dest.name}: latest_tag={latest}")
48+
49+
50+
def main() -> int:
51+
failures: list[str] = []
52+
for pkg_id, pkg in PACKAGES.items():
53+
github_repo = pkg["github_repo"]
54+
required = pkg.get("required", True)
55+
dest = ROOT_DIR / github_repo.split("/")[-1]
56+
if not clone(github_repo, dest, required):
57+
failures.append(github_repo)
58+
continue
59+
fetch_tags(dest)
60+
61+
if failures:
62+
print("\nRequired repos failed to clone:")
63+
for repo in failures:
64+
print(f" - {repo}")
65+
return 1
66+
return 0
67+
68+
69+
if __name__ == "__main__":
70+
sys.exit(main())

scripts/lib/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"root_modules": [
7373
"pathsim_flight",
7474
],
75+
"required": False,
7576
},
7677
"rf": {
7778
"repo": ROOT_DIR / "pathsim-rf",
@@ -84,6 +85,7 @@
8485
"root_modules": [
8586
"pathsim_rf",
8687
],
88+
"required": False,
8789
},
8890
}
8991

0 commit comments

Comments
 (0)