Skip to content

Commit fa4cb1a

Browse files
committed
docs: update README download badges
Use the desktop release version and the site-matched download count. Task: README download and desktop release badges.
1 parent 370f0fa commit fa4cb1a

2 files changed

Lines changed: 41 additions & 18 deletions

File tree

.github/workflows/desktop-download-badges.yml

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Refreshes the per-platform desktop download counters behind the README badges.
1+
# Refreshes the desktop and combined download counters behind the README badges.
22
#
33
# shields.io cannot do this on its own: its asset wildcards silently report 0
44
# (a tag whose .dmg had 39,877 downloads returns 0 for `*.dmg`), exact asset
@@ -11,6 +11,10 @@
1111
name: Desktop Download Badges
1212

1313
on:
14+
push:
15+
branches: [main]
16+
paths:
17+
- .github/workflows/desktop-download-badges.yml
1418
schedule:
1519
# Once a day is plenty; the counters move slowly and the API is rate-limited.
1620
- cron: '17 4 * * *'
@@ -33,7 +37,7 @@ jobs:
3337
ref: badges
3438
persist-credentials: true
3539

36-
- name: Sum the .dmg and .exe download counts
40+
- name: Refresh download counts
3741
env:
3842
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3943
# Desktop installers shipped from this repo up to v0.1.0 and move to
@@ -52,7 +56,18 @@ jobs:
5256
5357
# An empty suffix matches every asset, which is what the combined
5458
# counter wants; `endswith("")` is true for any string.
55-
write_badge() {
59+
write_endpoint() {
60+
local label="$1" message="$2" out="$3"
61+
jq -n --arg label "$label" --arg message "$message" '{
62+
schemaVersion: 1,
63+
label: $label,
64+
message: $message,
65+
color: "4D6BFE"
66+
}' > "$out"
67+
echo "${label}: ${message}"
68+
}
69+
70+
write_desktop_badge() {
5671
local suffix="$1" label="$2" out="$3"
5772
local total
5873
total="$(jq --arg s "$suffix" '
@@ -61,20 +76,29 @@ jobs:
6176
| .download_count
6277
] | add // 0
6378
' releases.json)"
64-
jq -n --arg label "$label" --arg message "$total" '{
65-
schemaVersion: 1,
66-
label: $label,
67-
message: $message,
68-
color: "4D6BFE"
69-
}' > "$out"
70-
echo "${label}: ${total}"
79+
write_endpoint "$label" "$total" "$out"
7180
}
7281
73-
write_badge '.dmg' 'macOS .dmg' desktop-dmg.json
74-
write_badge '.exe' 'Windows .exe' desktop-exe.json
82+
write_desktop_badge '.dmg' 'macOS .dmg' desktop-dmg.json
83+
write_desktop_badge '.exe' 'Windows .exe' desktop-exe.json
7584
# The shields `github/downloads/.../total` route reads one repository,
7685
# so the combined counter has to be summed here like the other two.
77-
write_badge '' 'desktop' desktop-total.json
86+
write_desktop_badge '' 'desktop' desktop-total.json
87+
88+
# Match the site: desktop and npm can represent the same users, so
89+
# publish the larger counter instead of adding them together.
90+
npm_downloads="$(
91+
curl --fail --silent --show-error --location \
92+
--retry 3 --retry-all-errors --connect-timeout 10 --max-time 30 \
93+
'https://api.npmjs.org/downloads/point/last-year/%40pymodel%2Fpythinker-code' \
94+
| jq -er '.downloads | numbers | select(. >= 0 and floor == .)'
95+
)"
96+
desktop_downloads="$(jq -er '.message | tonumber' desktop-total.json)"
97+
downloads="$(
98+
jq -n --argjson desktop "$desktop_downloads" --argjson npm "$npm_downloads" \
99+
'[$desktop, $npm] | max'
100+
)"
101+
write_endpoint 'downloads' "$downloads" downloads-total.json
78102
79103
rm -f releases.json
80104
@@ -85,10 +109,10 @@ jobs:
85109
git config user.email 'github-actions[bot]@users.noreply.github.com'
86110
# Stage before comparing: a document added in this run is untracked,
87111
# and `git diff` on an untracked path reports no change at all.
88-
git add desktop-dmg.json desktop-exe.json desktop-total.json
112+
git add desktop-dmg.json desktop-exe.json desktop-total.json downloads-total.json
89113
if git diff --cached --quiet; then
90114
echo 'Counts unchanged; nothing to publish.'
91115
exit 0
92116
fi
93-
git commit -m 'chore: refresh desktop download counts'
117+
git commit -m 'chore: refresh download counts'
94118
git push origin badges

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
### A coding agent you can run as a desktop app
66

7-
[![release](https://img.shields.io/npm/v/@pymodel/pythinker-code?style=flat-square&label=release&color=4f46e5)](https://www.npmjs.com/package/@pymodel/pythinker-code)
8-
[![downloads](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FPyModel%2Fpythinker-code%2Fbadges%2Fdesktop-total.json&style=flat-square&label=downloads&labelColor=000000&color=dfb317)](https://code.pythinker.com/)
9-
[![license](https://img.shields.io/badge/license-MIT-16a34a?style=flat-square)](LICENSE)
7+
[![release](https://img.shields.io/github/v/release/PyModel/pythinker-desktop-releases?style=flat-square&label=release&color=4f46e5)](https://github.com/PyModel/pythinker-desktop-releases/releases/latest)
8+
[![downloads](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FPyModel%2Fpythinker-code%2Fbadges%2Fdownloads-total.json&style=flat-square&label=downloads&labelColor=000000&color=dfb317)](https://code.pythinker.com/)
109
[![macOS](https://img.shields.io/badge/macOS-e5e7eb?style=flat-square&logo=apple&logoColor=000000)](https://code.pythinker.com/) | [![Windows](https://img.shields.io/badge/Windows-e5e7eb?style=flat-square&logo=data:image/svg%2Bxml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48dGl0bGU+V2luZG93cyAxMTwvdGl0bGU+PHBhdGggZmlsbD0iIzAwNzhENCIgZD0iTTAsMEgxMS4zNzdWMTEuMzcySDBaTTEyLjYyMywwSDI0VjExLjM3MkgxMi42MjNaTTAsMTIuNjIzSDExLjM3N1YyNEgwWm0xMi42MjMsMEgyNFYyNEgxMi42MjMiLz48L3N2Zz4=)](https://code.pythinker.com/)
1110
[![Node.js](https://img.shields.io/badge/Node.js-24.15%2B-339933?style=flat-square&logo=nodedotjs&logoColor=white)](package.json)
1211
[![visitors](https://komarev.com/ghpvc/?username=PyModel-pythinker-code&label=visitors&color=4f46e5&style=flat-square)](https://github.com/PyModel/pythinker-code)

0 commit comments

Comments
 (0)