feat: Add GitHub Actions workflow to track repository clone counts and display them in the README.

This commit is contained in:
AEmotionStudio
2026-01-01 22:59:55 -08:00
parent c500ddd2c1
commit 3eb25ee35a
2 changed files with 71 additions and 0 deletions
+68
View File
@@ -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)
+3
View File
@@ -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.*