-
-
Notifications
You must be signed in to change notification settings - Fork 588
64 lines (56 loc) · 2.24 KB
/
Badge_downloads.yml
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
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
$Summary = $page1 + $page2
$Summary = "{0:N1}k" -f ($Summary/1000)
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 (since May 2020)
message: ${{ env.DOWNLOADS_COUNT }}
namedLogo: PowerShell
color: brightgreen