This repository contains a simple, self-managing system to automatically track a daily streak or continuous counter. It runs once per day using GitHub Actions, executes a Python script to calculate the current day count, and commits a new, timestamped log file back to the repository.
The resulting files are named with the format: Day-X_YYYY-MM-DD.txt.
βββ .github/
β βββ workflows/
β βββ daily_run.yml # GitHub Action configuration
βββ daily_logs/ # Automated output folder
β βββ Day-1_2025-09-29.txt
β βββ Day-2_2025-09-30.txt
βββ daily_counter.py # The core Python logic
Follow these steps to deploy the tracker in your own GitHub repository.
- Create Repository: Start a new GitHub repository.
- Add Files: Add the
daily_counter.pyscript and the.github/workflows/daily_run.ymlfile to the root of your repository. - (Optional but Recommended): Create the empty directory
daily_logslocally and add a placeholder file (e.g.,.gitkeep) to ensure the directory is tracked by Git, though the Python script will create it if needed.
The GitHub Action is configured to run automatically, but you must ensure it has the necessary permissions to commit the files.
No additional secrets are needed. The action uses the built-in GITHUB_TOKEN which already has the permissions required by the workflow file (permissions: contents: write).
The workflow is currently scheduled to run every day at midnight UTC (0 0 * * *).
If you want to manually trigger the first run or test the process:
- Go to the Actions tab in your repository.
- Select the Daily Log Creator workflow.
- Click the Run workflow dropdown and select the
mainbranch.
The system ensures idempotence (it won't create duplicate files if run multiple times in one day).
- Daily Trigger: GitHub runs the
daily_run.ymljob at the scheduled time. - Count Calculation:
daily_counter.pylooks inside thedaily_logs/folder and counts all existing.txtfiles. This count is used to determine the sequential Day-X number. - Duplicate Check: The script generates the expected filename (e.g.,
Day-15_2026-03-05.txt) and checks if it already exists.- If file exists: The script exits with a
non-zero exit code (1), and the commit step is skipped. - If file is new: The script creates the file and exits with a
zero exit code (0).
- If file exists: The script exits with a
- Commit: The GitHub Action sees the
success status (0), stages the new file(git add daily_logs/*.txt), commits it, and pushes the change to themainbranch.
The core logic relies solely on the Python Standard Library.
| Module | Purpose |
|---|---|
datetime |
Used to get the current date (YYYY-MM-DD). |
pathlib |
Used for reliable, cross-platform file and directory manipulation. |
os, sys |
Used for interacting with the system exit codes (crucial for GitHub Actions). |