diff --git a/.github/workflows/GenerateReport-Dev.yml b/.github/workflows/GenerateReport-Dev.yml index eddcd94..87b620b 100644 --- a/.github/workflows/GenerateReport-Dev.yml +++ b/.github/workflows/GenerateReport-Dev.yml @@ -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' @@ -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 @@ -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 @@ -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 }} diff --git a/.github/workflows/GenerateReport.yml b/.github/workflows/GenerateReport.yml index 63c6dc1..43cedba 100644 --- a/.github/workflows/GenerateReport.yml +++ b/.github/workflows/GenerateReport.yml @@ -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 }} @@ -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: | @@ -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 }} diff --git a/MonthlyReport/2025-06/MonthlyReport-202506-04-1116.xlsx b/MonthlyReport/2025-06/MonthlyReport-202506-04-1116.xlsx new file mode 100644 index 0000000..255a132 Binary files /dev/null and b/MonthlyReport/2025-06/MonthlyReport-202506-04-1116.xlsx differ diff --git a/MonthlyReport/2025-06/MonthlyReport-202506-04-1120.xlsx b/MonthlyReport/2025-06/MonthlyReport-202506-04-1120.xlsx new file mode 100644 index 0000000..def7ee0 Binary files /dev/null and b/MonthlyReport/2025-06/MonthlyReport-202506-04-1120.xlsx differ diff --git a/WeeklyReport/2025-06-02/WeeklyReport_20250604_111614.csv b/WeeklyReport/2025-06-02/WeeklyReport_20250604_111614.csv new file mode 100644 index 0000000..ecd9f8d --- /dev/null +++ b/WeeklyReport/2025-06-02/WeeklyReport_20250604_111614.csv @@ -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': []}", diff --git a/WeeklyReport/2025-06-02/WeeklyReport_20250604_111614.html b/WeeklyReport/2025-06-02/WeeklyReport_20250604_111614.html new file mode 100644 index 0000000..eda40c0 --- /dev/null +++ b/WeeklyReport/2025-06-02/WeeklyReport_20250604_111614.html @@ -0,0 +1,234 @@ + + +
+ +Report generated at 2025-06-04 11:16:15 +08
+ + + + + + + +| 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 | + +
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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': []} | + + + ++ + + |
Report generated at 2025-06-04 11:20:38 +08
+ + + + + + + +| 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 | + +
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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': []} | + + + ++ + + |