+++ /dev/null
-name: GitHub Clone Count Update
-
-on:
- schedule:
- - cron: '0 */24 * * *'
- workflow_dispatch:
-
-jobs:
- clone-count:
- runs-on: ubuntu-latest
- if: github.repository == 'sap/e-mobility-charging-stations-simulator'
-
- steps:
- - uses: actions/checkout@v6
-
- - name: Validate configuration
- run: |
- if [ -z "$GIST_ID" ]; then
- echo "::error::GIST_ID variable is not configured"
- exit 1
- fi
- if [ -z "$SECRET_TOKEN" ]; then
- echo "::error::SECRET_TOKEN secret is not configured"
- exit 1
- fi
- env:
- GIST_ID: ${{ vars.GIST_ID }}
- SECRET_TOKEN: ${{ secrets.SECRET_TOKEN }}
-
- - name: gh login
- run: echo "${{ secrets.SECRET_TOKEN }}" | gh auth login --with-token
-
- - name: parse latest clone count
- run: |
- curl --user "${{ github.actor }}:${{ secrets.SECRET_TOKEN }}" \
- -H "Accept: application/vnd.github.v3+json" \
- https://api.github.com/repos/${{ github.repository }}/traffic/clones \
- > clone.json
-
- - name: download previous count
- run: |
- curl https://gist.githubusercontent.com/${{ github.actor }}/${{ vars.GIST_ID }}/raw/clone.json > clone_before.json
- if cat clone_before.json | grep '404: Not Found'; then
- cp clone.json clone_before.json
- fi
-
- - name: update clone.json
- run: |
- curl https://raw.githubusercontent.com/MShawon/github-clone-count-badge/master/main.py > main.py
- python3 main.py
-
- - name: update gist with latest count
- run: |
- content=$(sed -e 's/\\/\\\\/g' -e 's/\t/\\t/g' -e 's/\"/\\"/g' -e 's/\r//g' "clone.json" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
- echo '{"description": "${{ github.repository }} clone statistics", "files": {"clone.json": {"content": "'"$content"'"}}}' > post_clone.json
- curl -sf -X PATCH \
- --user "${{ github.actor }}:${{ secrets.SECRET_TOKEN }}" \
- -H "Content-Type: application/json" \
- -d @post_clone.json https://api.github.com/gists/${{ vars.GIST_ID }}
-
- - name: push
- uses: CasperWA/push-protected@v2
- with:
- token: ${{ secrets.SECRET_TOKEN }}
--- /dev/null
+name: GitHub Repo Stats
+
+on:
+ schedule:
+ - cron: '0 23 * * *'
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: repo-stats
+ cancel-in-progress: false
+
+jobs:
+ repo-stats:
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ if: github.repository == 'sap/e-mobility-charging-stations-simulator'
+
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
+
+ - name: Validate configuration
+ run: |
+ if [ -z "$GIST_ID" ]; then
+ echo "::error::GIST_ID variable is not configured"
+ exit 1
+ fi
+ if [ -z "$SECRET_TOKEN" ]; then
+ echo "::error::SECRET_TOKEN secret is not configured"
+ exit 1
+ fi
+ env:
+ GIST_ID: ${{ vars.GIST_ID }}
+ SECRET_TOKEN: ${{ secrets.SECRET_TOKEN }}
+
+ - name: Collect repository traffic stats
+ uses: jgehrcke/github-repo-stats@b1ef746a160025ee47390ea5e332b09a7acb3e80 # v1.4.2+
+ with:
+ ghtoken: ${{ secrets.SECRET_TOKEN }}
+ repository: ${{ github.repository }}
+ databranch: github-repo-stats
+
+ - name: Extract total clone count
+ id: clones
+ run: |
+ git fetch origin github-repo-stats
+ mkdir -p /tmp/stats-data
+ git archive origin/github-repo-stats | tar -x -C /tmp/stats-data 2>/dev/null || true
+ CSV_FILE=$(find /tmp/stats-data -path '*/ghrs-data/views_clones_aggregate.csv' | head -1)
+ if [ -n "$CSV_FILE" ] && [ -f "$CSV_FILE" ]; then
+ TOTAL=$(awk -F',' 'NR>1 {sum+=$2} END {print sum}' "$CSV_FILE")
+ echo "count=$TOTAL" >> "$GITHUB_OUTPUT"
+ else
+ echo "::warning::Could not locate views_clones_aggregate.csv - skipping badge update"
+ echo "skip=true" >> "$GITHUB_OUTPUT"
+ fi
+
+ - name: Update clone count badge
+ if: steps.clones.outputs.skip != 'true'
+ uses: schneegans/dynamic-badges-action@0e50b8bad39e7e1afd3e4e9c2b7dd145fad07501 # v1.8.0
+ with:
+ auth: ${{ secrets.SECRET_TOKEN }}
+ gistID: ${{ vars.GIST_ID }}
+ filename: clone.json
+ label: Clones
+ message: ${{ steps.clones.outputs.count }}
+ color: brightgreen
+ logoColor: white
+ namedLogo: github
+++ /dev/null
-**Markdown**
-
-```markdown
-[](https://github.com/MShawon/github-clone-count-badge)
-```
-
-**HTML**
-
-```html
-<a href="https://github.com/MShawon/github-clone-count-badge"
- ><img
- alt="GitHub Clones"
- src="https://img.shields.io/badge/dynamic/json?color=success&label=Clone&query=count&url=https://gist.githubusercontent.com/jerome-benoit/c7c669b881d5b27dc0b44a639504ff93/raw/clone.json&logo=github"
-/></a>
-```
<div align="center">
-[](https://github.com/SAP/e-mobility-charging-stations-simulator/graphs/traffic)
+[](https://github.com/SAP/e-mobility-charging-stations-simulator/graphs/traffic)
[](https://github.com/SAP/e-mobility-charging-stations-simulator/graphs/commit-activity)
[](https://github.com/SAP/e-mobility-charging-stations-simulator/actions/workflows/ci.yml)
[](https://api.reuse.software/info/github.com/SAP/e-mobility-charging-stations-simulator)