Skip to content

Commit

Permalink
check this clone count badge
Browse files Browse the repository at this point in the history
  • Loading branch information
dcalixto committed Dec 16, 2024
1 parent 48734fc commit 6b8becb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 90 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/clone-stats-and-badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Clone Stats and Badge Update

on:
schedule:
- cron: "0 0 * * *" # Run daily at midnight
workflow_dispatch:

jobs:
update-stats-and-badge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup GitHub CLI
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
echo "$GH_TOKEN" | gh auth login --with-token
- name: Get Latest Clone Count
run: |
gh api repos/${{ github.repository }}/traffic/clones > latest_clones.json
- name: Update Historical Data
env:
GIST_ID: ${{ secrets.GIST_ID }}
run: |
gh gist get $GIST_ID > previous_clones.json
jq -s '.[0] * .[1]' previous_clones.json latest_clones.json > clone.json
gh gist edit $GIST_ID clone.json
- name: Push Updated Stats
run: |
gh api -X PUT repos/${{ github.repository }}/traffic/clones --input clone.json
- name: Update README Badge
run: |
CLONE_COUNT=$(cat latest_clones.json | jq '.count')
BADGE_URL="https://img.shields.io/badge/Clones-${CLONE_COUNT}-brightgreen"
sed -i "s|!\[Clone Count\]([^)]*)|![Clone Count](${BADGE_URL})|" README.md
- name: Commit and Push Badge Update
run: |
git config --global user.name "GitHub Action"
git config --global user.email "action@github.com"
git add README.md
git commit -m "Update clone count badge"
git push
90 changes: 0 additions & 90 deletions .github/workflows/clone.yml

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ A Crystal shard for creating human-readable URLs and slugs. FriendlyId lets you

[![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)

![Clone Count](https://img.shields.io/badge/Clones-0-brightgreen)

## Installation

1. Add the dependency to your `shard.yml`:
Expand Down

0 comments on commit 6b8becb

Please sign in to comment.