-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (43 loc) · 1.59 KB
/
Copy pathtraffic.yml
File metadata and controls
50 lines (43 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Save traffic stats
# Guarda el histórico de clonaciones (la API de GitHub solo retiene 14 días).
on:
schedule:
- cron: "0 6 * * 0" # todos los domingos 06:00 UTC
workflow_dispatch: # permite correrlo a mano
permissions:
contents: write # push del histórico + la API de traffic exige push access
jobs:
save:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch and merge clone stats
env:
GH_TOKEN: ${{ secrets.TRAFFIC_PAT }}
run: |
set -euo pipefail
mkdir -p data/traffic
file=data/traffic/clones.json
[ -f "$file" ] || echo '[]' > "$file"
curl -sf \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/traffic/clones" \
> api.json
# Union por día: el dato nuevo pisa al viejo; los días fuera de la
# ventana de 14 días se conservan del histórico.
jq -s '
(.[0] + .[1].clones)
| group_by(.timestamp)
| map(.[-1])
| sort_by(.timestamp)
' "$file" api.json > merged.json
mv merged.json "$file"
rm -f api.json
- name: Commit
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add data/traffic/clones.json
git diff --cached --quiet || git commit -m "chore: update traffic clone stats"
git push