-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (121 loc) · 5.21 KB
/
GenerateReport-Dev.yml
File metadata and controls
146 lines (121 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Generate Report (Dev)
on:
workflow_dispatch:
push:
branches:
- dev
paths:
- '**.py'
- '.github/workflows/GenerateReport-Dev.yml'
- '.github/workflows/PythonSetup/**'
- '.github/workflows/RcloneSetup/**'
- '.env'
- 'src/**'
- 'requirements.txt'
- 'templates/**'
- 'utils/**'
permissions:
contents: write
jobs:
healthcheck:
name: Health Check
runs-on: ubuntu-latest
environment: WT_WeeklyTriggerEnv
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Call setup-python
id: setup-python
uses: ./.github/workflows/PythonSetup
- name: DEBUG - Check pip health
run: |
pip --version
python -c "import pip._vendor.resolvelib; print(pip._vendor.resolvelib.__file__)"
- 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: ubuntu-latest
needs: healthcheck
environment: WT_WeeklyTriggerEnv
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Call setup-python
id: setup-python
uses: ./.github/workflows/PythonSetup
- name: Install mutt (only on GitHub-hosted runners)
if: contains(runner.labels, 'self-hosted') == false
run: |
sudo apt-get update
sudo apt-get install -y mutt
- name: DEBUG - Check pip health
run: |
pip --version
python -c "import pip._vendor.resolvelib; print(pip._vendor.resolvelib.__file__)"
- name: DEBUG - Print config.env
run: grep -E '^(FULL_RELOAD_PACKAGES|BASE_PACKAGE_CSV|REQUIREMENTS_FILE)=' .env || true
- name: Run weekly report and extract personal report info
id: run_report
run: |
output=$(python GenerateReport.py | tee /dev/stderr)
summary_path="temp/PersonalReportSummary.txt"
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
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
fi
- name: DEBUG - Show changed files
run: |
git status
git diff --name-only
- name: Commit and push changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Set timezone to SGT (Singapore Time)
export TZ="Asia/Singapore"
SGT_TIME=$(date '+%Y-%m-%d %H:%M SGT')
shopt -s globstar
git add WeeklyReport/**/*.csv || true
git commit -m "📝 Update WeeklyReport on $SGT_TIME" || echo "No changes in WeeklyReport"
git add MonthlyReport/**/*.xlsx || true
git commit -m "📊 Update MonthlyReport on $SGT_TIME" || echo "No changes in MonthlyReport"
git add src/BasePackageWithDependencies.csv || true
git commit -m "📦 Update BasePackageWithDependencies on $SGT_TIME" || echo "No changes in BasePackageWithDependencies"
# Pull remote changes before pushing to avoid non-fast-forward errors
git fetch origin ${{ github.ref_name }}
# Try to rebase first, if it fails due to conflicts, try merge
if ! git rebase origin/${{ github.ref_name }}; then
echo "⚠️ Rebase failed, trying merge approach..."
git reset --hard HEAD
git pull origin ${{ github.ref_name }} --no-edit || {
echo "⚠️ Pull failed, trying to force push our changes..."
git push origin HEAD:${{ github.ref_name }} --force-with-lease || {
echo "❌ All push attempts failed. Another workflow may have pushed changes."
echo "ℹ️ This is expected behavior when multiple workflows run concurrently."
echo "ℹ️ The workflow will continue with other tasks (releases, uploads, etc.)."
exit 0 # Don't fail the workflow, just skip the push
}
}
fi
# Try to push, but don't fail the workflow if it doesn't work
git push origin HEAD:${{ github.ref_name }} || {
echo "⚠️ Push failed, but continuing with workflow..."
echo "ℹ️ This may happen when other workflows push changes concurrently."
echo "ℹ️ The workflow will continue with releases and uploads."
}