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
237 changes: 234 additions & 3 deletions .github/workflows/GenerateReport-Dev.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Generate Report (Dev)

on:
schedule:
- cron: '0 0 * * MON,THU'
workflow_dispatch:
push:
branches:
- dev
paths:
- '**.py'
- '.github/workflows/GenerateReport-Dev.yml'
- '.github/workflows/GenerateReport.yml'
- '.github/workflows/PythonSetup/**'
- '.github/workflows/RcloneSetup/**'
- '.env'
Expand All @@ -22,7 +24,7 @@ permissions:
jobs:
healthcheck:
name: Health Check
runs-on: self-hosted
runs-on: ubuntu-latest
environment: WT_WeeklyTriggerEnv
steps:
- name: Checkout repository
Expand All @@ -40,6 +42,14 @@ jobs:
- name: DEBUG - Print config.env
run: grep -E '^(FULL_RELOAD_PACKAGES|BASE_PACKAGE_CSV|REQUIREMENTS_FILE)=' .env || true

- name: Set up rclone
uses: ./.github/workflows/RcloneSetup
with:
rclone_conf_base64: ${{ secrets.RCLONE_CONF_BASE64 }}

- name: DEBUG - Check rclone connection
run: rclone lsd gdrive:/Geek/PythonPackageManager/WeeklyReports/

generate-report:
name: Generate Weekly Report
runs-on: self-hosted
Expand Down Expand Up @@ -94,4 +104,225 @@ jobs:
echo "❌ Push failed. Someone else may have pushed changes. Please re-run the workflow."
exit 1
}


create-weekly-release:
name: Create Weekly Report Release
runs-on: ubuntu-latest
environment: WT_WeeklyTriggerEnv
needs: generate-report
if: success()

steps:
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh

- name: Checkout latest commit from main
run: |
git init
git remote add origin https://github.com/${{ github.repository }}
git fetch origin dev
git checkout origin/dev

- name: Find latest report set
id: find_latest
run: |
echo "📁 Scanning for latest report set..."
latest_json=$(find WeeklyReport -type f -name "WeeklyReport_*.json" | \
sed -E 's/\.json$//' | \
sort -t '_' -k2 | \
tail -n 1).json

if [[ -z "$latest_json" || ! -f "$latest_json" ]]; then
echo "❌ No valid JSON report found."
exit 1
fi

base_name="${latest_json%.json}"
csv_file="${base_name}.csv"
html_file="${base_name}.html"

echo "📝 Latest base: $base_name"
echo "📄 CSV: $csv_file"
echo "📄 HTML: $html_file"
echo "📄 JSON: $latest_json"

echo "CSV_PATH=$csv_file" >> $GITHUB_ENV
echo "HTML_PATH=$html_file" >> $GITHUB_ENV
echo "JSON_PATH=$latest_json" >> $GITHUB_ENV

echo "CSV_FILENAME=$(basename "$csv_file")" >> $GITHUB_ENV
echo "HTML_FILENAME=$(basename "$html_file")" >> $GITHUB_ENV
echo "JSON_FILENAME=$(basename "$latest_json")" >> $GITHUB_ENV

# 🗓️ Get the Monday of current week
MONDAY_DATE=$(date -d "$(date +%Y-%m-%d -d @$(( $(date +%s) - ($(date +%u) - 1) * 86400 )))" +%Y%m%d)
echo "📅 This week's Monday: $MONDAY_DATE"

# 🔍 Find existing tags in this week and determine Ver{x}
existing_tags=$(gh release list --limit 100 --json tagName | jq -r ".[] | .tagName" | grep -E "^weekly-${MONDAY_DATE}-Ver[0-9]+$" || true)
max_ver=$(echo "$existing_tags" | grep -oE 'Ver[0-9]+' | sed 's/Ver//' | sort -n | tail -n 1)

if [[ -z "$max_ver" ]]; then
new_ver=1
else
new_ver=$((max_ver + 1))
fi

tag="weekly-${MONDAY_DATE}-Ver${new_ver}"
echo "🆕 Release tag: $tag"

echo "RELEASE_TAG=$tag" >> $GITHUB_ENV
echo "release_tag=$tag" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

- name: Create GitHub Release
run: |
gh release create "$RELEASE_TAG" \
"$CSV_PATH#${CSV_FILENAME}" \
"$HTML_PATH#${HTML_FILENAME}" \
"$JSON_PATH#${JSON_FILENAME}" \
--title "Weekly Report - $RELEASE_TAG" \
--notes "Automated weekly report"
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

- name: Remove old releases from last week (keep Ver1 and latest)
run: |
# ⏱️ Calculate last Monday date
LAST_MONDAY=$(date -d "last monday" +%Y%m%d)
echo "🧹 Cleaning up releases from last week: $LAST_MONDAY"

# 🔍 Find all tags that fits weekly-LAST_MONDAY-Ver{X}
matching_tags=$(gh release list --limit 100 --json tagName,createdAt | \
jq -r ".[] | select(.tagName | test(\"^weekly-${LAST_MONDAY}-Ver[0-9]+\")).tagName")

if [[ -z "$matching_tags" ]]; then
echo "ℹ️ No matching tags found for last week."
exit 0
fi

echo "🔍 All matching tags:"
echo "$matching_tags"

# Extract all tags
versions=$(echo "$matching_tags" | sed -nE "s/^weekly-${LAST_MONDAY}-Ver([0-9]+)$/\1/p" | sort -n)

# Get biggest ver
max_ver=$(echo "$versions" | tail -n 1)
echo "🆕 Max version: Ver$max_ver"

for tag in $matching_tags; do
ver=$(echo "$tag" | sed -nE "s/^weekly-${LAST_MONDAY}-Ver([0-9]+)$/\1/p")

if [[ "$ver" == "1" || "$ver" == "$max_ver" ]]; then
echo "✅ Keeping $tag"
continue
fi

echo "🗑️ Deleting $tag"
gh release delete "$tag" --yes || echo "⚠️ Failed to delete release $tag"
if git ls-remote --tags origin | grep -q "refs/tags/$tag$"; then
echo "🔖 Tag $tag exists. Deleting..."
gh api -X DELETE "repos/${{ github.repository }}/git/refs/tags/$tag" || echo "⚠️ Failed to delete tag ref $tag"
else
echo "ℹ️ Tag $tag does not exist. Skipping tag deletion."
fi
done
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

create-monthly-release:
name: Create Monthly Report Release
runs-on: ubuntu-latest
environment: WT_WeeklyTriggerEnv
needs: generate-report
if: success()
steps:
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh jq

- name: Checkout latest commit from main
run: |
git init
git remote add origin https://github.com/${{ github.repository }}
git fetch origin dev
git checkout origin/dev

- name: Find latest monthly report
id: find_latest_monthly
run: |
echo "🔍 Scanning for latest MonthlyReport..."
latest_file=$(find MonthlyReport -type f -name "MonthlyReport-*.xlsx" | sort | tail -n 1)

if [[ -z "$latest_file" || ! -f "$latest_file" ]]; then
echo "❌ No monthly report found."
exit 1
fi

echo "✅ Found: $latest_file"

filename=$(basename "$latest_file")
year_month=$(echo "$filename" | grep -oP '(?<=MonthlyReport-)[0-9]{6}')

echo "📦 Scanning existing monthly tags with prefix: monthly-${year_month}-Ver"

existing_tags=$(gh release list --limit 100 --json tagName | jq -r ".[] | .tagName" | grep -E "^monthly-${year_month}-Ver[0-9]+$" || true)

max_ver=$(echo "$existing_tags" | grep -oE 'Ver[0-9]+' | sed 's/Ver//' | sort -n | tail -n 1)

if [[ -z "$max_ver" ]]; then
new_ver=1
else
new_ver=$((max_ver + 1))
fi

tag="monthly-${year_month}-Ver${new_ver}"
echo "🆕 New tag: $tag"

echo "RELEASE_TAG=$tag" >> $GITHUB_ENV
echo "REPORT_FILE=$latest_file" >> $GITHUB_ENV
echo "REPORT_NAME=$filename" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

- name: Create GitHub Release
run: |
gh release create "$RELEASE_TAG" \
"$REPORT_FILE#${REPORT_NAME}" \
--title "Monthly Report - $RELEASE_TAG" \
--notes "Automated monthly report"
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

- name: Remove old releases for the same month
run: |
echo "🧹 Cleaning up other releases for the same month..."

current_month_prefix=$(echo "${{ env.RELEASE_TAG }}" | grep -oP 'monthly-\K[0-9]{6}')

gh release list --limit 100 --json tagName,createdAt | \
jq -c '.[] | select(.tagName | test("^monthly-'$current_month_prefix'$"))' | \
while read line; do
tag=$(echo "$line" | jq -r '.tagName')

if [[ "$tag" == "${{ env.RELEASE_TAG }}" ]]; then
echo "⏭️ Skipping current release: $tag"
continue
fi

echo "🗑️ Deleting other release from the same month: $tag"
gh release delete "$tag" --yes || echo "⚠️ Failed to delete release $tag"
if git ls-remote --tags origin | grep -q "refs/tags/$tag$"; then
echo "🔖 Tag $tag exists. Deleting..."
gh api -X DELETE "repos/${{ github.repository }}/git/refs/tags/$tag" || echo "⚠️ Failed to delete tag ref $tag"
else
echo "ℹ️ Tag $tag does not exist. Skipping tag deletion."
fi
done
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
31 changes: 20 additions & 11 deletions .github/workflows/GenerateReport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ jobs:

echo "🗑️ Deleting $tag"
gh release delete "$tag" --yes || echo "⚠️ Failed to delete release $tag"
gh api -X DELETE "repos/${{ github.repository }}/git/refs/tags/$tag" || echo "⚠️ Failed to delete tag ref $tag"
if git ls-remote --tags origin | grep -q "refs/tags/$tag$"; then
echo "🔖 Tag $tag exists. Deleting..."
gh api -X DELETE "repos/${{ github.repository }}/git/refs/tags/$tag" || echo "⚠️ Failed to delete tag ref $tag"
else
echo "ℹ️ Tag $tag does not exist. Skipping tag deletion."
fi
done
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
Expand Down Expand Up @@ -362,6 +367,14 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

- name: Create GitHub Release
run: |
gh release create "$RELEASE_TAG" \
"$REPORT_FILE#${REPORT_NAME}" \
--title "Monthly Report - $RELEASE_TAG" \
--notes "Automated monthly report"
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

- name: Remove old releases for the same month
run: |
Expand All @@ -381,16 +394,12 @@ jobs:

echo "🗑️ Deleting other release from the same month: $tag"
gh release delete "$tag" --yes || echo "⚠️ Failed to delete release $tag"
gh api -X DELETE "repos/${{ github.repository }}/git/refs/tags/$tag" || echo "⚠️ Failed to delete tag ref $tag"
if git ls-remote --tags origin | grep -q "refs/tags/$tag$"; then
echo "🔖 Tag $tag exists. Deleting..."
gh api -X DELETE "repos/${{ github.repository }}/git/refs/tags/$tag" || echo "⚠️ Failed to delete tag ref $tag"
else
echo "ℹ️ Tag $tag does not exist. Skipping tag deletion."
fi
done
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

- name: Create GitHub Release
run: |
gh release create "$RELEASE_TAG" \
"$REPORT_FILE#${REPORT_NAME}" \
--title "Monthly Report - $RELEASE_TAG" \
--notes "Automated monthly report"
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions WeeklyReport/2025-06-02/WeeklyReport_20250604_111614.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Package Name,Package Type,Custodian,Current Version,Dependencies for Current,Newer Versions,Dependencies for Latest,Latest Version,Current Version Vulnerable?,Current Version Vulnerability Details,Upgrade Version Vulnerable?,Upgrade Vulnerability Details,Suggested Upgrade,Upgrade Instruction,Remarks
absl-py,Dependency Package,I&S,2.1.0,,"2.2.0, 2.2.1, 2.2.2, 2.3.0",,2.3.0,No,,No,None,2.3.0,"{'base_package': 'absl-py==2.3.0', 'dependencies': []}",
Loading
Loading