Skip to content

Get download stats #172

Get download stats

Get download stats #172

Workflow file for this run

name: Get download stats
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
on:
schedule:
- cron: "0 5 * * *"
workflow_dispatch: {}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- 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 - | sed -n '0,/---/d; p' | sed 's/[()",{} ]/\n/g' \
| grep -i 'https.*pkgforge-dev.*AppImage.*' | awk -F'/' '{print $NF}' | grep -v '\.md')"
for REPO in $REPOS; do
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}')
[ -n "$NUM" ] || exit 1
echo "${REPO}: $NUM "
TOTAL=$(( TOTAL + NUM ))
done
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
git commit -m "total-downloads badge auto-commit"
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}