-
Notifications
You must be signed in to change notification settings - Fork 2
456 lines (401 loc) · 17.4 KB
/
update-json.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
name: update-json
# Environment variables
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Controls when the action will run.
on:
workflow_dispatch:
schedule:
- cron: "5 */12 * * *"
jobs:
update-pwsh:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Install modules
shell: pwsh
run: |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Install-Module -Name "Evergreen", "DnsClient-PS" -Force
# Import GPG key
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPGKEY }}
passphrase: ${{ secrets.GPGPASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_config_global: true
git_tag_gpgsign: true
git_push_gpgsign: false
git_committer_name: ${{ secrets.COMMIT_NAME }}
git_committer_email: ${{ secrets.COMMIT_EMAIL }}
# Run Pester tests
- name: Update app JSON
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
. "${{ github.workspace }}/scripts/Update-Json.ps1" -Path "${{ github.workspace }}/json"
- name: Save updated files list
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
$UpdateFile = "${{ github.workspace }}/json/_update-pwsh.txt"
if (Test-Path -Path $UpdateFile) {
$Updates = Get-Content -Path $UpdateFile
}
$files = foreach ($item in (git status --short --porcelain)) { ([RegEx]::Match($item, "^..\s(.*)$")).Groups[1].Value }
if ($null -ne $files) {
$Updates += $files
$Updates | Select-Object -Unique | Out-File -FilePath $UpdateFile -Encoding "Utf8" -Force -Verbose
}
- name: Save last update list
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
$params = @{
UpdateFile = "${{ github.workspace }}/json/_update-pwsh.txt"
LastUpdateFile = "${{ github.workspace }}/json/_lastupdate.txt"
}
. "${{ github.workspace }}/scripts/Save-LastUpdate.ps1" @params
# Format the date number for the commit message
- name: Get date
id: get-date
shell: pwsh
run: |
$Date = Get-Date -Format "yyyy.MM.dd"
echo "date=$Date" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Commit changes
id: commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update json ${{ steps.get-date.outputs.date }}.${{ github.run_number }} ${{ github.job }}"
commit_user_name: ${{ secrets.COMMIT_NAME }}
commit_user_email: ${{ secrets.COMMIT_EMAIL }}
- name: "Run if changes have been detected"
if: steps.commit.outputs.changes_detected == 'true'
run: echo "Changes committed."
- name: "Run if no changes have been detected"
if: steps.commit.outputs.changes_detected == 'false'
run: echo "No changes detected."
# update-powershell:
# needs: update-pwsh
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@v4
# with:
# ref: main
# # Run Pester tests
# - name: Git pull
# shell: powershell
# run: |
# git config --global core.safecrlf false
# git pull origin main
# - name: Install modules
# shell: powershell
# run: |
# Install-Module -Name "Evergreen" -Force
# # Import GPG key
# - name: Import GPG key
# id: import_gpg
# uses: crazy-max/ghaction-import-gpg@v6
# with:
# gpg_private_key: ${{ secrets.GPGKEY }}
# passphrase: ${{ secrets.GPGPASSPHRASE }}
# git_user_signingkey: true
# git_commit_gpgsign: true
# git_config_global: true
# git_tag_gpgsign: true
# git_push_gpgsign: false
# git_committer_name: ${{ secrets.COMMIT_NAME }}
# git_committer_email: ${{ secrets.COMMIT_EMAIL }}
# # Run Pester tests
# - name: Update app JSON
# shell: powershell
# working-directory: ${{ github.workspace }}
# run: |
# . "${{ github.workspace }}\scripts\Update-Json.ps1" -Path "${{ github.workspace }}\json"
# - name: Save updated files list
# shell: powershell
# working-directory: ${{ github.workspace }}
# run: |
# $UpdateFile = "${{ github.workspace }}\json\_update-powershell.txt"
# if (Test-Path -Path $UpdateFile) {
# $Updates = Get-Content -Path $UpdateFile
# }
# $files = foreach ($item in (git status --short --porcelain)) { ([RegEx]::Match($item, "^..\s(.*)$")).Groups[1].Value }
# if ($null -ne $files) {
# $Updates += $files
# $Updates | Select-Object -Unique | Out-File -FilePath $UpdateFile -Encoding "Utf8" -Force -Verbose
# }
# - name: Save last update list
# shell: powershell
# working-directory: ${{ github.workspace }}
# run: |
# $params = @{
# UpdateFile = "${{ github.workspace }}\json\_update-powershell.txt"
# LastUpdateFile = "${{ github.workspace }}\json\_lastupdate.txt"
# }
# . "${{ github.workspace }}\scripts\Save-LastUpdate.ps1" @params
# # Format the date number for the commit message
# - name: Get date
# id: get-date
# shell: powershell
# run: |
# $Date = Get-Date -Format "yyyy.MM.dd"
# echo "date=$Date" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
# - name: Commit changes
# id: commit
# uses: stefanzweifel/git-auto-commit-action@v5
# with:
# commit_message: "Update json ${{ steps.get-date.outputs.date }}.${{ github.run_number }} ${{ github.job }}"
# commit_user_name: ${{ secrets.COMMIT_NAME }}
# commit_user_email: ${{ secrets.COMMIT_EMAIL }}
# - name: "Run if changes have been detected"
# if: steps.commit.outputs.changes_detected == 'true'
# run: echo "Changes committed."
# - name: "Run if no changes have been detected"
# if: steps.commit.outputs.changes_detected == 'false'
# run: echo "No changes detected."
update-kv-apps:
needs: [update-pwsh]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Install Wrangler
id: install-wrangler
shell: bash
run: |
npm install -g wrangler
- name: Update Cloudflare KV with recent apps
id: update-apps
shell: pwsh
env:
CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
CLOUDFLARE_ZONE_ID: ${{secrets.CLOUDFLARE_ZONE_ID}}
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
run: |
foreach ($UpdateFile in @("${{ github.workspace }}/json/_update-pwsh.txt", "${{ github.workspace }}/json/_update-powershell.txt")) {
$Files = Get-Content -Path $UpdateFile -ErrorAction "SilentlyContinue"
if ($null -ne $Files) {
Write-Host "Found $($Files.Count) files with changes."
foreach ($file in $Files) {
Write-Host "`nChecking: $file"
if ($file -match "json$") {
Write-Host "Update with: ${{ github.workspace }}/$file."
try {
$file = Get-Item -Path "${{ github.workspace }}/$file" -ErrorAction "SilentlyContinue"
wrangler kv:key put $file.BaseName.ToLower() --path=$($file.FullName) --namespace-id="${{secrets.KV_PROD_NAMESPACE_ID}}"
}
catch {
Write-Warning -Message "Input from $file is not a valid."
}
}
}
}
}
- name: Remove update files
id: remove-update
shell: pwsh
run: |
$Files = "${{ github.workspace }}/json/_update-pwsh.txt", "${{ github.workspace }}/json/_update-powershell.txt"
Remove-Item -Path $Files -Force -ErrorAction "SilentlyContinue"
- name: Install modules
shell: pwsh
run: |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Install-Module -Name "Evergreen" -Force
- name: Update Cloudflare KV with all apps list
id: update-allapps
shell: pwsh
working-directory: "${{ github.workspace }}"
env:
CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
CLOUDFLARE_ZONE_ID: ${{secrets.CLOUDFLARE_ZONE_ID}}
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
run: |
try {
Import-Module -Name "Evergreen" -Force
Find-EvergreenApp | ConvertTo-Json | Out-File -FilePath "./AllApps.json" -Encoding "Utf8" -NoNewline
wrangler kv:key put "_allapps" --path="./AllApps.json" --namespace-id="${{secrets.KV_PROD_NAMESPACE_ID}}"
}
catch { $_.Exception.Message }
finally { Remove-Item -Path "./AllApps.json" -Force -ErrorAction "SilentlyContinue" }
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPGKEY }}
passphrase: ${{ secrets.GPGPASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_config_global: true
git_tag_gpgsign: true
git_push_gpgsign: false
git_committer_name: ${{ secrets.COMMIT_NAME }}
git_committer_email: ${{ secrets.COMMIT_EMAIL }}
- name: Get date
id: get-date
shell: pwsh
run: |
$Date = Get-Date -Format "yyyy.MM.dd"
echo "date=$Date" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Commit changes
id: commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update KV ${{ steps.get-date.outputs.date }}.${{ github.run_number }}"
commit_user_name: ${{ secrets.COMMIT_NAME }}
commit_user_email: ${{ secrets.COMMIT_EMAIL }}
- name: "Run if changes have been detected"
if: steps.commit.outputs.changes_detected == 'true'
run: echo "Changes committed."
- name: "Run if no changes have been detected"
if: steps.commit.outputs.changes_detected == 'false'
run: echo "No changes detected."
update-endpoints-versions:
needs: [update-pwsh]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: 'aaronparker/evergreen'
ref: main
- name: Install Wrangler
id: install-wrangler
shell: bash
run: |
npm install -g wrangler
- name: Update Cloudflare KV for endpoints/versions data
id: update-endpoints
shell: pwsh
working-directory: "${{ github.workspace }}"
env:
CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
CLOUDFLARE_ZONE_ID: ${{secrets.CLOUDFLARE_ZONE_ID}}
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
run: |
# Get endpoint URLs from Evergreen manifests and post to the version endpoint
$UrlMatch = "http[s]?\:\/\/([^\/?#]+)(?:[\/?#]|$)"
$Endpoints = Get-ChildItem -Path "${{ github.workspace }}/Evergreen/Manifests" -Recurse -Include "*.json" | ForEach-Object {
Write-Host "Processing: $($_.FullName)"
[PSCustomObject]@{
Application = $_.BaseName
Endpoints = @(((((Select-String -Path $_.FullName -Pattern $UrlMatch).Matches.Value | `
Select-Object -Unique | `
Sort-Object) -replace "http://|https://", "").TrimEnd("/|#|`",|`"")))
Ports = @(((((Select-String -Path $_.FullName -Pattern $UrlMatch).Matches.Value | Select-Object -Unique))) | ForEach-Object {
if ($_ -match "http://") { "80" }
if ($_ -match "https://") { "443" }
} | Select-Object -Unique | Sort-Object -Descending)
}
}
$Endpoints | ConvertTo-Json | Out-File -FilePath "${{ github.workspace }}/Endpoints.json" -Encoding "Utf8" -NoNewline
wrangler kv:key put "endpoints-versions" --path="${{ github.workspace }}/Endpoints.json" --namespace-id="${{secrets.KV_PROD_NAMESPACE_ID}}"
Remove-Item -Path "${{ github.workspace }}/Endpoints.json"
update-endpoints-downloads:
needs: [update-pwsh]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Install Wrangler
id: install-wrangler
shell: bash
run: |
npm install -g wrangler
- name: Update Cloudflare KV for endpoints/downloads data
id: update-endpoints
shell: pwsh
working-directory: "${{ github.workspace }}"
env:
CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
CLOUDFLARE_ZONE_ID: ${{secrets.CLOUDFLARE_ZONE_ID}}
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
run: |
# Get endpoint URLs from Evergreen manifests and post to the downloads endpoint
$UrlMatch = "http[s]?\:\/\/([^\/?#]+)(?:[\/?#]|$)"
$Endpoints = Get-ChildItem -Path "${{ github.workspace }}/json" -Recurse -Include "*.json" | ForEach-Object {
Write-Host "Processing: $($_.FullName)"
[PSCustomObject]@{
Application = $_.BaseName
Endpoints = @(((((Select-String -Path $_.FullName -Pattern $UrlMatch).Matches.Value | `
Select-Object -Unique | `
Sort-Object) -replace "http://|https://", "").TrimEnd("/|#|`",|`"")))
Ports = @(((((Select-String -Path $_.FullName -Pattern $UrlMatch).Matches.Value | Select-Object -Unique))) | ForEach-Object {
if ($_ -match "http://") { "80" }
if ($_ -match "https://") { "443" }
} | Select-Object -Unique | Sort-Object -Descending)
}
}
$Endpoints | ConvertTo-Json | Out-File -FilePath "${{ github.workspace }}/Endpoints.json" -Encoding "Utf8" -NoNewline
wrangler kv:key put "endpoints-downloads" --path="${{ github.workspace }}/Endpoints.json" --namespace-id="${{secrets.KV_PROD_NAMESPACE_ID}}"
Remove-Item -Path "${{ github.workspace }}/Endpoints.json"
update-docs:
needs: [update-pwsh, update-kv-apps]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.PAT }}
- name: Git pull
shell: pwsh
run: |
git config --global core.safecrlf false
git pull origin main
- name: Install modules
shell: pwsh
run: |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Install-Module -Name "Evergreen", "MarkdownPS" -Force
- name: Generate report
shell: pwsh
run: |
$params = @{
JsonPath = "${{ github.workspace }}/json"
OutputPath = "${{ github.workspace }}/docs/_apps"
IndexFile = "${{ github.workspace }}/docs/index.md"
LastUpdateFile = "${{ github.workspace }}/json/_lastupdate.txt"
}
. "${{ github.workspace }}/scripts/New-Report.ps1" @params
# Format the date number for the commit message
- name: Get date
id: get-date
shell: pwsh
run: |
$Date = Get-Date -Format "yyyy.MM.dd"
echo "date=$Date" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
# Import GPG key
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPGKEY }}
passphrase: ${{ secrets.GPGPASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_config_global: true
git_tag_gpgsign: true
git_push_gpgsign: false
git_committer_name: ${{ secrets.COMMIT_NAME }}
git_committer_email: ${{ secrets.COMMIT_EMAIL }}
- name: Commit changes
id: commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update docs ${{ steps.get-date.outputs.date }}.${{ github.run_number }} ${{ github.job }}"
commit_user_name: ${{ secrets.COMMIT_NAME }}
commit_user_email: ${{ secrets.COMMIT_EMAIL }}
- name: "Run if changes have been detected"
if: steps.commit.outputs.changes_detected == 'true'
run: echo "Changes committed."
- name: "Run if no changes have been detected"
if: steps.commit.outputs.changes_detected == 'false'
run: echo "No changes detected."