Files
dotnet-runtime/eng/testing/gen-debug-dump-docs.py
T
Santiago Fernandez Madero 070323db0d Add debugging a ci dump documentation template and script to fill info and include it on azdo test tab (#43937)
* Add debugging a ci dump documentation template and script to generate it on helix

* PR Feedback and fix helix workitems

* Fix python script and -buildid argument

* Upload doc only if dumps were found

* Pass down templatedir

* PR feedback
2020-11-04 12:28:33 -08:00

105 lines
2.8 KiB
Python

import os
import sys
import platform
build_id = ''
job_id = ''
workitem = ''
dump_dir = ''
template_dir = os.getcwd()
out_dir = template_dir
idx = 0
args_len = len(sys.argv)
while idx < args_len:
arg = sys.argv[idx]
idx += 1
if arg == '-buildid':
if idx >= args_len or sys.argv[idx].startswith('-'):
print("Must specify a value for -buildid")
exit(1)
build_id = sys.argv[idx]
idx += 1
if arg == '-jobid':
if idx >= args_len or sys.argv[idx].startswith('-'):
print("Must specify a value for -jobid")
exit(1)
job_id = sys.argv[idx]
idx += 1
if arg == '-workitem':
if idx >= args_len or sys.argv[idx].startswith('-'):
print("Must specify a value for -workitem")
exit(1)
workitem = sys.argv[idx]
idx += 1
if arg == '-templatedir':
if idx >= args_len or sys.argv[idx].startswith('-'):
print("Must specify a value for -templatedir")
exit(1)
template_dir = sys.argv[idx]
idx += 1
if arg == '-outdir':
if idx >= args_len or sys.argv[idx].startswith('-'):
print("Must specify a value for -outdir")
exit(1)
out_dir = sys.argv[idx]
idx += 1
if arg == '-dumpdir':
if idx >= args_len or sys.argv[idx].startswith('-'):
print("Must specify a value for -dumpdir")
exit(1)
dump_dir = sys.argv[idx]
idx += 1
found_dumps = False
if dump_dir != '':
for filename in os.listdir(dump_dir):
if filename.endswith('.dmp') or 'core.' in filename:
found_dumps = True
break
if not found_dumps:
print("Did not find dumps, skipping dump docs generation.")
exit(0)
if build_id == '':
print("ERROR: unespecified required argument -buildid")
exit(1)
if workitem == '':
print("ERROR: unespecified required argument -workitem")
exit(1)
if job_id == '':
print("ERROR: unespecified required argument -jobid")
exit(1)
replace_string = ''
dir_separator = '/' if platform.system() != 'Windows' else '\\'
source_file = template_dir + dir_separator + 'debug-dump-template.md'
with open(source_file, 'r+') as f:
file_text = f.read()
print('read file: ' + source_file)
replace_string = file_text.replace('%JOBID%', job_id)
replace_string = replace_string.replace('%WORKITEM%', workitem)
replace_string = replace_string.replace('%BUILDID%', build_id)
output_file = out_dir + dir_separator + 'how-to-debug-dump.md'
with open(output_file, 'w+') as output:
print('writing output file: ' + output_file)
write_file = output.write(replace_string)
print('done writing debug dump information')