11#!/usr/bin/env python3
22"""
3- Add missing plugin directories to the configuration files.
3+ Add missing plugins to all configuration files.
44
55This 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
1314from __future__ import annotations
1415
1516import json
16- import os
1717import re
1818import sys
1919from 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
3941def 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
102133def 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
220250def 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!" )
0 commit comments