forked from ShahjalalShohag/ProblemSolvingStats
-
Notifications
You must be signed in to change notification settings - Fork 2
87 lines (66 loc) · 2.32 KB
/
Copy pathupdate-stats.yml
File metadata and controls
87 lines (66 loc) · 2.32 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
name: Update Problem Solving Statistics
on:
# DYNAMIC_SCHEDULE_START
schedule:
- cron: '35 16 * * *'
# DYNAMIC_SCHEDULE_END
workflow_dispatch:
# ==========================
# GLOBAL TIMEZONE (BDT)
# ==========================
env:
TZ: Asia/Dhaka
jobs:
update-stats:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# ==========================
# AUTO GITHUB OWNER CONFIG
# ==========================
- name: Configure Git Identity
run: |
OWNER="${GITHUB_REPOSITORY_OWNER}"
echo "Using repository owner: $OWNER"
git config --local user.name "$OWNER"
git config --local user.email "$OWNER@users.noreply.github.com"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip install -r requirements.txt
- name: Fetch latest statistics and update README
id: fetch_stats
run: |
echo "Before update - README last modified:"
stat -c '%y' docs/README.md || ls -l docs/README.md
python3 scripts/auto_update.py 2>&1 | tee stats_output.txt
echo "After update - README last modified:"
stat -c '%y' docs/README.md || ls -l docs/README.md
echo "Checking if README was modified:"
git diff docs/README.md | head -20
# ==========================
# COMMIT + PUSH (BDT TIME)
# ==========================
- name: Commit and push if changed
run: |
echo "Checking for changes..."
git status
git add docs/README.md data/last_known_counts.json .github/workflows/update-stats.yml
echo "Files staged. Checking diff..."
git diff --staged --stat
if git diff --staged --quiet; then
echo "No changes to commit"
else
echo "Changes detected, committing..."
git commit \
--author="$GITHUB_REPOSITORY_OWNER <$GITHUB_REPOSITORY_OWNER@users.noreply.github.com>" \
-m "Auto-update: Problem solving statistics ($(date +'%Y-%m-%d %H:%M:%S'))"
git push
fi