@@ -13,55 +13,53 @@ jobs:
1313
1414 - name : Check packages exist in Homebrew
1515 run : |
16- pip3 install pyyaml -q
17- python3 - << 'EOF'
18- import subprocess, sys, yaml
16+ CATALOG="internal/config/data/packages.yaml"
17+ failed=()
1918
20- with open("internal/config/data/packages.yaml") as f:
21- data = yaml.safe_load(f)
19+ # Extract all package names (lines matching " - name: <value>")
20+ # then pair with their type by reading surrounding context
21+ while IFS= read -r line; do
22+ name=$(echo "$line" | sed 's/.*- name: //' | tr -d ' ')
23+ [[ -z "$name" ]] && continue
2224
23- formulae, casks, taps_needed = [], [], set()
25+ # Skip category names (they appear as " - name: Category")
26+ # Package names are indented with 6 spaces
27+ indent=$(echo "$line" | sed 's/[^ ].*//' | wc -c)
28+ [[ $indent -lt 7 ]] && continue
2429
25- for category in data.get("categories", []):
26- for pkg in category.get("packages", []):
27- name = pkg["name"]
28- if pkg.get("npm"):
29- continue # npm packages not validated here
30- if pkg.get("cask"):
31- casks.append(name)
32- else:
33- formulae.append(name)
34- # tap-qualified: owner/repo/formula
35- parts = name.split("/")
36- if len(parts) == 3:
37- taps_needed.add(f"{parts[0]}/{parts[1]}")
30+ # Check if this package is a cask (look ahead in file)
31+ is_cask=$(awk "/- name: ${name}$/,/- name:/" "$CATALOG" | grep -c "cask: true" || true)
32+ is_npm=$(awk "/- name: ${name}$/,/- name:/" "$CATALOG" | grep -c "npm: true" || true)
3833
39- # Add required taps
40- for tap in taps_needed:
41- subprocess.run(["brew", "tap", tap], capture_output=True)
34+ [[ $is_npm -gt 0 ]] && continue # skip npm packages
4235
43- failed = []
36+ # For tap-qualified names (owner/repo/formula), add tap first
37+ slash_count=$(echo "$name" | tr -cd '/' | wc -c)
38+ if [[ $slash_count -eq 2 ]]; then
39+ tap=$(echo "$name" | cut -d'/' -f1-2)
40+ brew tap "$tap" --quiet 2>/dev/null || true
41+ fi
4442
45- print(f"Checking {len(formulae)} formulae and {len(casks)} casks...\n")
43+ if [[ $is_cask -gt 0 ]]; then
44+ if ! brew info --cask "$name" &>/dev/null; then
45+ echo " MISSING cask: $name"
46+ failed+=("$name")
47+ fi
48+ else
49+ if ! brew info "$name" &>/dev/null; then
50+ echo " MISSING formula: $name"
51+ failed+=("$name")
52+ fi
53+ fi
54+ done < <(grep -n " - name: " "$CATALOG")
4655
47- for name in formulae:
48- result = subprocess.run(["brew", "info", name], capture_output=True)
49- if result.returncode != 0:
50- print(f" MISSING formula: {name}")
51- failed.append(name)
52-
53- for name in casks:
54- result = subprocess.run(["brew", "info", "--cask", name], capture_output=True)
55- if result.returncode != 0:
56- print(f" MISSING cask: {name}")
57- failed.append(name)
58-
59- if failed:
60- print(f"\n{len(failed)} package(s) not found in Homebrew:")
61- for name in failed:
62- print(f" - {name}")
63- print("\nUpdate packages.yaml to fix or remove these entries.")
64- sys.exit(1)
65- else:
66- print(f"All packages validated OK.")
67- EOF
56+ echo ""
57+ if [[ ${#failed[@]} -gt 0 ]]; then
58+ echo "${#failed[@]} package(s) not found in Homebrew:"
59+ for p in "${failed[@]}"; do echo " - $p"; done
60+ echo ""
61+ echo "Update packages.yaml to fix or remove these entries."
62+ exit 1
63+ else
64+ echo "All packages validated OK."
65+ fi
0 commit comments