Updated usercount shield counters #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update aggregate usercount shields in root READMEs | |
on: | |
push: | |
branches: sync-downloads-sandbox | |
paths: "**" | |
jobs: | |
update-downloads-shield: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout adamlui/chatgpt-widescreen | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.REPO_SYNC_PAT }} | |
repository: adamlui/chatgpt-widescreen | |
path: adamlui/chatgpt-widescreen | |
- name: Fetch/sum user counts | |
id: get-users | |
run: | | |
expand_num() { # expand nums abbreviated w/ 'k' or 'm' suffix to integers | |
local num=$(echo "$1" | tr '[:upper:]' '[:lower:]') # Convert to lowercase | |
if [[ $num =~ k$ ]] ; then | |
num="${num%k}" # remove 'k' suffix | |
num=$(awk "BEGIN { printf \"%.0f\", $num * 1000 }") # multiply by 1000 | |
elif [[ $num =~ m$ ]] ; then | |
num="${num%m}" # remove 'm' suffix | |
num=$(awk "BEGIN { printf \"%.0f\", $num * 1000000 }") # multiply by 1000000 | |
fi ; echo "$num" | |
} | |
abbreviate_num() { # abbreviate nums aesthetically | |
local num=$1 ; first_digit="${num:0:1}" second_digit="${num:1:1}" | |
second_digit=$(( second_digit < 5 ? 0 : 5 )) # round 2nd digit down | |
if (( num >= 10000000 )) ; then # abbr 10M+ | |
abbreviated_num="$(( num / 1000000 ))M+" | |
elif (( num >= 1000000 )) ; then # abbr 1M+ to 9.5M+ | |
abbreviated_num="${first_digit}" | |
(( second_digit != 0 )) && abbreviated_num+=".$second_digit" | |
abbreviated_num+="M+" | |
elif (( num >= 100000 )) ; then # abbr 100K+ to 950K+ | |
abbreviated_num="${first_digit}${second_digit}0K+" | |
elif (( num >= 10000 )) ; then # abbr 10K+ to 90K+ | |
abbreviated_num="${num:0:1}0K+" | |
elif (( num >= 1000 )) ; then # abbr 1K to 9.9K | |
remainder=$(( (num % 1000) / 100 )) | |
abbreviated_num="$(( num / 1000 ))" | |
(( remainder != 0 )) && abbreviated_num+=".$remainder" | |
abbreviated_num+="K" | |
else abbreviated_num="$num" ; fi # preserve <1K as is | |
echo "$abbreviated_num" | |
} | |
# Fetch Chrome active user count | |
base_url="https://img.shields.io/chrome-web-store/users/" | |
app_id="jgnjpnmofkalfliddjelaciggjgnphgm" | |
chrome_users=$(curl -s "$base_url$app_id" | | |
sed -n 's/.*<title>users: \([0-9.k]\+\)*<\/title>.*/\1/p') | |
chrome_users=$(expand_num "$chrome_users") | |
echo -e "\nChrome users: $chrome_users" | |
# Fetch Edge active user count | |
base_url="https://microsoftedge.microsoft.com/addons/getproductdetailsbycrxid/" | |
app_id="obnaaalnokmchdoagnhmllakaclaaooa" | |
edge_users=$(curl -s "$base_url$app_id" | | |
grep -o '"activeInstallCount":[0-9]*' | | |
sed 's/"activeInstallCount"://') | |
echo "Edge users: $edge_users" | |
# Fetch Greasy Fork total user count | |
base_url="https://img.shields.io/greasyfork/dt/" | |
app_id="461473" | |
gf_users=$(curl -s "$base_url$app_id" | | |
sed -n 's/.*<title>installs: \([0-9.k]\+\)*<\/title>.*/\1/p') | |
gf_users=$(expand_num "$gf_users") | |
echo "Greasy Fork users: $gf_users" | |
# Sum/format user counts | |
total_users=$((chrome_users + edge_users + gf_users)) | |
formatted_total=$(abbreviate_num "$total_users") | |
echo "Total users: $formatted_total" | |
# Store for update step next | |
echo "total_users=$formatted_total" >> $GITHUB_OUTPUT | |
- name: Update README shield | |
run: | | |
cd ${{ github.workspace }}/adamlui/chatgpt-widescreen | |
total_users=$(echo ${{ steps.get-downloads.outputs.total_users }}) | |
sed -i "s/\(badge\/[^-]*-\)[0-9.,km+]\+-/\1$total_users-/g" $(find docs/ -name "README.md") | |
- name: Push to adamlui/chatgpt-widescreen | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
push_options: --force | |
add_options: --all | |
commit_user_email: [email protected] | |
commit_author: kudo-sync-bot <[email protected]> | |
commit_message: Updated usercount shield counters | |
file_pattern: "**/README.md" | |
repository: adamlui/chatgpt-widescreen |