generated from ScoopInstaller/BucketTemplate
-
Notifications
You must be signed in to change notification settings - Fork 8
488 lines (434 loc) · 20.9 KB
/
Harvester.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# Copyright (c) 2023 okibcn
# This is free software, licensed under the GNU General Public License v3.0
# See /LICENSE for more information.
# https://github.com/okibcn/ScoopMaster
# Description: Scoop Meta-Bucket
name: Harvester
on:
schedule:
- cron: '21,51 * * * *'
# runs every 30 mins, at minutes 21 and 51 of each hour.
workflow_dispatch:
inputs:
debug_enabled:
description: 'Debug session enabled'
required: false
default: false
type: boolean
release:
description: 'Delivery Channel'
required: false
default: 'Artifact'
type: choice
options:
- "Artifact"
- "Release"
jobs:
build:
runs-on: windows-latest
# Use PowerShell Core shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: pwsh
steps:
- name: "🐞 Debug session"
uses: mxschmitt/action-tmate@v3
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event.inputs.debug_enabled == 'true'
## More info at https://til.simonwillison.net/github-actions/debug-tmate
## or https://github.com/mxschmitt/action-tmate
- name: "⏬ Checkout repository"
uses: actions/checkout@v3
- name: "🐞 Debug session"
uses: mxschmitt/action-tmate@v3
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event.inputs.debug_enabled == 'true'
## More info at https://til.simonwillison.net/github-actions/debug-tmate
## or https://github.com/mxschmitt/action-tmate
- name: "🔍 Discover known buckets from Scoop-Directory website."
run: |
cd ..
$lOfficial = (curl -s -X POST 'https://scoopsearch.search.windows.net/indexes/apps/docs/search?api-version=2020-06-30' `
-H 'Content-Type: application/json' `
-H 'api-key: DC6D2BBE65FC7313F2C52BBD2B0286ED' `
-d '
{
\"facets\":[\"Metadata/Repository,count:10000\"],
\"filter\":\"Metadata/OfficialRepositoryNumber eq 1\",
\"top\":0
}' | jq . | sls 'http.*github[^"]+').Matches.Value
Write-Host "$($lOfficial.count) Official buckets found in Scoop.sh"
$lCommunity = (curl -s -X POST 'https://scoopsearch.search.windows.net/indexes/apps/docs/search?api-version=2020-06-30' `
-H 'Content-Type: application/json' `
-H 'api-key: DC6D2BBE65FC7313F2C52BBD2B0286ED' `
-d '
{
\"facets\":[\"Metadata/Repository,count:10000\"],
\"filter\":\"Metadata/OfficialRepositoryNumber eq 0\",
\"top\":0
}' | jq . | sls 'http.*github[^"]+').Matches.Value
Write-Host "$($lCommunity.count) Community buckets found in Scoop.sh"
$scoopDBURL = "https://rasa.github.io/scoop-directory/by-apps.html"
$ErrorActionPreference = 'SilentlyContinue'
$lScoopdir = @()
$source = iwr $scoopDBURL
$source.Content -split '\r?\n' | ForEach-Object -Process {
if ($_ -match '<h2.*(http[^\"]+)"'){
$lScoopdir = $lScoopdir + ( , $matches[1])
}
}
Write-Host "$($lScoopdir.count) buckets found in Scoop-Directory."
$lActive = ($lOfficial+$lCommunity+$lScoopdir) | Sort-Object | Get-Unique
Write-Host "$($lActive.count) total Active buckets found so far"
$oldActive=gc ScoopMaster/ActiveBuckets
Write-Host "$($oldActive.count) previous Active buckets"
$oldDeprecated=gc ScoopMaster/DeprecatedBuckets
Write-Host "$($oldDeprecated.count) previous deprecated buckets"
$lDeprecated = ($oldActive+$oldDeprecated) | Sort-Object | Get-Unique | ? { -not ("$lActive" -match "$_") }
Write-Host "$($lDeprecated.count) current deprecated buckets"
$lBuckets = ($lActive+$lDeprecated) | Sort-Object | Get-Unique
Write-Host "$($lBuckets.count) Total buckets"
$lDeprecated | Set-Content ScoopMaster/DeprecatedBuckets
$lBuckets | Set-Content ScoopMaster/ActiveBuckets
cp ScoopMaster/ActiveBuckets Bucket_list.txt
- name: "⏬ Download Active buckets"
run: |
cd ..
$lBuckets=(gc .\Bucket_list.txt)
## CREATE INPUT FILE FOR ARIA2C
$lZips=$lBuckets | %{
if( -not ($_ -match 'https:\/\/github.com\/(.+)')){
$_ >> ERROR_badrepos.txt
return}
if(($_ -match 'okibcn\/ScoopMaster')){
return}
$owner_repo=$matches[1].replace('/','~')
return "$_/archive/refs/heads/master.zip`n out=$owner_repo.zip"
}
$lZips > download_list.txt
echo "UPDATE=$(Get-Date -format 'yyyy-MM-ddTHH:mm:ssZ')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
# DOWNLOAD BUCKETS
aria2c --save-session aria2-out.txt -j 16 -i download_list.txt -d zips
(cmd.exe /c dir /s /b /a-d zips) > Zip_list.txt
echo "N_BUCKETS=$((cat .\Zip_list.txt).count)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: "📃 Extract manifests from downloaded buckets"
run: |
cd ..
# EXTRACT MANIFESTS
7z e -y zips/*.zip -ojsons/* */bucket/*.json */*.json
# PREPARE OUTPUT
Remove-Item -Force -Recurse jsons/*/.*.json
$nManifests = (cmd.exe /c dir /s /b /a-d jsons).count
$nZips = (cat .\Zip_list.txt).count
Write-Host "PROCESS COMPLETED. $nManifests manifests extracted from $nZips downloaded buckets."
- name: "📝 Indexing JSON manifests"
run: |
function longV([string]$v) {
$numbers = [regex]::matches($v, '\d+')
if ($numbers.Count -eq 0) {
#doesn't contain numbers
return $v
}
$notnumbers = [regex]::matches($v, '([^\d]+)')
$longnumbers = @($numbers | % {
$_.Value.PadLeft(10, '0')
})
$i = [int]0
if ($numbers[0].Index -eq 0) {
# starts with a number
($longnumbers | % { $_ ; $notnumbers[$i].value ; $i++ }) -join ''
}
else {
($notnumbers | % { $_.Value ; $longnumbers[$i] ; $i++ }) -join ''
}
}
# Returns 0 if both versions match, 1 if the firs one is higher,
# and -1 if the second is higher
function CompareV([string]$a, [string]$b) {
if ($a -eq $b) {
return 0
}
if ( $(longV $a) -gt $(longV $b)) {
return 1
}
return -1
}
cd ..
## PROCESS JSON FILES
$FullDB = $null
$FullDB = New-Object system.data.datatable
$FullDB.Columns.Add("Name") | Out-Null
$FullDB.Columns.Add("Version") | Out-Null
$FullDB.Columns.Add("Date") | Out-Null
$FullDB.Columns.Add("Bucket") | Out-Null
$FullDB.Columns.Add("Description") | Out-Null
$FullDB.Columns.Add("Homepage") | Out-Null
$FullDB.Columns.Add("Autoupdate") | Out-Null
$FullDB.Columns.Add("Clone") | Out-Null
$files = gci jsons/*/*.json ##o##
$nManifests=$files.Count
$progress=0
Write-host "##"
Write-host "## INDEXING JSON FILES..."
Write-host "## ================================="
Write-host "##"
foreach ( $file in $files ) {
$name = $file.BaseName
$bucket = $file.FullName.split('\')[-2].replace('~', "/")
$progress++
$percent = [math]::round(100 * $progress / $nManifests)
if ($percent -ne $oldpercent){
Write-Output "( $percent% ) $progress / $nManifests (indexed/total) Indexing bucket $bucket"
$oldpercent=$percent
}
$date = $file.LastWriteTimeUtc.ToString("yyyy-MM-ddTHH:mm:ssZ")
$filecontent = gc $file
try{
$json = $filecontent | ConvertFrom-Json
$version = $json.version
$description = "$($json.description)"
}catch{
$file.fullname >> ERROR_manifest.txt
continue
}
try{
$homepage = $json.homepage
}catch{
$file.fullname >> ERROR_manifest.txt
$homepage = ""
}
$Clone= if ($filecontent -Match 'ghproxy|"_from"') {'C'} else {'N'}
$autoup = if ($json.autoupdate) {'A'} else {'_'}
[void]$FullDB.Rows.Add($name, $version, $date, $bucket, $description, $homepage, $autoup, $clone)
}
$DB = $FullDB | Sort-Object Name
$hash = $null
$hash = New-Object system.data.datatable
$hash.Columns.Add("Name") | Out-Null
$hash.Columns.Add("Version") | Out-Null
$hash.Columns.Add("Date") | Out-Null
$hash.Columns.Add("Bucket") | Out-Null
$hash.Columns.Add("Description") | Out-Null
$hash.Columns.Add("Homepage") | Out-Null
$hash.Columns.Add("Autoupdate") | Out-Null
$hash.Columns.Add("Priority") | Out-Null
$name = ""
$nApps = 0
$progress=0
Write-host "##"
Write-host "## FINDING LATEST VERSIONS..."
Write-host "## ================================="
Write-host "##"
foreach ( $row in $DB ) {
$progress++
$percent = [math]::round(100 * $progress / $nManifests)
if ($percent -ne $oldpercent){
Write-Output "( $percent% ) $progress / $nManifests - $nApps (indexed/total-harvested) Last checked app: $name.json"
$oldpercent=$percent
}
if ($row.Bucket -eq "lzwme/scoop-proxy-cn") { continue }
if ($row.Bucket -eq "duzyn/scoop-cn") { continue }
if ($row.name -ne $name) {
$name = $row.name
[void]$hash.Rows.Add($name, $row.Version, $row.Date, $row.Bucket, $row.Description, $row.Homepage, $row.Autoupdate, $row.Clone)
$nApps++
continue
}
$app=[ref]$hash.Rows[-1]
$current = if ($hash.Rows[-1].Bucket -match '^okibcn/' ) {'O'} else {'_'}
$current = $current + $hash.Rows[-1].autoupdate + $hash.Rows[-1].Version
$current = if ($hash.Rows[-1].Bucket -match '^ScoopInstaller/' ) {$current + 'S'} else {$current + $hash.Rows[-1].Priority}
$candidate = if ($row.Bucket -match '^okibcn/' ) {'O'} else {'_'}
$candidate = $candidate + $row.autoupdate + $row.Version
$candidate = if ($row.Bucket -match '^ScoopInstaller/' ) {$candidate + 'S'} else {$candidate + $row.Clone}
switch ( CompareV $candidate $current ) {
-1 { # not higher priority
break
}
1 { # higher priority, replace entry
$hash.Rows[-1].Version = $row.Version
$hash.Rows[-1].Date = $row.Date
$hash.Rows[-1].Bucket = $row.Bucket
$hash.Rows[-1].Description = $row.Description
$hash.Rows[-1].Homepage = $row.Homepage
$hash.Rows[-1].Autoupdate = $row.Autoupdate
$hash.Rows[-1].Priority = $row.Clone
}
0 { # same priority, update newest
if ($row.date -gt $hash.Rows[-1].LastDate) {
$hash.Rows[-1].Date = $row.Date
$hash.Rows[-1].Bucket = $row.Bucket
$hash.Rows[-1].Description = $row.Description
$hash.Rows[-1].Homepage = $row.Homepage
$hash.Rows[-1].Autoupdate = $row.Autoupdate
$hash.Rows[-1].Priority = $row.Clone
}
}
}
}
$hash = $hash | select | Sort-Object Name
$scoopDBfile = "./LastAppsDB.csv"
$hash | ConvertTo-csv > $scoopDBfile
mkdir local | Out-Null
$progress=0
$nApps=$hash.rows.count
Write-host "##"
Write-host "## CHECKING LINE AND FILE ENDING FORMAT OF SELECTED MANIFESTS..."
Write-host "## ============================================================="
Write-host "##"
foreach ( $row in $hash ) {
[void]$FullDB.Rows.Add($row.Name, $row.Version, $row.Date, "okibcn/ScoopMaster", $row.Description, $row.Homepage, $row.Autoupdate)
$file="jsons/$( $row.Bucket.replace('/','~') )/$($row.Name).json"
Get-Content $file > "local/$($row.Name).json"
$progress++
$percent = [math]::round(100 * $progress / $nApps)
if ($percent -ne $oldpercent){
Write-Output "( $percent% ) $progress / $nApps (hasvested/total) Last processed app: $($row.Name).json"
$oldpercent=$percent
}
}
$FullDB = $FullDB | select Name, Version, Autoupdate, Bucket, Homepage, Description | Sort-Object Name,Autoupdate,Version
$scoopDBfile = "./AllAppsDB.csv"
$FullDB | ConvertTo-csv > $scoopDBfile
echo "N_MANIFESTS=$nManifests" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "N_APPS=$nApps" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7z a AllAppsDB.7z AllAppsDB.csv
7z a LastAppsDB.7z LastAppsDB.csv
move-item *DB.* ScoopMaster
- name: "📦 Prepare updated repo"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
############################
## ##
## UPDATE BUCKET ##
## ##
############################
# cd ..
# aria2c https://github.com/okibcn/ScoopMaster/archive/refs/heads/master.zip -o ScoopMaster.zip
# 7z e ScoopMaster.zip */bucket/* -obucket
# cd ScoopMaster
$lDeleted = $lUpdated = $lNew = @()
$progress = 0
Write-host "##"
Write-host "## CHECKING MODIFIED MANIFESTS..."
Write-host "## ================================="
Write-host "##"
$current = gci bucket/*.json
foreach ($file in $current) {
$progress++
$percent = [math]::round(100 * $progress / $env:N_APPS)
if ($percent -ne $oldpercent){
Write-Output "( $percent% ) $progress / $env:N_APPS (reviewed/total) Last checked app: $($file.BaseName)"
$oldpercent=$percent
}
$candidate = "../local/$($file.Name)"
if (-not (test-path $candidate)) {
Remove-Item $file
$lDeleted += $file.BaseName
continue
}
$hFile = (Get-FileHash -Algorithm SHA1 $file).Hash
$hCandidate = (Get-FileHash -Algorithm SHA1 $candidate).Hash
if ($hCandidate -ne $hFile) {
Move-Item $candidate $file -Force
$lUpdated += $file
continue
}
Remove-Item $candidate
}
$lNew = (gci ../local/*).BaseName
move-item ../local/* bucket -Force
move-item ../*.txt .
$lDeleted > AppsLeavingScoop.txt
$lUpdated > AppsUpdated.txt
$lNew > AppsNew.txt
if ( "${{github.event.inputs.release}}" -eq 'Artifact') {7z a '-x!*.7z' ScoopMaster.7z *}
$downloads=((( gh api repos/okibcn/ScoopMaster/releases | jq . ) -match "download_count" | sls '\d+' ).matches | Measure-Object Value -Sum ).Sum
$stats=@{}
$stats.Add('date',"$($env:UPDATE)")
$stats.Add('prevDate',"$((gc stats.json | ConvertFrom-Json).date.ToString("yyyy-MM-ddTHH:mm:ssZ"))")
$stats.Add('totalBuckets',(gc Bucket_list.txt).count)
$stats.Add('badBuckets',((gc ./aria2-out.txt) | sls 'http').Matches.count)
$stats.Add('buckets',$stats.totalBuckets - $stats.badBuckets )
$stats.Add('manifests',$( [int]($env:N_MANIFESTS) + [int]($env:N_APPS) ) )
$stats.Add('badManifests',(gc ERROR_manifest.txt).count)
$stats.Add('apps',[int]$env:N_APPS)
$stats.Add('appsNew',$lnew.count)
$stats.Add('appsUpdated',$lUpdated.count)
$stats.Add('appsDeleted',$lDeleted.count)
$stats.Add('downloads',[int]$downloads)
$stats.Add('totalDownloads',[int]$( (gc stats.json | ConvertFrom-Json).totalDownloads + $stats.downloads ))
$stats | ConvertTo-Json > stats.json
"New Downloads: $downloads"
"Total Downloads: $( (gc stats.json | ConvertFrom-Json).totalDownloads + $stats.downloads )"
(gc .\README.md) -Replace "\d+(?=\*\* manifests)","$($stats.manifests)" | Set-Content README.md
(gc .\README.md) -Replace "\d+(?=\*\* buckets)","$($stats.buckets)" | Set-Content README.md
(gc .\README.md) -Replace "\d+(?=\*\* apps)","$($stats.apps)" | Set-Content README.md
Write-Output "These databases are updated every 30 minutes. The current content and metrics for these databases are:" > body.txt
Write-Output "- **AllAppsDB** contains info of **$($stats.manifests)** manifests in **$($stats.buckets)** online buckets." >> body.txt
Write-Output "- **LastAppsDB** contains highest version of each of the **$($stats.apps)** apps in Scoop, all of them contained in this bucket." >> body.txt
Write-Output " " >> body.txt
Write-Output "These databases can be used for fast online data retrieval, for instance by CLI scoop search utilities such as `ss` (ScoopSearch)" >> body.txt
Write-Output " " >> body.txt
Write-Output "The current snapshot timestamp for these databases is $($stats.date). In the last 30 minutes:" >> body.txt
Write-Output "- $($stats.appsNew) apps were added to Scoop." >> body.txt
Write-Output "- $($stats.appsUpdated) apps were updated." >> body.txt
Write-Output "- $($stats.appsDeleted) apps left Scoop." >> body.txt
Write-Output " "
Write-Output " "
Write-Output "- AllAppsDB contains the data of **$($stats.manifests)** manifests in $($stats.buckets) online buckets."
Write-Output "- LastAppsDB contains highest version of each of the $($stats.apps) apps in Scoop, all of them contained in this bucket."
Write-Output " "
Write-Output "The current snapshot timestamp for these databases is $($stats.date). In the last 30 minutes:"
Write-Output "- $($stats.appsNew) apps were added to Scoop."
Write-Output "- $($stats.appsUpdated) apps were updated."
Write-Output "- $($stats.appsDeleted) apps left Scoop."
- name: "🐞 Debug session"
uses: mxschmitt/action-tmate@v3
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event.inputs.debug_enabled == 'true'
## More info at https://til.simonwillison.net/github-actions/debug-tmate
## or https://github.com/mxschmitt/action-tmate
- name: "🎉 Release updated databases"
uses: softprops/action-gh-release@v0.1.15
# go to https://github.com/OWNER/REPO/settings/actions and
# in "**"Workflow Permissions" section give actions **Read and Write permissions**.
if: github.event_name != 'workflow_dispatch' || github.event.inputs.release == 'Release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: Databases
body_path: body.txt
files: ./*DB.*
- name: "⭐ Update repo (Commit-n-Push)"
if: github.event_name != 'workflow_dispatch' || github.event.inputs.release == 'Release'
run: |
git config --global core.autocrlf false
git config --global core.safecrlf false
git -C . init
git -C . config --local user.name "GitHub Actions"
git -C . config --local user.email actions@github.com
git -C . add -A
git -C . commit --no-verify -m "Update timestamp $($env:UPDATE)"
$sha=(git -C . rev-parse HEAD)
git push
- name: "👍 Full Upload as Artifact"
uses: actions/upload-artifact@v3
# if: github.event_name == 'workflow_dispatch'
if: github.event.inputs.release == 'Artifact'
with:
name: Logs
path: |
*.7z
- name: "👍 Standard Upload logs as Artifact"
uses: actions/upload-artifact@v3
# if: github.event_name == 'workflow_dispatch'
if: github.event_name != 'workflow_dispatch' || github.event.inputs.release == 'Release'
with:
name: Logs
path: |
*.txt