Skip to content

Commit 3048f97

Browse files
authored
Update update-download-badges.yml
1 parent 7d60e8c commit 3048f97

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed
Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
name: Update downloads badges
2+
23
on:
34
release:
45
types: [published, edited, released]
56
schedule:
6-
- cron: '0 * * * *' # toutes les heures UTC
7-
workflow_dispatch: # permet de lancer manuellement depuis l'onglet Actions
7+
- cron: '0 * * * *' # Toutes les heures UTC
8+
workflow_dispatch: # Permet de lancer manuellement
9+
810
permissions:
9-
contents: write
11+
contents: read # Plus besoin d'écrire dans le repo
1012

1113
jobs:
1214
update-badges:
@@ -32,71 +34,57 @@ jobs:
3234
BADGES_DIR: ${{ env.BADGES_DIR }}
3335
run: |
3436
set -euo pipefail
35-
3637
mkdir -p "$BADGES_DIR"
3738
page=1
3839
total_appimage=0
3940
total_zsync=0
40-
4141
echo "Fetching releases from $REPO..."
42-
4342
while true; do
4443
echo "Fetching page $page..."
4544
resp=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
4645
-H "Accept: application/vnd.github+json" \
4746
-H "X-GitHub-Api-Version: 2022-11-28" \
4847
"https://api.github.com/repos/$REPO/releases?per_page=100&page=$page")
49-
5048
len=$(echo "$resp" | jq 'length')
5149
echo "Found $len releases on page $page"
52-
5350
if [ "$len" -eq 0 ]; then
5451
echo "No more releases to fetch"
5552
break
5653
fi
57-
58-
# Debug: afficher un exemple d'asset pour vérifier la structure
5954
if [ "$page" -eq 1 ]; then
6055
echo "Sample asset structure:"
6156
echo "$resp" | jq '.[0].assets[0]? // empty' || true
6257
fi
63-
64-
# Somme AppImage sur la page (fichiers se terminant par .AppImage SEULEMENT)
6558
page_app=$(echo "$resp" | jq --arg re "$APPIMAGE_REGEX" '
6659
[.[] | .assets[]? |
6760
select(.name | test($re) and (test("\\.zsync$") | not)) |
6861
.download_count // 0] | add // 0
6962
')
70-
71-
# Somme zsync sur la page
7263
page_zsync=$(echo "$resp" | jq --arg re "$ZSYNC_REGEX" '
7364
[.[] | .assets[]? |
7465
select(.name | test($re)) |
7566
.download_count // 0] | add // 0
7667
')
77-
7868
echo "Page $page - AppImage: $page_app, zsync: $page_zsync"
79-
8069
total_appimage=$((total_appimage + page_app))
8170
total_zsync=$((total_zsync + page_zsync))
82-
8371
page=$((page + 1))
8472
done
85-
8673
echo "Total AppImage downloads: $total_appimage"
8774
echo "Total zsync downloads: $total_zsync"
88-
89-
# Écrire les JSON pour Shields endpoint
9075
printf '{"schemaVersion":1,"label":"AppImage downloads","message":"%s","color":"blue"}\n' "$total_appimage" > "$BADGES_DIR/appimage.json"
9176
printf '{"schemaVersion":1,"label":"zsync downloads","message":"%s","color":"blue"}\n' "$total_zsync" > "$BADGES_DIR/zsync.json"
9277
93-
git config user.name "github-actions[bot]"
94-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
95-
git add "$BADGES_DIR/appimage.json" "$BADGES_DIR/zsync.json"
96-
97-
if git diff --staged --quiet; then
98-
echo "No changes to commit"
99-
else
100-
git commit -m "Update download badges: AppImage=$total_appimage zsync=$total_zsync"
101-
git push
102-
fi
78+
- name: Update Gist with badges
79+
env:
80+
GIST_TOKEN: ${{ secrets.GIST_TOKEN }}
81+
GIST_ID: 1a767d8eb615ae6cb497fe90ce0076bb
82+
BADGES_DIR: ${{ env.BADGES_DIR }}
83+
run: |
84+
for badge in appimage zsync; do
85+
FILENAME="$badge.json"
86+
RAW_CONTENT=$(cat "$BADGES_DIR/$FILENAME")
87+
curl -s -X PATCH "https://api.github.com/gists/$GIST_ID" \
88+
-H "Authorization: token $GIST_TOKEN" \
89+
-d "{\"files\": { \"$FILENAME\": { \"content\": $RAW_CONTENT }}}"
90+
done

0 commit comments

Comments
 (0)