Skip to content

Commit 6b8becb

Browse files
author
dcalixto
committed
check this clone count badge
1 parent 48734fc commit 6b8becb

File tree

3 files changed

+50
-90
lines changed

3 files changed

+50
-90
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Clone Stats and Badge Update
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *" # Run daily at midnight
6+
workflow_dispatch:
7+
8+
jobs:
9+
update-stats-and-badge:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Setup GitHub CLI
15+
env:
16+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
17+
run: |
18+
echo "$GH_TOKEN" | gh auth login --with-token
19+
20+
- name: Get Latest Clone Count
21+
run: |
22+
gh api repos/${{ github.repository }}/traffic/clones > latest_clones.json
23+
24+
- name: Update Historical Data
25+
env:
26+
GIST_ID: ${{ secrets.GIST_ID }}
27+
run: |
28+
gh gist get $GIST_ID > previous_clones.json
29+
jq -s '.[0] * .[1]' previous_clones.json latest_clones.json > clone.json
30+
gh gist edit $GIST_ID clone.json
31+
32+
- name: Push Updated Stats
33+
run: |
34+
gh api -X PUT repos/${{ github.repository }}/traffic/clones --input clone.json
35+
36+
- name: Update README Badge
37+
run: |
38+
CLONE_COUNT=$(cat latest_clones.json | jq '.count')
39+
BADGE_URL="https://img.shields.io/badge/Clones-${CLONE_COUNT}-brightgreen"
40+
sed -i "s|!\[Clone Count\]([^)]*)|![Clone Count](${BADGE_URL})|" README.md
41+
42+
- name: Commit and Push Badge Update
43+
run: |
44+
git config --global user.name "GitHub Action"
45+
git config --global user.email "[email protected]"
46+
git add README.md
47+
git commit -m "Update clone count badge"
48+
git push

.github/workflows/clone.yml

-90
This file was deleted.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ A Crystal shard for creating human-readable URLs and slugs. FriendlyId lets you
44

55
[![Crystal Test](https://github.com/dcalixto/friendly_id/actions/workflows/crystal-test.yml/badge.svg?branch=master)](https://github.com/dcalixto/friendly_id/actions/workflows/crystal-test.yml)
66

7+
![Clone Count](https://img.shields.io/badge/Clones-0-brightgreen)
8+
79
## Installation
810

911
1. Add the dependency to your `shard.yml`:

0 commit comments

Comments
 (0)