-
Notifications
You must be signed in to change notification settings - Fork 2
109 lines (90 loc) · 3.59 KB
/
lovnishverma.yml
File metadata and controls
109 lines (90 loc) · 3.59 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
name: lovnishverma
on:
schedule:
# Run once a day at 04:00 UTC -> 09:30 AM IST
- cron: '0 4 * * *'
workflow_dispatch:
jobs:
daily-journal:
runs-on: ubuntu-latest
permissions:
contents: write
env:
TZ: 'Asia/Kolkata'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: 'Human Check: Weekends & Variance'
id: check
run: |
DAY=$(date +%u) # 1=Mon, 7=Sun
# 1. Weekend Logic:
# Real developers often don't code on Sundays.
# 50% chance to skip Sunday commits.
if [ $DAY -eq 7 ]; then
if [ $(( RANDOM % 2 )) -eq 0 ]; then
echo "It's Sunday. Taking a break."
echo "skip=true" >> $GITHUB_OUTPUT
exit 0
fi
fi
echo "skip=false" >> $GITHUB_OUTPUT
- name: Generate Useful Content
if: steps.check.outputs.skip == 'false'
run: |
mkdir -p journal
DATE=$(date '+%Y-%m-%d')
FILE="journal/daily_log.md"
# Ensure file exists with header
if [ ! -f $FILE ]; then
echo "# Developer Daily Journal" > $FILE
echo "A log of daily repository stats and inspiration." >> $FILE
echo "" >> $FILE
fi
# 1. FETCH A QUOTE (Useful Content)
# Tries to fetch a tech quote, falls back to a default if API fails
QUOTE=$(curl -s "https://api.quotable.io/random?tags=technology" | grep -o '"content":"[^"]*"' | cut -d'"' -f4)
if [ -z "$QUOTE" ]; then
QUOTE="Code is like humor. When you have to explain it, it’s bad."
fi
# 2. GATHER STATS
COMMIT_COUNT=$(git rev-list --count HEAD 2>/dev/null || echo "1")
REPO_SIZE=$(du -sh . | cut -f1)
# 3. PREPEND TO FILE (Newest entries at top)
# We create a temporary file to handle the prepend logic cleanly
TEMP_CONTENT="### $DATE (IST)
- **Status:** Active
- **Repo Size:** $REPO_SIZE
- **Total Commits:** $COMMIT_COUNT
- **Daily Insight:** *$QUOTE*
---
"
# Add new content to a temp file, then append original content
echo "$TEMP_CONTENT" > journal/temp.md
cat $FILE >> journal/temp.md
# Replace original file (but keep header if we want, or just overwrite)
# To keep it simple and clean, let's just keep the last 30 entries logic?
# For now, let's just overwrite the main file with the new sorted content.
mv journal/temp.md $FILE
# Clean up: Keep file size manageable (keep only top 100 lines)
head -n 100 $FILE > journal/temp_clean.md && mv journal/temp_clean.md $FILE
- name: Commit & Push
if: steps.check.outputs.skip == 'false'
run: |
git config --global user.name "lovnishverma"
git config --global user.email "princelv84@gmail.com"
git add journal/daily_log.md
# Only commit if the file actually changed
if ! git diff --staged --quiet; then
MESSAGES=(
"docs: update daily journal"
"chore: log repository stats"
"docs: add today's insight"
"ci: daily health check"
)
MSG=${MESSAGES[$RANDOM % ${#MESSAGES[@]}]}
git commit -m "$MSG"
git push
fi