Browse Source

Updated downloads count badge method

main
Dmitry Nefedov 3 weeks ago
parent
commit
2023294552
  1. 83
      .github/workflows/Badge_downloads.yml

83
.github/workflows/Badge_downloads.yml

@ -17,29 +17,33 @@ jobs:
- name: Get download counts - name: Get download counts
run: | run: |
# Count downloads for the first page of the repo
# By default, GitHub parses only first page
$Token = "${{ secrets.GITHUB_TOKEN }}" $Token = "${{ secrets.GITHUB_TOKEN }}"
$Headers = @{ $Headers = @{
Accept = "application/vnd.github+json" Accept = "application/vnd.github+json"
Authorization = "Bearer $Token" Authorization = "Bearer $Token"
}
$Parameters = @{
Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases?per_page=100&page=1"
Headers = $Headers
UseBasicParsing = $true
Verbose = $true
} }
$page1 = ((Invoke-RestMethod @Parameters).assets.download_count | Measure-Object -Sum).Sum
# Count downloads for the second page of the repo # Count downloads for the first page of the repo
$Parameters = @{ # By default, GitHub parses only first page
Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases?per_page=100&page=2" $Releases = @()
$Page = 1
do
{
$Parameters = @{
Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases?per_page=100&page=$page"
Headers = $Headers Headers = $Headers
UseBasicParsing = $true UseBasicParsing = $true
Verbose = $true Verbose = $true
}
$Pages = Invoke-RestMethod @Parameters
$Releases += $Pages
$Page++
} }
$page2 = ((Invoke-RestMethod @Parameters).assets.download_count | Measure-Object -Sum).Sum while ($Pages.Count -gt 0)
$Allpages = ($Releases.assets.download_count | Measure-Object -Sum).Sum
# https://community.chocolatey.org/packages/sophia # https://community.chocolatey.org/packages/sophia
$Parameters = @{ $Parameters = @{
@ -51,24 +55,49 @@ jobs:
# https://sourceforge.net/projects/sophia-script-windows.mirror/ # https://sourceforge.net/projects/sophia-script-windows.mirror/
$Parameters = @{ $Parameters = @{
Uri = "https://sourceforge.net/projects/sophia-script-windows.mirror/files/stats/json?start_date=2025-09-11&end_date=$(Get-Date -Format "yyyy-MM-dd")" Uri = "https://sourceforge.net/projects/sophia-script-windows.mirror/files/stats/json?start_date=2025-09-11&end_date=$(Get-Date -Format 'yyyy-MM-dd')"
UseBasicParsing = $true UseBasicParsing = $true
Verbose = $true Verbose = $true
} }
$sourceforge = (Invoke-RestMethod @Parameters).total $SourceForge = (Invoke-RestMethod @Parameters).total
$Summary = "{0:N3} Million" -f (($page1 + $page2 + $choco + $sourceforge)/1000000) $Summary = "{0:N3} Million" -f (($Allpages + $SourceForge)/1000000)
Write-Verbose -Message $Summary -Verbose Write-Verbose -Message $Summary -Verbose
echo "DOWNLOADS_COUNT=$Summary" >> $env:GITHUB_ENV echo "DOWNLOADS_COUNT=$Summary" >> $env:GITHUB_ENV
- name: Writing to Gist - name: Writing to Gist
uses: schneegans/dynamic-badges-action@master env:
with: GIST_TOKEN: ${{ secrets.GIST_SOPHIASCRIPT_DOWNLOADS_COUNT }}
auth: ${{ secrets.GIST_SOPHIASCRIPT_DOWNLOADS_COUNT }} shell: pwsh
gistID: 25ddc72387f298503b752ad5b8d16eed run: |
filename: SophiaScriptDownloadsCount.json # https://gist.github.com/farag2/25ddc72387f298503b752ad5b8d16eed
label: downloads
message: ${{ env.DOWNLOADS_COUNT }} $fileContent = @{
namedLogo: GitHub schemaVersion = 1
color: brightgreen label = "downloads"
message = $env:DOWNLOADS_COUNT
color = "brightgreen"
namedLogo = "GitHub"
} | ConvertTo-Json
$Body = @{
files = @{
"SophiaScriptDownloadsCount.json" = @{
content = $fileContent
}
}
} | ConvertTo-Json -Depth 5
$Headers = @{
Authorization = "Bearer $env:GIST_TOKEN"
Accept = "application/vnd.github+json"
}
$Parameters = @{
Uri = "https://api.github.com/gists/25ddc72387f298503b752ad5b8d16eed"
Method = "Patch"
Body = $Body
Headers = $Headers
UseBasicParsing = $true
Verbose = $true
}
Invoke-RestMethod @Parameters

Loading…
Cancel
Save