From b25130c61500a40197fe0119ede18fb20f4d2f92 Mon Sep 17 00:00:00 2001 From: Nathan Falvey Date: Fri, 27 Feb 2026 18:56:53 +0000 Subject: [PATCH] Implement Gitea Action to update README with dynamic stats --- .gitea/workflows/update.yaml | 28 +++++++++++++++++++++++++--- README.MD | 8 ++++++++ update_profile.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/update.yaml b/.gitea/workflows/update.yaml index 4dfa18c..e88eec7 100644 --- a/.gitea/workflows/update.yaml +++ b/.gitea/workflows/update.yaml @@ -1,7 +1,29 @@ -- name: Commit and Push changes +name: Update Profile Stats + +on: + schedule: + - cron: '0 * * * *' # Runs every hour + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Update README file + run: python3 update_profile.py + + - name: Commit and Push run: | git config --local user.email "action@gitea.com" git config --local user.name "Gitea Action" git add README.md - git commit -m "Update profile stats" || echo "No changes to commit" - git push + # Only commit if there are actual changes to avoid errors + git diff --quiet && git diff --staged --quiet || (git commit -m "Update profile stats" && git push) \ No newline at end of file diff --git a/README.MD b/README.MD index e69de29..80e35cd 100644 --- a/README.MD +++ b/README.MD @@ -0,0 +1,8 @@ +# Welcome to my Gitea Profile! + +This page is automatically updated by a Gitea Action. + +### šŸ“Š My Gitea Stats +Stats are loading... +--- +*Last updated: (Waiting for first run)* \ No newline at end of file diff --git a/update_profile.py b/update_profile.py index e69de29..12832fd 100644 --- a/update_profile.py +++ b/update_profile.py @@ -0,0 +1,34 @@ +import datetime +import os +import re + +def generate_stats(): + now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + return f"āœ… My Gitea instance is alive and well!\nšŸ•’ Last update: {now}." + +def main(): + readme_path = "README.md" + + if not os.path.exists(readme_path): + print("README.md not found!") + return + + with open(readme_path, "r", encoding="utf-8") as f: + content = f.read() + + # Generate new dynamic content + stats_content = generate_stats() + + # Replace content between the markers + pattern = r".*?" + replacement = f"\n{stats_content}\n" + new_content = re.sub(pattern, replacement, content, flags=re.DOTALL) + + # 4. Save the file back to disk + with open(readme_path, "w", encoding="utf-8") as f: + f.write(new_content) + + print("README.md updated locally.") + +if __name__ == "__main__": + main() \ No newline at end of file