-
Notifications
You must be signed in to change notification settings - Fork 2
279 lines (247 loc) · 11.5 KB
/
Copy pathupdate-apps.yml
File metadata and controls
279 lines (247 loc) · 11.5 KB
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
name: 'Update apps'
# Environment variables
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Controls when the action will run.
on:
workflow_run:
workflows: ['Update self-hosted']
types:
- completed
workflow_dispatch:
jobs:
update-pwsh:
runs-on: windows-latest
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run && github.event.workflow_run.conclusion == 'success') }}
steps:
- uses: actions/checkout@v7
with:
ref: main
- name: Install modules
shell: pwsh
run: |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Register-PackageSource -Name "NuGet" -Location "https://api.nuget.org/v3/index.json" -ProviderName "NuGet" -Trusted
Install-PackageProvider -Name "PowerShellGet" -MinimumVersion "2.2.5" -Force -ErrorAction "Ignore"
Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted"
Install-Module -Name "DnsClient-PS"
Install-Module -Name "Evergreen" -AllowClobber -SkipPublisherCheck -AllowPrerelease -Force -Verbose
Update-Evergreen
# Import GPG key
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v7
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: Update app JSON
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
Import-Module -Name "Evergreen"
. "${{ github.workspace }}\scripts\Update-Json.ps1" -Path "${{ github.workspace }}\json"
# Write the supported apps to a JSON file for reference
Find-EvergreenApp | ConvertTo-Json | Out-File "${{ github.workspace }}\json\supported-apps.json" -Encoding utf8 -Force
# 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@v7
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@v7
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: |
# Fetch at least two commits so HEAD~1 is available
git fetch --no-tags --prune --depth=2 origin main || true
# Get list of changed json files in the json directory from the previous commit
$changed = git diff --name-only HEAD~1 HEAD -- 'json/*.json' 2>$null
if (-not $changed) {
Write-Host "No json files changed in the previous commit."
exit 0
}
$files = $changed -split "`n" | Where-Object { $_ -and $_ -match '\.json$' } | ForEach-Object { $_.Trim() }
Write-Host "Found $($files.Count) json files changed:"
$files | ForEach-Object { Write-Host " - $_" }
foreach ($rel in $files) {
try {
$full = Join-Path -Path $Env:GITHUB_WORKSPACE -ChildPath $rel
if (-not (Test-Path $full)) {
Write-Warning -Message "File not found: $full"
continue
}
$key = [System.IO.Path]::GetFileNameWithoutExtension($rel).ToLower()
Write-Host "Uploading $rel as KV key '$key'..."
wrangler kv key put $key --path="$full" --namespace-id="${{secrets.KV_PROD_NAMESPACE_ID}}" --remote
}
catch {
Write-Warning -Message "Failed to upload $rel - $($_.Exception.Message)"
}
}
- name: Install modules
shell: pwsh
run: |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Register-PackageSource -Name "NuGet" -Location "https://api.nuget.org/v3/index.json" -ProviderName "NuGet" -Trusted
Install-PackageProvider -Name "PowerShellGet" -MinimumVersion "2.2.5" -Force -ErrorAction "Ignore"
Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted"
Install-Module -Name "Evergreen" -AllowClobber -SkipPublisherCheck -AllowPrerelease -Force -Verbose
Update-Evergreen
- 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"
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}}" --remote
}
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@v7
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@v7
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 }}
update-endpoints-versions:
needs: [update-pwsh]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
repository: "eucpilots/evergreen-apps"
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 }}/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}}" --remote
Remove-Item -Path "${{ github.workspace }}/Endpoints.json"
update-endpoints-downloads:
needs: [update-pwsh]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
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}}" --remote
Remove-Item -Path "${{ github.workspace }}/Endpoints.json"