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
3 changes: 3 additions & 0 deletions .github/workflows/GenerateReport-Debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
- '.github/workflows/RcloneSetup/**'
- '.env'
- 'src/**'
- 'requirements.txt'
- 'templates/**'
- 'utils/**'

permissions:
contents: write
Expand Down
99 changes: 98 additions & 1 deletion .github/workflows/GenerateReport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ on:
schedule:
- cron: '0 0 * * MON,THU'
workflow_dispatch:
push:
branches:
- main
paths:
- '**.py'
- 'GenerateReport.yml'
- '.github/workflows/PythonSetup/**'
- '.github/workflows/RcloneSetup/**'
- '.env'
- 'src/**'
- 'requirements.txt'
- 'templates/**'
- 'utils/**'

permissions:
contents: write
Expand Down Expand Up @@ -166,7 +179,7 @@ jobs:
echo "✅ Rclone upload completed successfully."
fi

create_release:
create-weekly-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: generate-report
Expand Down Expand Up @@ -292,3 +305,87 @@ jobs:
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

create-monthly-release:
name: Create Monthly Report Release
runs-on: ubuntu-latest
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 main
git checkout origin/main

- 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"

# Derive release tag
filename=$(basename "$latest_file")
year_month=$(echo "$filename" | grep -oP '(?<=MonthlyReport-)[0-9]{4}-[0-9]{2}' | tr -d '-')
tag="monthly-${year_month}"

echo "RELEASE_TAG=$tag" >> $GITHUB_ENV
echo "REPORT_FILE=$latest_file" >> $GITHUB_ENV
echo "REPORT_NAME=$filename" >> $GITHUB_ENV

- name: Create GitHub Monthly Release
id: create_monthly_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
release_name: "Monthly Report - ${{ env.RELEASE_TAG }}"
draft: false
prerelease: false

- name: Upload Monthly Report
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_monthly_release.outputs.upload_url }}
asset_path: ${{ env.REPORT_FILE }}
asset_name: ${{ env.REPORT_NAME }}
asset_content_type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

- 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"
gh api -X DELETE "repos/${{ github.repository }}/git/refs/tags/$tag" || echo "⚠️ Failed to delete tag ref $tag"
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Binary file not shown.
Binary file not shown.
6 changes: 0 additions & 6 deletions WeeklyReport/2025-06-02/WeeklyReport_20250602_165317.csv

This file was deleted.

Loading