lovnishverma #270
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |