Skip to content

Update Download Badge #4

Update Download Badge

Update Download Badge #4

Workflow file for this run

name: Update Download Badge
on:
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
downloads:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Generate badge
shell: bash
run: |
packages=(
MockQueryable.Core
MockQueryable.EntityFrameworkCore
MockQueryable.Moq
MockQueryable.NSubstitute
MockQueryable.FakeItEasy
)
total=0
for pkg in "${packages[@]}"; do
package_id="${pkg,,}"
url="https://api.nuget.org/v3/registration5-gz-semver2/${package_id}/index.json"
count=$(curl -fsSL --compressed "$url" \
| jq '[.items[].items[]?.catalogEntry.downloads // 0] | add // 0')
echo "$pkg: $count"
total=$((total + count))
done
if [ "$total" -ge 1000000 ]; then
display=$(awk "BEGIN {printf \"%.1fM\", $total/1000000}")
elif [ "$total" -ge 1000 ]; then
display=$(awk "BEGIN {printf \"%.1fK\", $total/1000}")
else
display="$total"
fi
mkdir -p .github/badges
cat > .github/badges/downloads.json <<EOF
{
"schemaVersion": 1,
"label": "total downloads",
"message": "$display",
"color": "brightgreen"
}
EOF
- name: Create pull request
uses: peter-evans/create-pull-request@v7
with:
commit-message: Update download badge
title: Update download badge
body: Automated update of total NuGet downloads badge.
branch: automation/update-download-badge
delete-branch: true
add-paths: |
.github/badges/downloads.json