@@ -84,6 +84,21 @@ def compare_metadata(registry_package: Dict[str, Any], sop_data: Dict[str, Any])
8484 return True
8585
8686
87+ def run_git_command (command , error_message = None ):
88+ """Run a git command and handle errors gracefully."""
89+ try :
90+ result = subprocess .run (command , check = True ,
91+ capture_output = True , text = True )
92+ return result .stdout .strip ()
93+ except subprocess .CalledProcessError as e :
94+ msg = error_message or f"Git command failed: { ' ' .join (command )} "
95+ print (f"❌ { msg } " )
96+ print (f"Error details: { e } " )
97+ print (f"Command output: { e .stdout } " )
98+ print (f"Command error: { e .stderr } " )
99+ return None
100+
101+
87102def main ():
88103 """Main function to check all packages in registry.json."""
89104 registry_path = "registry.json"
@@ -155,26 +170,41 @@ def main():
155170 sys .exit (1 )
156171
157172 # Configure Git
158- subprocess .run (["git" , "config" , "user.name" , "sharafdin" ], check = True )
159- subprocess .run (["git" , "config" , "user.email" ,
160- "isasharafdin@gmail.com" ], check = True )
173+ run_git_command (["git" , "config" , "user.name" , "sharafdin" ],
174+ "Failed to configure Git username" )
175+ run_git_command (["git" , "config" , "user.email" , "isasharafdin@gmail.com" ],
176+ "Failed to configure Git email" )
161177
162178 # Use the repository URL from the GitHub environment if available
163179 repo_url = os .getenv ("GITHUB_REPOSITORY" , "soplang/registry" )
164- subprocess .run (["git" , "remote" , "set-url" , "origin" ,
165- f"https://x-access-token:{ pat } @github.com/{ repo_url } .git" ], check = True )
180+ remote_url = f"https://x-access-token:{ pat } @github.com/{ repo_url } .git"
181+ run_git_command (["git" , "remote" , "set-url" , "origin" , remote_url ],
182+ "Failed to set Git remote URL" )
166183
167184 # Add, commit, and push changes
168- subprocess . run (["git" , "add" , registry_path ], check = True )
169- subprocess . run (
170- [ "git" , "commit" , "-m" , "chore: update 'valid' status for packages" ], check = True )
185+ if not run_git_command (["git" , "add" , registry_path ],
186+ "Failed to stage changes" ):
187+ sys . exit ( 1 )
171188
172- # Get current branch and push
173- branch_name = subprocess .check_output (
174- ["git" , "rev-parse" , "--abbrev-ref" , "HEAD" ]).strip ().decode ()
175- subprocess .run (["git" , "push" , "origin" , branch_name ], check = True )
189+ if not run_git_command (["git" , "commit" , "-m" , "chore: update 'valid' status for packages" ],
190+ "Failed to commit changes" ):
191+ sys .exit (1 )
176192
177- print ("✅ Successfully updated and committed package validity status" )
193+ # Get current branch
194+ branch_name = run_git_command (["git" , "rev-parse" , "--abbrev-ref" , "HEAD" ],
195+ "Failed to determine current branch" )
196+ if not branch_name :
197+ branch_name = "main" # Default to main if we can't determine the branch
198+
199+ # Try to push changes
200+ print (f"Pushing changes to { branch_name } branch..." )
201+ if run_git_command (["git" , "push" , "origin" , branch_name ],
202+ f"Failed to push changes to { branch_name } " ):
203+ print ("✅ Successfully updated and committed package validity status" )
204+ else :
205+ print (
206+ "⚠️ Changes were made locally but could not be pushed to the repository" )
207+ sys .exit (1 )
178208 else :
179209 print ("✅ No changes to package validity status" )
180210
0 commit comments