Badge Downloads #156
This file contains hidden or 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: Badge Downloads | |
on: | |
workflow_dispatch: | |
schedule: | |
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#schedule | |
# At 7 am UTC every day | |
- cron: "0 7 * * *" | |
jobs: | |
update-badges: | |
name: Update Badges | |
runs-on: windows-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@main | |
- name: Get the Numbers | |
run: | | |
# Count downloads for the first page of the repo | |
# By default, GitHub parses only first page | |
$Token = "${{ secrets.GITHUB_TOKEN }}" | |
$Headers = @{ | |
Accept = "application/vnd.github+json" | |
Authorization = "Bearer $Token" | |
} | |
$Parameters = @{ | |
Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases?per_page=100&page=1" | |
Headers = $Headers | |
Verbose = $true | |
} | |
$page1 = ((Invoke-RestMethod @Parameters).assets.download_count | Measure-Object -Sum).Sum | |
# Count downloads for the second page of the repo | |
$Token = "${{ secrets.GITHUB_TOKEN }}" | |
$Headers = @{ | |
Accept = "application/vnd.github+json" | |
Authorization = "Bearer $Token" | |
Verbose = $true | |
} | |
$Parameters = @{ | |
Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases?per_page=100&page=2" | |
Headers = $Headers | |
Verbose = $true | |
} | |
$page2 = ((Invoke-RestMethod @Parameters).assets.download_count | Measure-Object -Sum).Sum | |
# https://community.chocolatey.org/packages/sophia | |
$Parameters = @{ | |
Uri = "https://community.chocolatey.org/api/v2/Packages()?`$filter=Id eq 'sophia' and IsLatestVersion" | |
Verbose = $true | |
} | |
$choco = (Invoke-RestMethod @Parameters).properties.DownloadCount."#text" | |
$Summary = $page1 + $page2 + $choco | |
Write-Verbose -Message $Summary -Verbose | |
$Summary = "{0:N3} Million" -f ($Summary/1000000) | |
Write-Verbose -Message $Summary -Verbose | |
echo "DOWNLOADS_COUNT=$Summary" >> $env:GITHUB_ENV | |
- name: Writing to Gist | |
uses: schneegans/dynamic-badges-action@master | |
with: | |
auth: ${{ secrets.GIST_SOPHIASCRIPT_DOWNLOADS_COUNT }} | |
gistID: 25ddc72387f298503b752ad5b8d16eed | |
filename: SophiaScriptDownloadsCount.json | |
label: downloads | |
message: ${{ env.DOWNLOADS_COUNT }} | |
namedLogo: GitHub | |
color: brightgreen |