Skip to content

Commit ef5db56

Browse files
use script for the action as well
1 parent 76c98de commit ef5db56

File tree

3 files changed

+145
-63
lines changed

3 files changed

+145
-63
lines changed

.github/scripts/add_missing_plugins.py

Lines changed: 90 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python3
22
"""
3-
Add missing plugin directories to the configuration files.
3+
Add missing plugins to all configuration files.
44
55
This script scans the repository for plugin directories (sam-*) and adds
6-
any missing ones to:
6+
any missing plugins to:
77
- .github/workflows/build-plugin.yaml
8+
- .github/workflows/sync-plugin-configs.yaml (paths exclusions)
89
- .release-please-manifest.json
910
- release-please-config.json
1011
- .github/pr_labeler.yaml
@@ -13,7 +14,6 @@
1314
from __future__ import annotations
1415

1516
import json
16-
import os
1717
import re
1818
import sys
1919
from pathlib import Path
@@ -31,21 +31,24 @@ def get_plugin_directories(repo_root: Path) -> Set[str]:
3131
return plugins
3232

3333

34-
def get_package_name(plugin_name: str) -> str:
35-
"""Convert plugin directory name to Python package name."""
36-
return plugin_name.replace("-", "_")
34+
def get_package_name(plugin_dir: str) -> str:
35+
"""Convert plugin directory name to package name."""
36+
# sam-foo-bar -> solace_agent_mesh_foo_bar
37+
suffix = plugin_dir.replace("sam-", "").replace("-", "_")
38+
return f"solace_agent_mesh_{suffix}"
3739

3840

3941
def update_build_workflow(repo_root: Path, plugins: Set[str]) -> bool:
40-
"""Update build-plugin.yaml with missing plugins."""
42+
"""Update .github/workflows/build-plugin.yaml with missing plugins."""
4143
workflow_path = repo_root / ".github" / "workflows" / "build-plugin.yaml"
44+
4245
if not workflow_path.exists():
4346
print(f" ⚠️ {workflow_path} does not exist, skipping")
4447
return False
4548

4649
content = workflow_path.read_text()
4750

48-
# Find existing plugins in options
51+
# Find existing plugins in options (lines like " - sam-foo")
4952
existing_plugins = set()
5053
for match in re.finditer(r"^\s*-\s*(sam-[\w-]+)\s*$", content, re.MULTILINE):
5154
existing_plugins.add(match.group(1))
@@ -55,49 +58,77 @@ def update_build_workflow(repo_root: Path, plugins: Set[str]) -> bool:
5558
print(" ✅ build-plugin.yaml already has all plugins")
5659
return False
5760

58-
# Find the options block and add missing plugins
61+
# Find the last plugin option and add after it
5962
lines = content.split("\n")
60-
new_lines = []
61-
in_options = False
62-
options_indent = None
6363
last_option_idx = -1
64+
indent = " " # Default indent
6465

6566
for i, line in enumerate(lines):
66-
new_lines.append(line)
67-
if "options:" in line and "plugin_directory" in "\n".join(
68-
lines[max(0, i - 5) : i]
69-
):
70-
in_options = True
71-
# Get indentation of next line (the first option)
72-
continue
73-
if in_options:
74-
match = re.match(r"^(\s*)-\s*sam-[\w-]+", line)
75-
if match:
76-
options_indent = match.group(1)
77-
last_option_idx = len(new_lines) - 1
78-
elif (
79-
line.strip()
80-
and not line.strip().startswith("-")
81-
and not line.strip().startswith("#")
82-
):
83-
# End of options block
84-
in_options = False
85-
86-
if last_option_idx > 0 and options_indent:
87-
# Insert missing plugins after the last option
88-
for plugin in sorted(missing):
89-
new_lines.insert(last_option_idx + 1, f"{options_indent}- {plugin}")
90-
last_option_idx += 1
91-
92-
workflow_path.write_text("\n".join(new_lines))
93-
print(f" ✅ Added {len(missing)} plugins to build-plugin.yaml:")
94-
for plugin in sorted(missing):
95-
print(f" - {plugin}")
96-
return True
97-
else:
67+
match = re.match(r"^(\s*)-\s*sam-[\w-]+\s*$", line)
68+
if match:
69+
indent = match.group(1)
70+
last_option_idx = i
71+
72+
if last_option_idx < 0:
9873
print(" ⚠️ Could not find options block in build-plugin.yaml")
9974
return False
10075

76+
# Insert missing plugins after the last option
77+
for plugin in sorted(missing, reverse=True):
78+
lines.insert(last_option_idx + 1, f"{indent}- {plugin}")
79+
80+
workflow_path.write_text("\n".join(lines))
81+
print(f" ✅ Added {len(missing)} plugins to build-plugin.yaml:")
82+
for plugin in sorted(missing):
83+
print(f" + {plugin}")
84+
return True
85+
86+
87+
def update_sync_workflow(repo_root: Path, plugins: Set[str]) -> bool:
88+
"""Update .github/workflows/sync-plugin-configs.yaml paths exclusions with missing plugins."""
89+
workflow_path = repo_root / ".github" / "workflows" / "sync-plugin-configs.yaml"
90+
91+
if not workflow_path.exists():
92+
print(f" ⚠️ {workflow_path} does not exist, skipping")
93+
return False
94+
95+
content = workflow_path.read_text()
96+
97+
# Find existing plugins in paths exclusions (! prefix)
98+
existing_plugins = set()
99+
for match in re.finditer(r'^\s*-\s*"!(sam-[\w-]+)/\*\*"', content, re.MULTILINE):
100+
existing_plugins.add(match.group(1))
101+
102+
missing = plugins - existing_plugins
103+
if not missing:
104+
print(" ✅ sync-plugin-configs.yaml already has all plugins")
105+
return False
106+
107+
# Find the last exclusion pattern (lines with "!sam-*/**") and add after it
108+
lines = content.split("\n")
109+
last_exclusion_idx = -1
110+
indent = " " # Default indent
111+
112+
for i, line in enumerate(lines):
113+
match = re.match(r'^(\s*)-\s*"!sam-[\w-]+/\*\*"', line)
114+
if match:
115+
indent = match.group(1)
116+
last_exclusion_idx = i
117+
118+
if last_exclusion_idx < 0:
119+
print(" ⚠️ Could not find paths exclusions in sync-plugin-configs.yaml")
120+
return False
121+
122+
# Insert missing plugins after the last exclusion
123+
for plugin in sorted(missing, reverse=True):
124+
lines.insert(last_exclusion_idx + 1, f'{indent}- "!{plugin}/**"')
125+
126+
workflow_path.write_text("\n".join(lines))
127+
print(f" ✅ Added {len(missing)} plugins to sync-plugin-configs.yaml:")
128+
for plugin in sorted(missing):
129+
print(f" + {plugin}")
130+
return True
131+
101132

102133
def update_manifest(repo_root: Path, plugins: Set[str]) -> bool:
103134
"""Update .release-please-manifest.json with missing plugins."""
@@ -127,7 +158,7 @@ def update_manifest(repo_root: Path, plugins: Set[str]) -> bool:
127158

128159
print(f" ✅ Added {len(missing)} plugins to .release-please-manifest.json:")
129160
for plugin in sorted(missing):
130-
print(f" - {plugin}: 0.1.0")
161+
print(f" + {plugin}")
131162
return True
132163

133164

@@ -171,7 +202,7 @@ def update_release_config(repo_root: Path, plugins: Set[str]) -> bool:
171202

172203
print(f" ✅ Added {len(missing)} plugins to release-please-config.json:")
173204
for plugin in sorted(missing):
174-
print(f" - {plugin}")
205+
print(f" + {plugin}")
175206
return True
176207

177208

@@ -183,8 +214,7 @@ def update_pr_labeler(repo_root: Path, plugins: Set[str]) -> bool:
183214
content = labeler_path.read_text()
184215
else:
185216
content = """# PR Labeler configuration
186-
# Labels PRs based on which plugin directories have changes
187-
# Used by CI to determine which plugins to build and test
217+
# This file automatically labels PRs based on changed files.
188218
189219
"""
190220

@@ -201,10 +231,10 @@ def update_pr_labeler(repo_root: Path, plugins: Set[str]) -> bool:
201231
# Add missing plugins at the end
202232
new_entries = []
203233
for plugin in sorted(missing):
204-
new_entries.append(f"""
205-
{plugin}:
234+
new_entries.append(f"""{plugin}:
206235
- changed-files:
207-
- any-glob-to-any-file: {plugin}/**
236+
- any-glob-to-any-file: {plugin}/**
237+
208238
""")
209239

210240
content = content.rstrip() + "\n" + "".join(new_entries)
@@ -213,14 +243,14 @@ def update_pr_labeler(repo_root: Path, plugins: Set[str]) -> bool:
213243

214244
print(f" ✅ Added {len(missing)} plugins to pr_labeler.yaml:")
215245
for plugin in sorted(missing):
216-
print(f" - {plugin}")
246+
print(f" + {plugin}")
217247
return True
218248

219249

220250
def main():
221251
# Find repository root
222252
script_dir = Path(__file__).parent
223-
repo_root = script_dir.parent
253+
repo_root = script_dir.parent.parent
224254

225255
print(f"Repository root: {repo_root}")
226256
print()
@@ -240,6 +270,11 @@ def main():
240270
updated_any = True
241271
print()
242272

273+
print("Updating sync-plugin-configs.yaml...")
274+
if update_sync_workflow(repo_root, actual_plugins):
275+
updated_any = True
276+
print()
277+
243278
print("Updating .release-please-manifest.json...")
244279
if update_manifest(repo_root, actual_plugins):
245280
updated_any = True
@@ -257,7 +292,8 @@ def main():
257292

258293
# Summary
259294
if updated_any:
260-
print("✅ Configuration files have been updated!")
295+
print("=" * 50)
296+
print("✅ Configuration files updated successfully!")
261297
print(" Please review the changes and commit them.")
262298
else:
263299
print("✅ All configuration files are already up to date!")

.github/scripts/check_plugins.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
This script scans the repository for plugin directories (sam-*) and verifies
66
they are properly configured in:
77
- .github/workflows/build-plugin.yaml
8+
- .github/workflows/sync-plugin-configs.yaml (paths exclusions)
89
- .release-please-manifest.json
910
- release-please-config.json
1011
- .github/pr_labeler.yaml
@@ -13,7 +14,6 @@
1314
from __future__ import annotations
1415

1516
import json
16-
import os
1717
import re
1818
import sys
1919
from pathlib import Path
@@ -40,17 +40,15 @@ def get_plugins_from_build_workflow(repo_root: Path) -> Set[str]:
4040
content = workflow_path.read_text()
4141

4242
# Find the options list under workflow_dispatch
43-
# Look for the pattern after 'options:'
4443
plugins = set()
4544
in_options = False
4645
for line in content.split("\n"):
4746
if "options:" in line:
4847
in_options = True
4948
continue
5049
if in_options:
51-
# Check if we've exited the options block
5250
if line.strip() and not line.strip().startswith("-"):
53-
if not line.startswith(" " * 10): # Less indented than options
51+
if not line.startswith(" " * 10):
5452
break
5553
match = re.match(r"\s*-\s*(sam-[\w-]+)", line)
5654
if match:
@@ -59,6 +57,22 @@ def get_plugins_from_build_workflow(repo_root: Path) -> Set[str]:
5957
return plugins
6058

6159

60+
def get_plugins_from_sync_workflow(repo_root: Path) -> Set[str]:
61+
"""Extract plugin names from sync-plugin-configs.yaml paths exclusions (!)."""
62+
workflow_path = repo_root / ".github" / "workflows" / "sync-plugin-configs.yaml"
63+
if not workflow_path.exists():
64+
return set()
65+
66+
content = workflow_path.read_text()
67+
68+
# Find plugins in paths section with ! prefix (exclusions)
69+
plugins = set()
70+
for match in re.finditer(r'^\s*-\s*"!(sam-[\w-]+)/\*\*"', content, re.MULTILINE):
71+
plugins.add(match.group(1))
72+
73+
return plugins
74+
75+
6276
def get_plugins_from_manifest(repo_root: Path) -> Set[str]:
6377
"""Extract plugin names from .release-please-manifest.json."""
6478
manifest_path = repo_root / ".release-please-manifest.json"
@@ -104,7 +118,7 @@ def get_plugins_from_pr_labeler(repo_root: Path) -> Set[str]:
104118
def main():
105119
# Find repository root
106120
script_dir = Path(__file__).parent
107-
repo_root = script_dir.parent
121+
repo_root = script_dir.parent.parent
108122

109123
print(f"Repository root: {repo_root}")
110124
print()
@@ -121,6 +135,7 @@ def main():
121135

122136
configs = [
123137
("build-plugin.yaml", get_plugins_from_build_workflow(repo_root)),
138+
("sync-plugin-configs.yaml", get_plugins_from_sync_workflow(repo_root)),
124139
(".release-please-manifest.json", get_plugins_from_manifest(repo_root)),
125140
("release-please-config.json", get_plugins_from_release_config(repo_root)),
126141
("pr_labeler.yaml", get_plugins_from_pr_labeler(repo_root)),
@@ -134,13 +149,13 @@ def main():
134149

135150
if missing:
136151
all_match = False
137-
print(f" ❌ Missing plugins:")
152+
print(" ❌ Missing plugins:")
138153
for plugin in sorted(missing):
139154
print(f" - {plugin}")
140155

141156
if extra:
142157
all_match = False
143-
print(f" ⚠️ Extra plugins (in config but not in repo):")
158+
print(" ⚠️ Extra plugins (in config but not in repo):")
144159
for plugin in sorted(extra):
145160
print(f" - {plugin}")
146161

@@ -155,7 +170,7 @@ def main():
155170
return 0
156171
else:
157172
print("❌ Some configuration files need to be updated.")
158-
print(" Run 'python scripts/add_missing_plugins.py' to fix.")
173+
print(" Run 'python .github/scripts/add_missing_plugins.py' to fix.")
159174
return 1
160175

161176

0 commit comments

Comments
 (0)