@@ -159,6 +159,31 @@ def self.manage_module(puppet_module, module_files, defaults)
159159 end
160160 end
161161
162+ def self . execute_in_module ( puppet_module , options )
163+ puts "Executing in '#{ puppet_module . given_name } '"
164+ puppet_module . repository . prepare_workspace ( branch : options [ :branch ] , operate_offline : false , rebase : options [ :rebase ] )
165+
166+ command_args = options [ :command_args ] . dup
167+ env_whitelist = ( options [ :env ] || '' ) . split ( ',' ) . map ( &:strip )
168+ local_script = File . expand_path command_args [ 0 ]
169+ command_args [ 0 ] = local_script if File . exist? ( local_script )
170+
171+ # Remove bundler-related env vars to allow the subprocess to run `bundle` unless explicitly whitelisted.
172+ command_env = ENV . reject { |k , _v | k . match? ( /(^BUNDLE|^SOURCE_DATE_EPOCH$|^GEM_|RUBY)/ ) && !env_whitelist . include? ( k ) }
173+
174+ success = system ( command_env , *command_args , unsetenv_others : true , chdir : puppet_module . working_directory )
175+ unless success
176+ message = "Command execution failed ('#{ command_args . join ' ' } ': #{ $CHILD_STATUS} )"
177+ raise ModuleSync ::Error , message
178+ end
179+
180+ status = puppet_module . repository . git . status
181+ changed_files = [ status . changed , status . added , status . deleted , puppet_module . repository . untracked_unignored_files ] . flat_map ( &:keys ) . uniq
182+ pushed = puppet_module . repository . submit_changes ( changed_files , options )
183+
184+ options [ :pr ] && ( pushed || puppet_module . pull_request_branch_ready? ) && puppet_module . open_pull_request
185+ end
186+
162187 def self . config_path ( file , options )
163188 return file if Pathname . new ( file ) . absolute?
164189
@@ -214,55 +239,22 @@ def self.execute(cli_options)
214239 initialized_modules = managed_modules
215240 initialized_modules . each ( &:git_service ) if options [ :pr ]
216241
217- errors = { }
242+ errors = false
218243 initialized_modules . each do |puppet_module |
219- $stdout. puts "#{ puppet_module . given_name } :"
220-
221- puppet_module . repository . clone unless puppet_module . repository . cloned?
222- if @options [ :default_branch ]
223- puppet_module . repository . switch branch : false
224- else
225- puppet_module . repository . switch branch : @options [ :branch ]
226- end
227-
228- command_args = cli_options [ :command_args ]
229- env_whitelist = ( @options [ :env ] || '' ) . split ( ',' )
230- local_script = File . expand_path command_args [ 0 ]
231- command_args [ 0 ] = local_script if File . exist? ( local_script )
232-
233- # Remove bundler-related env vars to allow the subprocess to run `bundle` unless explicitly whitelisted.
234- command_env = ENV . reject { |k , _v | k . match? ( /(^BUNDLE|^SOURCE_DATE_EPOCH$|^GEM_|RUBY)/ ) && !env_whitelist . include? ( k ) }
235-
236- result = system command_env , *command_args , unsetenv_others : true , chdir : puppet_module . working_directory
237- unless result
238- message = "Command execution failed ('#{ @options [ :command_args ] . join ' ' } ': #{ $CHILD_STATUS} )"
239- raise Thor ::Error , message if @options [ :fail_fast ]
240-
241- errors [ puppet_module . given_name ] = message
242- warn message
243- end
244-
245- if result
246- if @options [ :message ]
247- repo = puppet_module . repository
248- status = repo . git . status
249- changed_files = [ status . changed , status . added , status . deleted , repo . untracked_unignored_files ] . flat_map ( &:keys ) . uniq
250- pushed = puppet_module . repository . submit_changes ( changed_files , @options )
251- end
252- @options [ :pr ] && ( pushed || puppet_module . pull_request_branch_ready? ) && puppet_module . open_pull_request
253- end
254-
255- $stdout. puts ''
256- end
244+ execute_in_module ( puppet_module , options )
245+ rescue ModuleSync ::Error , Git ::Error => e
246+ message = e . message || 'Error during `execute`'
247+ warn "#{ puppet_module . given_name } : #{ message } "
248+ exit 1 unless options [ :skip_broken ]
249+ errors = true
250+ $stdout. puts "Skipping '#{ puppet_module . given_name } ' as execute process failed"
251+ rescue StandardError
252+ raise unless options [ :skip_broken ]
257253
258- unless errors . empty?
259- raise Thor ::Error , <<~MSG
260- Error(s) during `execute` command:
261- #{ errors . map { |name , message | " * #{ name } : #{ message } " } . join "\n " }
262- MSG
254+ errors = true
255+ $stdout. puts "Skipping '#{ puppet_module . given_name } ' as execute process failed"
263256 end
264-
265- exit 1 unless errors . empty?
257+ exit 1 if errors
266258 end
267259
268260 def self . reset ( cli_options )
0 commit comments