DEV Community

SAURAV KUMAR
SAURAV KUMAR

Posted on

How I Automated Daily GitHub Contributions Using GitHub Actions ⚡

🎯 The Challenge

As a developer working on a long-term project, I faced a common problem: my GitHub contribution graph wasn't reflecting my actual work. Despite coding daily and pushing commits, my profile showed gaps because:

  1. Commits were on feature branches – GitHub only counts contributions on the default branch or merged PRs
  2. Wrong email configuration – My commits used a work email not linked to my GitHub account
  3. Time zone confusion – Struggled with UTC vs IST conversions

💡 The Solution: GitHub Actions

I decided to create an automated workflow that:

  • Updates my README.md daily with a timestamp
  • Commits and pushes automatically
  • Runs at 8:30 AM IST every day
  • Can be triggered manually for testing

🛠️ Implementation Journey

Phase 1: Email Configuration Issue

Problem: Commits weren't showing up on my profile.

# Wrong config (work email)
git config user.email "work.email@company.com"

# Correct config (GitHub email)
git config user.email "your-github-email@gmail.com"
Enter fullscreen mode Exit fullscreen mode


`

Solution: Set the correct email for the project:

bash
git config user.email "sk729584@gmail.com"
git config user.name "Saurav02022"


Phase 2: Branch Strategy Mistake

Problem: I initially merged the feature branch to main without asking – a workflow violation!

Lesson Learned: Always respect branching strategies and ask before merging to protected branches.

Solution:

`bash

Revert the unauthorized merge

git reset --hard
git push --force origin main

Return to feature branch

git checkout feature/day-02
`


Phase 3: GitHub Action Creation

Created .github/workflows/daily-readme-update.yml:

`yaml
name: Daily README Update

on:
# Scheduled trigger - runs daily at 8:30 AM IST
schedule:
- cron: '30 2 * * *' # 3:00 AM UTC = 8:30 AM IST

# Manual trigger
workflow_dispatch:

jobs:
update-readme:
runs-on: ubuntu-latest

steps:
  - name: Checkout repository
    uses: actions/checkout@v4
    with:
      token: ${{ secrets.GITHUB_TOKEN }}

  - name: Set up Git configuration
    run: |
      git config --local user.email "sk729584@gmail.com"
      git config --local user.name "Saurav02022"

  - name: Update README with current date and time
    run: |
      CURRENT_DATETIME=$(TZ='Asia/Kolkata' date '+%Y-%m-%d %H:%M:%S IST')

      if grep -q "<!-- AUTO-UPDATE-START -->" README.md; then
        sed -i "/<!-- AUTO-UPDATE-START -->/,/<!-- AUTO-UPDATE-END -->/c\\
      <!-- AUTO-UPDATE-START -->\\
      **Last Updated:** $CURRENT_DATETIME\\
      \\
      *This section is automatically updated daily at 8:30 AM IST by GitHub Actions.*\\
      <!-- AUTO-UPDATE-END -->" README.md
      else
        echo "" >> README.md
        echo "---" >> README.md
        echo "<!-- AUTO-UPDATE-START -->" >> README.md
        echo "**Last Updated:** $CURRENT_DATETIME" >> README.md
        echo "*This section is automatically updated daily at 8:30 AM IST by GitHub Actions.*" >> README.md
        echo "<!-- AUTO-UPDATE-END -->" >> README.md
      fi

  - name: Check for changes
    id: check_changes
    run: |
      if git diff --quiet; then
        echo "changes=false" >> $GITHUB_OUTPUT
      else
        echo "changes=true" >> $GITHUB_OUTPUT
      fi

  - name: Commit and push changes
    if: steps.check_changes.outputs.changes == 'true'
    run: |
      git add README.md
      git commit -m "chore: Auto-update README with current timestamp"
      git push
Enter fullscreen mode Exit fullscreen mode

`


Phase 4: Time Zone Confusion

Initial Mistake: Set cron to '0 9 * * *' thinking it was IST.
Reality: Cron uses UTC!
9:00 AM UTC = 2:30 PM IST ❌

Correct Calculation:

  • Target: 8:30 AM IST
  • IST = UTC + 5:30
  • 8:30 AM IST - 5:30 = 3:00 AM UTC
  • Cron: '30 2 * * *' (minute 30, hour 2 UTC)

🚀 Setup Steps

1. Enable Workflow Permissions

Repository → Settings → Actions → General → Workflow permissions
✅ Select “Read and write permissions”
✅ Check “Allow GitHub Actions to create and approve pull requests”


2. Add Auto-Update Section to README

`markdown

Last Updated: 2025-10-06 00:12:34 IST

This section is automatically updated daily at 8:30 AM IST by GitHub Actions.

`


3. Test with Manual Trigger

Go to Actions tab → Daily README Update → Run workflow


✅ Results

  • Daily contributions: Automatic green squares every day at 8:30 AM IST
  • Zero maintenance: Completely automated
  • Professional profile: Shows consistent activity
  • Learning experience: Deep dive into GitHub Actions, cron, and time zones

🎯 Key Takeaways

  • Email matters: GitHub links commits via email addresses
  • Branch strategy: Only default branch commits count as contributions
  • UTC vs Local Time: Always convert to UTC for cron schedules
  • Test first: Use workflow_dispatch for manual testing
  • GITHUB_TOKEN: Automatically provided, no manual secrets needed
  • Git etiquette: Never merge without permission!

📊 Impact

Before: Sporadic contributions, gaps in activity
After: Consistent daily contributions, professional profile
Bonus: Learned GitHub Actions automation


🔗 Resources


💬 Your Turn

Have you automated your GitHub contributions?
What challenges did you face? Drop your thoughts in the comments below! 👇


Tags: #GitHubActions #DevOps #Automation #GitHub #WebDev #Tutorial #Productivity


🔗 Connect with Me

💬 What automation challenges have you solved?
Share your experiences in the comments below!

Top comments (0)