1515runtimeNames = list (map (lambda x : x ['name' ], runtimesMatrix ))
1616
1717common_args = {
18- '--continue-on-fail' : {"action" : "store_true" , "help" : "Won't exit(1) on failed command and continue with next steps. " },
1918 '--quiet' : {"action" : "store_true" , "help" : "Won't print start/end/failed messages in PR" },
2019 '--clean' : {"action" : "store_true" , "help" : "Clean up the previous bot's & author's comments in PR" },
2120 '--image' : {"help" : "Override docker image '--image docker.io/paritytech/ci-unified:latest'" },
2221}
2322
23+ def print_and_log (message , output_file = '/tmp/cmd/command_output.log' ):
24+ print (message )
25+ with open (output_file , 'a' ) as f :
26+ f .write (message + '\n ' )
27+
28+ def setup_logging ():
29+ if not os .path .exists ('/tmp/cmd' ):
30+ os .makedirs ('/tmp/cmd' )
31+ open ('/tmp/cmd/command_output.log' , 'w' )
32+
2433parser = argparse .ArgumentParser (prog = "/cmd " , description = 'A command runner for polkadot-sdk repo' , add_help = False )
2534parser .add_argument ('--help' , action = _HelpAction , help = 'help for help if you need some help' ) # help for help
2635for arg , config in common_args .items ():
2736 parser .add_argument (arg , ** config )
2837
2938subparsers = parser .add_subparsers (help = 'a command to run' , dest = 'command' )
3039
40+ setup_logging ()
41+
3142"""
3243BENCH
3344"""
3950 Runs benchmarks for pallet_balances and pallet_multisig for all runtimes which have these pallets. **--quiet** makes it to output nothing to PR but reactions
4051 %(prog)s --pallet pallet_balances pallet_xcm_benchmarks::generic --quiet
4152
42- Runs bench for all pallets for westend runtime and continues even if some benchmarks fail
43- %(prog)s --runtime westend --continue-on- fail
53+ Runs bench for all pallets for westend runtime and fails fast on first failed benchmark
54+ %(prog)s --runtime westend --fail-fast
4455
4556 Does not output anything and cleans up the previous bot's & author command triggering comments in PR
4657 %(prog)s --runtime westend rococo --pallet pallet_balances pallet_multisig --quiet --clean
5364
5465parser_bench .add_argument ('--runtime' , help = 'Runtime(s) space separated' , choices = runtimeNames , nargs = '*' , default = runtimeNames )
5566parser_bench .add_argument ('--pallet' , help = 'Pallet(s) space separated' , nargs = '*' , default = [])
67+ parser_bench .add_argument ('--fail-fast' , help = 'Fail fast on first failed benchmark' , action = 'store_true' )
5668
5769"""
5870FMT
@@ -156,7 +168,9 @@ def main():
156168 manifest_path = os .popen (search_manifest_path ).read ()
157169 if not manifest_path :
158170 print (f'-- pallet { pallet } not found in dev runtime' )
159- exit (1 )
171+ if args .fail_fast :
172+ print_and_log (f'Error: { pallet } not found in dev runtime' )
173+ sys .exit (1 )
160174 package_dir = os .path .dirname (manifest_path )
161175 print (f'-- package_dir: { package_dir } ' )
162176 print (f'-- manifest_path: { manifest_path } ' )
@@ -186,8 +200,9 @@ def main():
186200 f"{ config ['bench_flags' ]} "
187201 print (f'-- Running: { cmd } \n ' )
188202 status = os .system (cmd )
189- if status != 0 and not args .continue_on_fail :
190- print (f'Failed to benchmark { pallet } in { runtime } ' )
203+
204+ if status != 0 and args .fail_fast :
205+ print_and_log (f'❌ Failed to benchmark { pallet } in { runtime } ' )
191206 sys .exit (1 )
192207
193208 # Otherwise collect failed benchmarks and print them at the end
@@ -198,39 +213,39 @@ def main():
198213 successful_benchmarks [f'{ runtime } ' ] = successful_benchmarks .get (f'{ runtime } ' , []) + [pallet ]
199214
200215 if failed_benchmarks :
201- print ('❌ Failed benchmarks of runtimes/pallets:' )
216+ print_and_log ('❌ Failed benchmarks of runtimes/pallets:' )
202217 for runtime , pallets in failed_benchmarks .items ():
203- print (f'-- { runtime } : { pallets } ' )
218+ print_and_log (f'-- { runtime } : { pallets } ' )
204219
205220 if successful_benchmarks :
206- print ('✅ Successful benchmarks of runtimes/pallets:' )
221+ print_and_log ('✅ Successful benchmarks of runtimes/pallets:' )
207222 for runtime , pallets in successful_benchmarks .items ():
208- print (f'-- { runtime } : { pallets } ' )
223+ print_and_log (f'-- { runtime } : { pallets } ' )
209224
210225 elif args .command == 'fmt' :
211226 command = f"cargo +nightly fmt"
212227 print (f'Formatting with `{ command } `' )
213228 nightly_status = os .system (f'{ command } ' )
214229 taplo_status = os .system ('taplo format --config .config/taplo.toml' )
215230
216- if (nightly_status != 0 or taplo_status != 0 ) and not args . continue_on_fail :
217- print ('❌ Failed to format code' )
231+ if (nightly_status != 0 or taplo_status != 0 ):
232+ print_and_log ('❌ Failed to format code' )
218233 sys .exit (1 )
219234
220235 elif args .command == 'update-ui' :
221236 command = 'sh ./scripts/update-ui-tests.sh'
222237 print (f'Updating ui with `{ command } `' )
223238 status = os .system (f'{ command } ' )
224239
225- if status != 0 and not args . continue_on_fail :
226- print ('❌ Failed to format code ' )
240+ if status != 0 :
241+ print_and_log ('❌ Failed to update ui ' )
227242 sys .exit (1 )
228243
229244 elif args .command == 'prdoc' :
230245 # Call the main function from ./github/scripts/generate-prdoc.py module
231246 exit_code = generate_prdoc .main (args )
232- if exit_code != 0 and not args . continue_on_fail :
233- print ('❌ Failed to generate prdoc' )
247+ if exit_code != 0 :
248+ print_and_log ('❌ Failed to generate prdoc' )
234249 sys .exit (exit_code )
235250
236251 print ('🚀 Done' )
0 commit comments