Skip to content

Commit 441db85

Browse files
authored
Merge pull request #2 from pathumzcode/Updates
Updates
2 parents 1008b80 + 5bbd7be commit 441db85

File tree

6 files changed

+267
-26
lines changed

6 files changed

+267
-26
lines changed

.github/workflows/daily-commit.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Daily GitHub Streak
2+
3+
on:
4+
schedule:
5+
# Run every day at 00:00 UTC (adjust to your timezone if needed)
6+
# This runs at 5:30 AM IST (Sri Lanka time)
7+
- cron: '0 0 * * *'
8+
9+
# Allow manual trigger from Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
daily-commit:
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
contents: write
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Configure Git
26+
run: |
27+
git config --global user.name "pathumzcode"
28+
git config --global user.email "[email protected]"
29+
30+
- name: Update activity log
31+
run: |
32+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Daily activity logged" >> daily_activity.log
33+
34+
- name: Commit and push changes
35+
run: |
36+
git add daily_activity.log
37+
git commit -m "Daily update: $(date '+%Y-%m-%d')" || echo "No changes to commit"
38+
git push origin Updates
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
8+
# Virtual Environment
9+
venv/
10+
env/
11+
ENV/
12+
13+
# IDE
14+
.vscode/
15+
.idea/
16+
*.swp
17+
*.swo
18+
19+
# OS
20+
.DS_Store
21+
Thumbs.db
22+
desktop.ini
23+
24+
# Logs (keep daily_activity.log tracked)
25+
*.log
26+
!daily_activity.log

README.md

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,93 @@ Automated daily activity tracker to maintain consistent GitHub contributions and
44

55
## 📊 Purpose
66

7-
This repository uses an automated Python script to log daily activity and maintain my GitHub contribution graph. It helps me:
7+
This repository uses **GitHub Actions** to automatically log daily activity and maintain my GitHub contribution graph. It helps me:
88

9-
- Keep my GitHub streak alive
9+
- Keep my GitHub streak alive 🔥
1010
- Track daily coding consistency
1111
- Maintain an active GitHub profile
12-
- Practice automation and scripting
12+
- Practice automation and CI/CD workflows
1313

1414
## 🛠️ How It Works
1515

16-
The repository contains a Python script that:
17-
1. Logs a daily timestamp to `daily_activity.log`
18-
2. Commits the changes automatically
19-
3. Pushes to GitHub to update the contribution graph
20-
4. Runs on a scheduled basis (daily automation)
16+
The repository contains **two methods** for maintaining the streak:
17+
18+
### 1. **Automated (Recommended)** - GitHub Actions
19+
- Runs automatically **every day at 00:00 UTC** (5:30 AM IST)
20+
- No manual intervention required
21+
- Uses GitHub's built-in automation
22+
- Works even when you're offline
23+
24+
### 2. **Manual** - Python Script
25+
- Run `auto_commit.py` manually when needed
26+
- Use `run_auto_commit.bat` on Windows for quick execution
27+
- Useful for testing or backup
2128

2229
## 🚀 Features
2330

24-
- ✅ Automated daily commits
25-
- ✅ Timestamp logging
26-
- ✅ Maintains GitHub streak
27-
- ✅ No manual intervention needed
31+
-**Fully automated** daily commits via GitHub Actions
32+
-**Manual trigger** option from GitHub Actions tab
33+
- ✅ Timestamp logging in `daily_activity.log`
34+
- ✅ Maintains GitHub streak without manual intervention
35+
- ✅ Smart branch detection (main/master)
36+
- ✅ Conflict prevention with automatic pulls
2837
- ✅ Simple and lightweight
2938

39+
## ⚙️ Setup
40+
41+
### GitHub Actions (Automatic)
42+
43+
The workflow is already configured in `.github/workflows/daily-commit.yml`. It runs automatically:
44+
45+
1. **Scheduled**: Every day at 00:00 UTC
46+
2. **Manual**: Go to **Actions****Daily GitHub Streak****Run workflow**
47+
48+
No additional setup required! Just push the workflow file to GitHub.
49+
50+
### Manual Execution (Python Script)
51+
52+
If you want to run manually:
53+
54+
```bash
55+
# Clone the repository
56+
git clone https://github.com/pathumzcode/Day-To-Day-Update.git
57+
cd Day-To-Day-Update
58+
59+
# Run the script
60+
python auto_commit.py
61+
62+
# Or on Windows, double-click:
63+
run_auto_commit.bat
64+
```
65+
3066
## 📝 Activity Log
3167

3268
All daily activities are tracked in `daily_activity.log` with timestamps
3369

34-
## ⚙️ Technology Stack
70+
## 🔧 Technology Stack
3571

3672
- **Language:** Python 3
3773
- **Version Control:** Git
38-
- **Automation:** Cron/Task Scheduler
74+
- **Automation:** GitHub Actions
75+
- **CI/CD:** YAML workflow
76+
77+
## 🐛 Troubleshooting
78+
79+
### Workflow not running?
80+
- Check **Actions** tab on GitHub for errors
81+
- Ensure **Actions** are enabled in repository settings
82+
- Verify the workflow file is in `.github/workflows/`
83+
84+
### Manual script not working?
85+
- Make sure you have Python 3 installed
86+
- Verify git is configured: `git config --global user.name "Your Name"`
87+
- Check internet connection
88+
- Ensure you have push access to the repository
3989

4090
## 📌 Note
4191

4292
This is an automated activity tracker. For my actual coding projects and contributions, check out my other repositories.
4393

4494
---
4595

46-
**Profile:** [@pathumzcode](https://github.com/pathumzcode)
96+
**Profile:** [@pathumzcode](https://github.com/pathumzcode) | **Automated:** ✅ GitHub Actions

SETUP_COMPLETE.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# GitHub Daily Streak - Setup Complete! ✅
2+
3+
## What Was Fixed
4+
5+
### Problems Identified:
6+
1. ❌ No automated workflow - script only ran manually
7+
2. ❌ Required manual execution every day
8+
3. ❌ No scheduled automation to maintain streak
9+
10+
### Solutions Implemented:
11+
12+
#### 1. **GitHub Actions Workflow** (Primary Solution)
13+
- ✅ Created `.github/workflows/daily-commit.yml`
14+
- ✅ Runs automatically **every day at 00:00 UTC** (5:30 AM IST)
15+
- ✅ Commits to the **Updates** branch
16+
- ✅ Works even when you're offline
17+
- ✅ Can also be triggered manually from GitHub Actions tab
18+
19+
#### 2. **Enhanced Python Script**
20+
- ✅ Added smart branch detection (now uses Updates branch)
21+
- ✅ Added `git pull` before push to prevent conflicts
22+
- ✅ Better error handling and messages
23+
- ✅ Checks if there are actual changes before committing
24+
25+
#### 3. **Additional Files**
26+
- ✅ Created `.gitignore` to keep repo clean
27+
- ✅ Updated `README.md` with complete documentation
28+
- ✅ Added troubleshooting section
29+
30+
## How It Works Now
31+
32+
### Automatic (No Action Required)
33+
GitHub Actions will run every day at midnight UTC and:
34+
1. Pull latest changes
35+
2. Add a timestamp to `daily_activity.log`
36+
3. Commit the change
37+
4. Push to your **Updates** branch
38+
5. Your streak is maintained! 🔥
39+
40+
### Manual (Optional)
41+
You can still run manually anytime:
42+
```bash
43+
python auto_commit.py
44+
```
45+
Or double-click `run_auto_commit.bat` on Windows.
46+
47+
## Next Steps
48+
49+
### Enable GitHub Actions (Important!)
50+
1. Go to your repository on GitHub: https://github.com/pathumzcode/Day-To-Day-Update
51+
2. Click on the **Actions** tab
52+
3. If prompted, click **"I understand my workflows, go ahead and enable them"**
53+
4. You should see "Daily GitHub Streak" workflow listed
54+
55+
### Test Manual Trigger
56+
1. Go to **Actions****Daily GitHub Streak**
57+
2. Click **"Run workflow"** → Select **Updates** branch → **Run workflow**
58+
3. Watch it execute in real-time!
59+
60+
### Verify Automation
61+
- Check back tomorrow to see if it ran automatically
62+
- View the Actions tab to see execution history
63+
- Check `daily_activity.log` for new entries
64+
65+
## Files Changed
66+
67+
1.`.github/workflows/daily-commit.yml` - NEW (GitHub Actions workflow)
68+
2.`.gitignore` - NEW (Ignores unnecessary files)
69+
3.`auto_commit.py` - UPDATED (Better error handling, branch detection)
70+
4.`README.md` - UPDATED (Complete documentation)
71+
5.`daily_activity.log` - UPDATED (Test commit added)
72+
73+
## Troubleshooting
74+
75+
### If workflow doesn't run:
76+
- Ensure Actions are enabled in repository settings
77+
- Check that the workflow file exists in `.github/workflows/`
78+
- Look for errors in the Actions tab
79+
80+
### If you want to change the schedule:
81+
Edit `.github/workflows/daily-commit.yml` and modify the cron expression:
82+
```yaml
83+
- cron: '0 0 * * *' # Currently: midnight UTC
84+
```
85+
86+
## Success Confirmation
87+
88+
✅ All files pushed to GitHub Updates branch
89+
✅ Python script tested and working
90+
✅ GitHub Actions workflow configured
91+
✅ README updated with instructions
92+
✅ Ready for automatic daily commits!
93+
94+
---
95+
96+
**Your GitHub streak will now be maintained automatically! 🔥**
97+
98+
Check your profile: https://github.com/pathumzcode

auto_commit.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ def run_command(cmd):
1818
print(f"Error: {e.stderr}")
1919
return False
2020

21+
def get_current_branch():
22+
"""Get the current git branch name"""
23+
try:
24+
result = subprocess.run("git rev-parse --abbrev-ref HEAD",
25+
shell=True, capture_output=True, text=True, check=True)
26+
return result.stdout.strip()
27+
except subprocess.CalledProcessError:
28+
return "main" # Default to main if can't detect
29+
2130
def auto_commit():
2231
"""Make an automatic commit to keep GitHub streak alive"""
2332

@@ -27,6 +36,14 @@ def auto_commit():
2736

2837
print(f"Working in: {repo_path}")
2938

39+
# Get current branch
40+
current_branch = get_current_branch()
41+
print(f"Current branch: {current_branch}")
42+
43+
# Pull latest changes first to avoid conflicts
44+
print("\n1. Pulling latest changes...")
45+
run_command(f"git pull origin {current_branch}")
46+
3047
# Create/update activity file
3148
activity_file = "daily_activity.log"
3249
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
@@ -41,30 +58,38 @@ def auto_commit():
4158
print("\n🔄 Starting git operations...")
4259

4360
# Check git status
44-
print("\n1. Checking git status...")
61+
print("\n2. Checking git status...")
4562
run_command("git status")
4663

4764
# Add changes
48-
print("\n2. Adding changes...")
65+
print("\n3. Adding changes...")
4966
if not run_command(f"git add {activity_file}"):
5067
print("❌ Failed to add changes")
5168
return False
5269

70+
# Check if there are actual changes to commit
71+
result = subprocess.run("git diff --cached --quiet",
72+
shell=True, capture_output=True)
73+
if result.returncode == 0:
74+
print("ℹ️ No changes to commit (already up to date)")
75+
return True
76+
5377
# Commit
5478
commit_message = f"Daily update: {date_only}"
55-
print(f"\n3. Creating commit: '{commit_message}'...")
79+
print(f"\n4. Creating commit: '{commit_message}'...")
5680
if not run_command(f'git commit -m "{commit_message}"'):
57-
print("❌ Failed to commit (maybe no changes?)")
81+
print("❌ Failed to commit")
5882
return False
5983

6084
# Push to GitHub
61-
print("\n4. Pushing to GitHub...")
62-
if not run_command("git push origin main"):
63-
# Try 'master' if 'main' fails
64-
print("Trying 'master' branch...")
65-
if not run_command("git push origin master"):
66-
print("❌ Failed to push changes")
67-
return False
85+
print(f"\n5. Pushing to GitHub ({current_branch})...")
86+
if not run_command(f"git push origin {current_branch}"):
87+
print("❌ Failed to push changes")
88+
print("💡 Make sure you have:")
89+
print(" - Configured git credentials")
90+
print(" - Have push access to the repository")
91+
print(" - Internet connection is active")
92+
return False
6893

6994
print("\n✅ Success! Your GitHub contribution has been logged.")
7095
print(f"🌟 Check your profile: https://github.com/pathumzcode")

daily_activity.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[2026-01-05 10:44:58] Daily activity logged
22
[2026-01-05 10:53:10] Daily activity logged
3+
[2026-01-09 10:41:31] Daily activity logged
4+
[2026-01-09 10:52:38] Daily activity logged

0 commit comments

Comments
 (0)