Skip to content

Commit 70bdb85

Browse files
Merge pull request #229 from microsoft/dev
chore: Dev merge to main
2 parents 5e52ad9 + 6b3dce7 commit 70bdb85

38 files changed

Lines changed: 557 additions & 590 deletions

.github/workflows/validate-bicep-params.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ jobs:
3434
- name: Validate infra/ parameters
3535
id: validate_infra
3636
continue-on-error: true
37+
env:
38+
ACCELERATOR_NAME: ${{ env.accelerator_name }}
3739
run: |
3840
set +e
39-
python scripts/validate_bicep_params.py --dir infra --strict --no-color --json-output infra_results.json 2>&1 | tee infra_output.txt
41+
RUN_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
42+
python scripts/validate_bicep_params.py --dir infra --strict --no-color \
43+
--json-output infra_results.json \
44+
--html-output email_body.html \
45+
--accelerator-name "${ACCELERATOR_NAME}" \
46+
--run-url "${RUN_URL}" 2>&1 | tee infra_output.txt
4047
EXIT_CODE=${PIPESTATUS[0]}
4148
set -e
4249
echo "## Infra Param Validation" >> "$GITHUB_STEP_SUMMARY"
@@ -61,24 +68,21 @@ jobs:
6168
name: bicep-validation-results
6269
path: |
6370
infra_results.json
71+
email_body.html
6472
retention-days: 30
6573

6674
- name: Send schedule notification on failure
6775
if: github.event_name == 'schedule' && steps.result.outputs.status == 'failure'
6876
env:
6977
LOGICAPP_URL: ${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}
70-
GITHUB_REPOSITORY: ${{ github.repository }}
71-
GITHUB_RUN_ID: ${{ github.run_id }}
7278
ACCELERATOR_NAME: ${{ env.accelerator_name }}
7379
run: |
74-
RUN_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
75-
INFRA_OUTPUT=$(sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' infra_output.txt)
80+
EMAIL_BODY=$(cat email_body.html)
7681
7782
jq -n \
7883
--arg name "${ACCELERATOR_NAME}" \
79-
--arg infra "$INFRA_OUTPUT" \
80-
--arg url "$RUN_URL" \
81-
'{subject: ("Bicep Parameter Validation Report - " + $name + " - Issues Detected"), body: ("<p>Dear Team,</p><p>The scheduled <strong>Bicep Parameter Validation</strong> for <strong>" + $name + "</strong> has detected parameter mapping errors.</p><p><strong>infra/ Results:</strong></p><pre>" + $infra + "</pre><p><strong>Run URL:</strong> <a href=\"" + $url + "\">" + $url + "</a></p><p>Please fix the parameter mapping issues at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>")}' \
84+
--arg body "$EMAIL_BODY" \
85+
'{subject: ("Bicep Parameter Validation Report - " + $name + " - Issues Detected"), body: $body}' \
8286
| curl -X POST "${LOGICAPP_URL}" \
8387
-H "Content-Type: application/json" \
8488
-d @- || echo "Failed to send notification"
@@ -87,18 +91,14 @@ jobs:
8791
if: github.event_name == 'schedule' && steps.result.outputs.status == 'success'
8892
env:
8993
LOGICAPP_URL: ${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}
90-
GITHUB_REPOSITORY: ${{ github.repository }}
91-
GITHUB_RUN_ID: ${{ github.run_id }}
9294
ACCELERATOR_NAME: ${{ env.accelerator_name }}
9395
run: |
94-
RUN_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
95-
INFRA_OUTPUT=$(sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' infra_output.txt)
96+
EMAIL_BODY=$(cat email_body.html)
9697
9798
jq -n \
9899
--arg name "${ACCELERATOR_NAME}" \
99-
--arg infra "$INFRA_OUTPUT" \
100-
--arg url "$RUN_URL" \
101-
'{subject: ("Bicep Parameter Validation Report - " + $name + " - Passed"), body: ("<p>Dear Team,</p><p>The scheduled <strong>Bicep Parameter Validation</strong> for <strong>" + $name + "</strong> has completed successfully. All parameter mappings are valid.</p><p><strong>infra/ Results:</strong></p><pre>" + $infra + "</pre><p><strong>Run URL:</strong> <a href=\"" + $url + "\">" + $url + "</a></p><p>Best regards,<br>Your Automation Team</p>")}' \
100+
--arg body "$EMAIL_BODY" \
101+
'{subject: ("Bicep Parameter Validation Report - " + $name + " - Passed"), body: $body}' \
102102
| curl -X POST "${LOGICAPP_URL}" \
103103
-H "Content-Type: application/json" \
104104
-d @- || echo "Failed to send notification"

scripts/validate_bicep_params.py

Lines changed: 275 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def parse_parameters_env_vars(json_path: Path) -> dict[str, list[str]]:
110110
data = json.loads(sanitized)
111111
params = data.get("parameters", {})
112112
except json.JSONDecodeError:
113-
pass
113+
pass # File is not valid JSON after azd variable substitution; fall through to regex scan
114114

115115
# Walk each top-level parameter and scan its entire serialized value
116116
# for ${VAR} references from the original text.
@@ -341,6 +341,250 @@ def print_report(results: list[ValidationResult], *, use_color: bool = True) ->
341341
print(f"{c['ERROR']}Parameter mapping issues detected!{c['RESET']}")
342342

343343

344+
# ---------------------------------------------------------------------------
345+
# HTML email report
346+
# ---------------------------------------------------------------------------
347+
348+
def _html_escape(text: str) -> str:
349+
"""Escape HTML special characters."""
350+
return (
351+
text.replace("&", "&amp;")
352+
.replace("<", "&lt;")
353+
.replace(">", "&gt;")
354+
.replace('"', "&quot;")
355+
)
356+
357+
358+
def generate_html_report(
359+
results: list[ValidationResult],
360+
*,
361+
accelerator_name: str = "",
362+
run_url: str = "",
363+
scan_dir: str = "",
364+
) -> str:
365+
"""Build a structured HTML email body from validation results."""
366+
total_errors = sum(
367+
1 for r in results for i in r.issues if i.severity == "ERROR"
368+
)
369+
total_warnings = sum(
370+
1 for r in results for i in r.issues if i.severity == "WARNING"
371+
)
372+
has_errors = total_errors > 0
373+
overall_status = "Issues Detected" if has_errors else "Passed"
374+
status_color = "#D32F2F" if has_errors else "#2E7D32"
375+
status_bg = "#FFEBEE" if has_errors else "#E8F5E9"
376+
status_icon = "&#10060;" if has_errors else "&#9989;"
377+
378+
parts: list[str] = []
379+
380+
# --- Document wrapper (Outlook-compatible, no gradient/border-radius/box-shadow) ---
381+
parts.append(
382+
'<!DOCTYPE html><html><head><meta charset="utf-8"></head>'
383+
'<body style="margin:0;padding:0;font-family:Segoe UI,Helvetica,Arial,sans-serif;'
384+
'background-color:#ffffff;">'
385+
'<table role="presentation" width="100%" cellpadding="0" cellspacing="0"'
386+
' style="background-color:#ffffff;">'
387+
'<tr><td align="center" style="padding:0;">'
388+
'<table role="presentation" width="100%" cellpadding="0" cellspacing="0"'
389+
' style="max-width:680px;background-color:#ffffff;">'
390+
)
391+
392+
# --- Header banner (solid color, Outlook-safe) ---
393+
parts.append(
394+
f'<tr><td style="background-color:#0078D4;padding:20px 24px;color:#ffffff;">'
395+
f'<h1 style="margin:0 0 4px 0;font-size:20px;font-weight:600;color:#ffffff;">'
396+
f'Bicep Parameter Validation Report</h1>'
397+
f'<p style="margin:0;font-size:13px;color:#ffffff;">'
398+
f'{_html_escape(accelerator_name) if accelerator_name else "Accelerator"}'
399+
f' &mdash; Automated Check</p>'
400+
f'</td></tr>'
401+
)
402+
403+
# --- Summary card ---
404+
parts.append(
405+
f'<tr><td style="padding:16px 24px 12px 24px;">'
406+
f'<table role="presentation" width="100%" cellpadding="0" cellspacing="0"'
407+
f' style="background-color:{status_bg};border-left:4px solid {status_color};">'
408+
f'<tr><td style="padding:12px 16px;">'
409+
f'<span style="font-size:16px;font-weight:600;color:{status_color};">'
410+
f'{status_icon} Overall Status: {overall_status}</span>'
411+
f'</td></tr>'
412+
f'<tr><td style="padding:4px 16px 12px 16px;">'
413+
f'<table role="presentation" cellpadding="0" cellspacing="0"><tr>'
414+
)
415+
# Accelerator name pill
416+
if accelerator_name:
417+
parts.append(
418+
f'<td style="padding-right:20px;vertical-align:top;">'
419+
f'<span style="font-size:11px;color:#666;">Accelerator</span><br>'
420+
f'<strong style="font-size:13px;">{_html_escape(accelerator_name)}'
421+
f'</strong></td>'
422+
)
423+
# Scan directory pill
424+
if scan_dir:
425+
parts.append(
426+
f'<td style="padding-right:20px;vertical-align:top;">'
427+
f'<span style="font-size:11px;color:#666;">Scan Directory</span><br>'
428+
f'<strong style="font-size:13px;">{_html_escape(scan_dir)}/</strong>'
429+
f'</td>'
430+
)
431+
# Error count pill
432+
err_pill_color = "#D32F2F" if total_errors > 0 else "#2E7D32"
433+
parts.append(
434+
f'<td style="padding-right:20px;vertical-align:top;">'
435+
f'<span style="font-size:11px;color:#666;">Errors</span><br>'
436+
f'<strong style="font-size:13px;color:{err_pill_color};">'
437+
f'{total_errors}</strong></td>'
438+
)
439+
# Warning count pill
440+
warn_pill_color = "#F57C00" if total_warnings > 0 else "#2E7D32"
441+
parts.append(
442+
f'<td style="vertical-align:top;">'
443+
f'<span style="font-size:11px;color:#666;">Warnings</span><br>'
444+
f'<strong style="font-size:13px;color:{warn_pill_color};">'
445+
f'{total_warnings}</strong></td>'
446+
)
447+
parts.append("</tr></table></td></tr></table></td></tr>")
448+
449+
# --- Per-pair detail sections ---
450+
parts.append('<tr><td style="padding:8px 24px 0 24px;">')
451+
for r in results:
452+
errors = [i for i in r.issues if i.severity == "ERROR"]
453+
warnings = [i for i in r.issues if i.severity == "WARNING"]
454+
455+
if not r.issues:
456+
badge = (
457+
'<span style="display:inline-block;padding:2px 8px;'
458+
'font-size:11px;font-weight:700;'
459+
'color:#2E7D32;background-color:#E8F5E9;">PASS</span>'
460+
)
461+
elif errors:
462+
badge = (
463+
'<span style="display:inline-block;padding:2px 8px;'
464+
'font-size:11px;font-weight:700;'
465+
'color:#D32F2F;background-color:#FFEBEE;">FAIL</span>'
466+
)
467+
else:
468+
badge = (
469+
'<span style="display:inline-block;padding:2px 8px;'
470+
'font-size:11px;font-weight:700;'
471+
'color:#F57C00;background-color:#FFF3E0;">WARN</span>'
472+
)
473+
474+
parts.append(
475+
f'<table role="presentation" width="100%" cellpadding="0"'
476+
f' cellspacing="0" style="margin-bottom:12px;border:1px solid #e0e0e0;">'
477+
f'<tr><td style="background-color:#fafafa;padding:10px 12px;'
478+
f'border-bottom:1px solid #e0e0e0;">'
479+
f'{badge} '
480+
f'<strong style="font-size:13px;">'
481+
f'{_html_escape(r.pair)}</strong>'
482+
f'<span style="float:right;font-size:11px;color:#888;">'
483+
f'{len(errors)} error(s), {len(warnings)} warning(s)</span>'
484+
f'</td></tr>'
485+
)
486+
487+
if r.issues:
488+
# --- Errors sub-section ---
489+
if errors:
490+
parts.append(
491+
'<tr><td style="padding:10px 12px 4px 12px;">'
492+
'<span style="color:#D32F2F;font-weight:600;font-size:13px;">'
493+
'&#9679; Errors</span></td></tr>'
494+
'<tr><td style="padding:0 12px 8px 12px;">'
495+
'<table role="presentation" width="100%" cellpadding="0"'
496+
' cellspacing="0" style="font-size:12px;border:1px solid #f5c6cb;">'
497+
'<tr style="background-color:#FFEBEE;">'
498+
'<th style="text-align:left;padding:6px 10px;'
499+
'border-bottom:1px solid #f5c6cb;width:180px;'
500+
'font-weight:700;">Parameter</th>'
501+
'<th style="text-align:left;padding:6px 10px;'
502+
'border-bottom:1px solid #f5c6cb;'
503+
'font-weight:700;">Details</th></tr>'
504+
)
505+
for idx, issue in enumerate(errors):
506+
bg = "#ffffff" if idx % 2 == 0 else "#fff5f5"
507+
parts.append(
508+
f'<tr style="background-color:{bg};">'
509+
f'<td style="padding:5px 10px;border-bottom:1px solid #f5c6cb;'
510+
f'vertical-align:top;font-family:Consolas,monospace;'
511+
f'font-size:11px;word-break:break-all;">'
512+
f'{_html_escape(issue.param_name)}</td>'
513+
f'<td style="padding:5px 10px;border-bottom:1px solid #f5c6cb;'
514+
f'vertical-align:top;">{_html_escape(issue.message)}</td>'
515+
f'</tr>'
516+
)
517+
parts.append("</table></td></tr>")
518+
519+
# --- Warnings sub-section ---
520+
if warnings:
521+
parts.append(
522+
'<tr><td style="padding:10px 12px 4px 12px;">'
523+
'<span style="color:#F57C00;font-weight:600;font-size:13px;">'
524+
'&#9679; Warnings</span></td></tr>'
525+
'<tr><td style="padding:0 12px 8px 12px;">'
526+
'<table role="presentation" width="100%" cellpadding="0"'
527+
' cellspacing="0" style="font-size:12px;border:1px solid #ffe0b2;">'
528+
'<tr style="background-color:#FFF3E0;">'
529+
'<th style="text-align:left;padding:6px 10px;'
530+
'border-bottom:1px solid #ffe0b2;width:180px;'
531+
'font-weight:700;">Parameter</th>'
532+
'<th style="text-align:left;padding:6px 10px;'
533+
'border-bottom:1px solid #ffe0b2;'
534+
'font-weight:700;">Details</th></tr>'
535+
)
536+
for idx, issue in enumerate(warnings):
537+
bg = "#ffffff" if idx % 2 == 0 else "#fffaf0"
538+
parts.append(
539+
f'<tr style="background-color:{bg};">'
540+
f'<td style="padding:5px 10px;border-bottom:1px solid #ffe0b2;'
541+
f'vertical-align:top;font-family:Consolas,monospace;'
542+
f'font-size:11px;word-break:break-all;">'
543+
f'{_html_escape(issue.param_name)}</td>'
544+
f'<td style="padding:5px 10px;border-bottom:1px solid #ffe0b2;'
545+
f'vertical-align:top;">{_html_escape(issue.message)}</td>'
546+
f'</tr>'
547+
)
548+
parts.append("</table></td></tr>")
549+
else:
550+
parts.append(
551+
'<tr><td style="padding:10px 12px;color:#2E7D32;'
552+
'font-size:12px;">All parameters validated successfully.'
553+
'</td></tr>'
554+
)
555+
556+
parts.append("</table>")
557+
558+
parts.append("</td></tr>")
559+
560+
# --- Footer with run URL ---
561+
footer_parts: list[str] = []
562+
if run_url:
563+
footer_parts.append(
564+
f'<a href="{_html_escape(run_url)}" style="display:inline-block;'
565+
f'padding:8px 16px;background-color:#0078D4;color:#ffffff;'
566+
f'text-decoration:none;font-size:12px;'
567+
f'font-weight:600;">View Workflow Run</a>'
568+
)
569+
if has_errors:
570+
footer_parts.append(
571+
'<p style="margin:10px 0 0 0;font-size:12px;color:#555;">'
572+
'Please fix the parameter mapping issues at your earliest convenience.</p>'
573+
)
574+
footer_parts.append(
575+
'<p style="margin:10px 0 0 0;font-size:12px;color:#999;">'
576+
'Best regards,<br>Your Automation Team</p>'
577+
)
578+
parts.append(
579+
f'<tr><td style="padding:14px 24px 20px 24px;border-top:1px solid #e0e0e0;">'
580+
f'{"".join(footer_parts)}</td></tr>'
581+
)
582+
583+
# --- Close wrapper ---
584+
parts.append("</table></td></tr></table></body></html>")
585+
return "".join(parts)
586+
587+
344588
# ---------------------------------------------------------------------------
345589
# CLI
346590
# ---------------------------------------------------------------------------
@@ -379,6 +623,23 @@ def main() -> int:
379623
type=Path,
380624
help="Write results as JSON to the given file path.",
381625
)
626+
parser.add_argument(
627+
"--html-output",
628+
type=Path,
629+
help="Write a structured HTML email report to the given file path.",
630+
)
631+
parser.add_argument(
632+
"--accelerator-name",
633+
type=str,
634+
default="",
635+
help="Accelerator display name for the HTML report header.",
636+
)
637+
parser.add_argument(
638+
"--run-url",
639+
type=str,
640+
default="",
641+
help="Workflow run URL to include in the HTML report footer.",
642+
)
382643
args = parser.parse_args()
383644

384645
results: list[ValidationResult] = []
@@ -415,6 +676,19 @@ def main() -> int:
415676
)
416677
print(f"\nJSON report written to {args.json_output}")
417678

679+
# Optional HTML email report
680+
if args.html_output:
681+
scan_dir = str(args.dir) if args.dir else ""
682+
html = generate_html_report(
683+
results,
684+
accelerator_name=args.accelerator_name,
685+
run_url=args.run_url,
686+
scan_dir=scan_dir,
687+
)
688+
args.html_output.parent.mkdir(parents=True, exist_ok=True)
689+
args.html_output.write_text(html, encoding="utf-8")
690+
print(f"HTML report written to {args.html_output}")
691+
418692
has_errors = any(r.has_errors for r in results)
419693
return 1 if args.strict and has_errors else 0
420694

src/backend-api/pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ dependencies = [
1616
"fastapi[standard]==0.116.1",
1717
"httpx==0.28.1",
1818
"pydantic-settings==2.10.1",
19-
"python-dotenv",
20-
"python-multipart==0.0.22",
19+
"python-dotenv==1.2.2",
20+
"python-multipart==0.0.26",
2121
"protobuf==7.34.0",
2222
"sas-cosmosdb==0.1.4",
2323
"semantic-kernel[azure]==1.40.0",
@@ -34,6 +34,9 @@ override-dependencies = [
3434
"aiohttp==3.13.4",
3535
"azure-core==1.38.0",
3636
"urllib3==2.6.3",
37+
"requests==2.33.0",
38+
"werkzeug==3.1.4",
39+
"pygments==2.20.0",
3740
"black==26.3.1",
3841
"cryptography==46.0.7",
3942
"pyjwt==2.12.0",

0 commit comments

Comments
 (0)