]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
ci: replace clone-count with jgehrcke/github-repo-stats
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 11 May 2026 00:28:57 +0000 (02:28 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 11 May 2026 00:28:57 +0000 (02:28 +0200)
- Replace fragile MShawon/github-clone-count-badge (unversioned curl)
  with jgehrcke/github-repo-stats (SHA-pinned, proper deduplication)
- Add schneegans/dynamic-badges-action for shields.io endpoint badge
- Pin all actions to full commit SHA (supply chain hardening)
- Add permissions, concurrency, and timeout-minutes
- Remove obsolete CLONE.md
- Rename workflow file to repo-stats.yml

.github/workflows/clone-count.yml [deleted file]
.github/workflows/repo-stats.yml [new file with mode: 0644]
CLONE.md [deleted file]
README.md

diff --git a/.github/workflows/clone-count.yml b/.github/workflows/clone-count.yml
deleted file mode 100644 (file)
index 8d9dd51..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-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 }}
diff --git a/.github/workflows/repo-stats.yml b/.github/workflows/repo-stats.yml
new file mode 100644 (file)
index 0000000..5a92448
--- /dev/null
@@ -0,0 +1,71 @@
+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
diff --git a/CLONE.md b/CLONE.md
deleted file mode 100644 (file)
index 3a54121..0000000
--- a/CLONE.md
+++ /dev/null
@@ -1,15 +0,0 @@
-**Markdown**
-
-```markdown
-[![GitHub Clones](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)](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>
-```
index 34350fc1df9bdc000bcdc830b6f36c2931513e61..aefd24ef0c54dbf7b8904727d9484725e86593ee 100644 (file)
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
 
 <div align="center">
 
-[![GitHub Clones](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=Clone&query=count&url=https://gist.githubusercontent.com/jerome-benoit/c7c669b881d5b27dc0b44a639504ff93/raw/clone.json&logo=github)](https://github.com/SAP/e-mobility-charging-stations-simulator/graphs/traffic)
+[![GitHub Clones](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/jerome-benoit/c7c669b881d5b27dc0b44a639504ff93/raw/clone.json&logo=github)](https://github.com/SAP/e-mobility-charging-stations-simulator/graphs/traffic)
 [![GitHub commit activity (main)](https://img.shields.io/github/commit-activity/m/SAP/e-mobility-charging-stations-simulator/main?color=brightgreen&logo=github)](https://github.com/SAP/e-mobility-charging-stations-simulator/graphs/commit-activity)
 [![CI workflow](https://github.com/SAP/e-mobility-charging-stations-simulator/actions/workflows/ci.yml/badge.svg)](https://github.com/SAP/e-mobility-charging-stations-simulator/actions/workflows/ci.yml)
 [![REUSE status](https://api.reuse.software/badge/github.com/SAP/e-mobility-charging-stations-simulator)](https://api.reuse.software/info/github.com/SAP/e-mobility-charging-stations-simulator)