From cfa6c9584ebf3a12deb68ed53155c4af2e1ba2b5 Mon Sep 17 00:00:00 2001 From: Ted Date: Wed, 25 Jun 2025 18:30:58 +0800 Subject: [PATCH] feat: embed upgrade table in email --- .github/workflows/GenerateReport.yml | 18 +++++++++++++-- GenerateReport.py | 33 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/.github/workflows/GenerateReport.yml b/.github/workflows/GenerateReport.yml index 4a6f29a..cd77f75 100644 --- a/.github/workflows/GenerateReport.yml +++ b/.github/workflows/GenerateReport.yml @@ -83,12 +83,14 @@ jobs: output=$(python GenerateReport.py | tee /dev/stderr) summary_path="temp/PersonalReportSummary.txt" + table_path="temp/PersonalReportEmail.html" echo "šŸ“„ Using fixed summary path: $summary_path" if [[ ! -f "$summary_path" ]]; then echo "āš ļø Summary file not found. No packages to upgrade." echo "UPGRADE_COUNT=0" >> $GITHUB_ENV echo "UPGRADE_PKG_LIST=" >> $GITHUB_ENV + echo "UPGRADE_TABLE=" >> $GITHUB_ENV else count=$(grep -oP '^UPGRADE_COUNT=\K\d+' "$summary_path") pkgs=$(awk '/^PACKAGE_LIST:/ {flag=1; next} /^$/ {flag=0} flag' "$summary_path") @@ -96,6 +98,11 @@ jobs: echo "UPGRADE_PKG_LIST<> $GITHUB_ENV echo "$pkgs" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV + if [[ -f "$table_path" ]]; then + echo "UPGRADE_TABLE<> $GITHUB_ENV + cat "$table_path" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + fi fi - name: DEBUG - Show changed files @@ -136,11 +143,17 @@ jobs: if [ "${{ env.UPGRADE_COUNT }}" -eq 0 ]; then subject="āœ… Personal Report - No packages need upgrade" - echo -e "Hello team,\n\nNo packages require upgrade this week.\n\nRegards,\nReport Bot" > "$body_file" + cat < "$body_file" +Hello team,

No packages require upgrade this week.

Regards,
Report Bot +EOF + content_type="text/html" attachments="" else subject="šŸ” Personal Report - ${{ env.UPGRADE_COUNT }} packages need upgrade" - echo -e "Hello team,\n\nšŸ”§ Number of packages needing upgrade: ${{ env.UPGRADE_COUNT }}\n\nšŸ“¦ Package list, custodian and instructions:\n${{ env.UPGRADE_PKG_LIST }}\n\nRegards,\nReport Bot" > "$body_file" + cat < "$body_file" +Hello team,

šŸ”§ Number of packages needing upgrade: ${{ env.UPGRADE_COUNT }}

${{ env.UPGRADE_TABLE }}

Regards,
Report Bot +EOF + content_type="text/html" attachments="-a temp/PersonalReport.csv -a temp/PersonalReport.html" fi @@ -149,6 +162,7 @@ jobs: echo "Sending to: ${{ secrets.EMAIL_TO_LIST }}" mutt -e "set smtp_url=smtp://${{ secrets.EMAIL_USERNAME }}:${{ secrets.EMAIL_PASSWORD }}@${{ secrets.SMTP_SERVER }}:${{ secrets.SMTP_PORT }}" \ -e "set from='${{ secrets.EMAIL_USERNAME }}'" \ + -e "set content_type=$content_type" \ -s "$subject" $attachments -- "${{ secrets.EMAIL_TO_LIST }}" < "$body_file" if [ $? -eq 0 ]; then echo "āœ… Email sent successfully." diff --git a/GenerateReport.py b/GenerateReport.py index 1025a2c..fd77a85 100644 --- a/GenerateReport.py +++ b/GenerateReport.py @@ -393,6 +393,39 @@ def main() -> None: instr_text = instruction_to_text(row.get('Upgrade Instruction')) if instr_text: f.write(f" Upgrade Instruction: {instr_text}\n") + + # Save simplified HTML table for email body + email_html_path = os.path.join(PERSONAL_REPORT_DIR, "PersonalReportEmail.html") + with open(email_html_path, "w", encoding="utf-8") as ef: + ef.write("\n") + ef.write("\n") + for idx, row in enumerate(PersonalReportRows, 1): + instr = row.get('Upgrade Instruction') or {} + custodian = row.get('Custodian', '') + base_pkg = row.get('Package Name', '') + cur_ver = row.get('Current Version', '') + base_instr = instr.get('base_package', '') + deps = instr.get('dependencies', []) or [] + + target_ver = '' + if base_instr: + try: + _, target_ver = base_instr.split('==', 1) + except ValueError: + pass + + base_display = f"{base_pkg} ({cur_ver})" + if target_ver: + base_display += f" → {target_ver}" + + if deps: + ef.write(f"\n") + for dep in deps[1:]: + ef.write(f"\n") + else: + ef.write(f"\n") + ef.write("
S/NCustodianBase PackageDependency Packages
{idx}{custodian}{base_display}{deps[0]}
{dep}
{idx}{custodian}{base_display}-
\n") + print(f"āœ… Personal email HTML saved to {email_html_path}") else: print("ā„¹ļø No packages matched Personal Report criteria. Skipping personal report generation.")