diff --git a/.github/workflows/git_clones.yml b/.github/workflows/git_clones.yml new file mode 100644 index 0000000..2ed949b --- /dev/null +++ b/.github/workflows/git_clones.yml @@ -0,0 +1,68 @@ +name: Update Clone Count Badge + +on: + schedule: + - cron: '0 0 * * *' # Runs daily at midnight + workflow_dispatch: # Allows manual trigger + +jobs: + update-badge: + runs-on: ubuntu-latest + permissions: + contents: write # Needed to push to the branch + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Fetch Clone Stats and Save JSON + uses: actions/github-script@v6 + with: + script: | + try { + const { owner, repo } = context.repo; + // Add a small delay/retry logic if needed, but direct call usually works + const result = await github.rest.repos.getClones({ + owner, + repo, + }); + + const clones = result.data; + console.log(`Clones: ${clones.count}, Uniques: ${clones.uniques}`); + + const fs = require('fs'); + const data = { + count: clones.count, + uniques: clones.uniques, + timestamp: new Date().toISOString() + }; + + fs.writeFileSync('git_clones.json', JSON.stringify(data, null, 2)); + } catch (error) { + console.error('Error fetching clone stats:', error); + // Fail the workflow if we can't get data + process.exit(1); + } + + - name: Push to Badges Branch + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + # Stash the json file we just created + mv git_clones.json /tmp/git_clones.json + + # Fetch the badges branch or create it + git fetch origin badges:badges || true + git checkout badges || git checkout --orphan badges + + # Clean the branch to ensure it only has the JSON (optional but cleaner) + git rm -rf . + + # Restore the json file + mv /tmp/git_clones.json git_clones.json + + # Commit and push + git add git_clones.json + # Only commit if there are changes + git diff --quiet && git diff --staged --quiet || (git commit -m "Update clone statistics" && git push origin badges) diff --git a/README.md b/README.md index 963a49c..ba45d6d 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ [![Dependencies](https://img.shields.io/badge/dependencies-none-brightgreen?style=for-the-badge&color=blue)](package.json) [![License](https://img.shields.io/badge/License-GPLv3-red?style=for-the-badge)](LICENSE) [![Version](https://img.shields.io/badge/Version-1.5.0-orange?style=for-the-badge)](https://github.com/AEmotionStudio/ComfyUI-MagnifyGlass/releases) +[![Downloads](https://img.shields.io/github/downloads/AEmotionStudio/ComfyUI-MagnifyGlass/total?style=for-the-badge&color=blueviolet)](https://github.com/AEmotionStudio/ComfyUI-MagnifyGlass/releases) +[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FAEmotionStudio%2FComfyUI-MagnifyGlass&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com) +[![Clones](https://img.shields.io/badge/dynamic/json?color=success&label=Clone%20Count&query=count&url=https://raw.githubusercontent.com/AEmotionStudio/ComfyUI-MagnifyGlass/badges/git_clones.json&logo=github&style=for-the-badge)](https://github.com/AEmotionStudio/ComfyUI-MagnifyGlass/graphs/traffic) **A powerful, customizable magnifying glass extension for ComfyUI.** *Inspect fine details in your generated images, node connections, and canvas with ease.*