Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .github/workflows/GenerateReport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,26 @@ 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")
echo "UPGRADE_COUNT=$count" >> $GITHUB_ENV
echo "UPGRADE_PKG_LIST<<EOF" >> $GITHUB_ENV
echo "$pkgs" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
if [[ -f "$table_path" ]]; then
echo "UPGRADE_TABLE<<EOF" >> $GITHUB_ENV
cat "$table_path" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi
fi

- name: DEBUG - Show changed files
Expand Down Expand Up @@ -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 <<EOF > "$body_file"
Hello team,<br><br>No packages require upgrade this week.<br><br>Regards,<br>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 <<EOF > "$body_file"
Hello team,<br><br>🔧 Number of packages needing upgrade: ${{ env.UPGRADE_COUNT }}<br><br>${{ env.UPGRADE_TABLE }}<br><br>Regards,<br>Report Bot
EOF
content_type="text/html"
attachments="-a temp/PersonalReport.csv -a temp/PersonalReport.html"
fi

Expand All @@ -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."
Expand Down
33 changes: 33 additions & 0 deletions GenerateReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<table border='1' cellspacing='0' cellpadding='4'>\n")
ef.write("<tr><th>S/N</th><th>Custodian</th><th>Base Package</th><th>Dependency Packages</th></tr>\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"<tr><td rowspan='{len(deps)}'>{idx}</td><td rowspan='{len(deps)}'>{custodian}</td><td rowspan='{len(deps)}'>{base_display}</td><td>{deps[0]}</td></tr>\n")
for dep in deps[1:]:
ef.write(f"<tr><td>{dep}</td></tr>\n")
else:
ef.write(f"<tr><td>{idx}</td><td>{custodian}</td><td>{base_display}</td><td>-</td></tr>\n")
ef.write("</table>\n")
print(f"✅ Personal email HTML saved to {email_html_path}")

else:
print("ℹ️ No packages matched Personal Report criteria. Skipping personal report generation.")
Expand Down