-
Notifications
You must be signed in to change notification settings - Fork 24
86 lines (73 loc) · 2.89 KB
/
stats.yaml
File metadata and controls
86 lines (73 loc) · 2.89 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Get download stats
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
on:
schedule:
- cron: "0 3 * * *"
workflow_dispatch: {}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install dependencies
run: |
sudo apt update && sudo apt install wget
wget "https://raw.githubusercontent.com/xonixx/gron.awk/refs/heads/main/gron.awk" -O ./gron.awk
chmod +x ./gron.awk
- name: Get stats
run: |
LIST="https://raw.githubusercontent.com/pkgforge-dev/Anylinux-AppImages/refs/heads/main/README.md"
REPOS="$(
wget -q "$LIST" -O - \
| awk '/APPS_LIST_START/{p=1; next}/APPS_LIST_END/{p=0} p' \
| grep -io 'pkgforge-dev/.*AppImage.*)' \
| awk -F')' '{print $1}'
)"
cp ./.github/repos.stats /tmp/repos.stats.prev
for REPO in $REPOS; do
REPO=${REPO##*/}
NUM=$(wget -q --header="Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/pkgforge-dev/$REPO/releases?per_page=100" -O - \
| ./gron.awk | awk -F'=' '/download_count/ {total += $2} END {print total}')
if [ -z "$NUM" ]; then
>&2 echo "WARNING, COULD NOT GET STATS FROM $REPO"
continue
fi
if ! grep -q "$REPO:" ./.github/repos.stats; then
echo "${REPO}: $NUM" >> ./.github/repos.stats
else
sed -i -e "s|$REPO:.*|${REPO}: $NUM|" ./.github/repos.stats
fi
done
sorted=$(sort -u ./.github/repos.stats)
echo "$sorted" > ./.github/repos.stats
sort -rnk2 ./.github/repos.stats > ./.github/repos.stats.bytotal
awk -F': ' '
NR==FNR { old[$1] = $2; next }
{
daily = $2 - old[$1]
if (daily < 0) daily = 0
print $1 ": " daily
}
' /tmp/repos.stats.prev ./.github/repos.stats | sort -rnk2 > ./.github/repos.stats.diff
TOTAL=$(awk -F':' '{sum += $2} END {print sum}' ./.github/repos.stats)
echo "Total: $TOTAL"
cat << EOF > .github/badge.json
{
"schemaVersion": 1,
"label": "Downloads",
"message": "$TOTAL",
"color": "blue"
}
EOF
- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add ./.github/badge.json ./.github/repos.stats*
git commit -m "total-downloads badge auto-commit"
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}