-
Notifications
You must be signed in to change notification settings - Fork 0
480 lines (443 loc) · 18.3 KB
/
main.yaml
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
name: Build & Release (NKDAgility)
permissions:
contents: read
pull-requests: write
on:
push:
branches: ["main"]
tags-ignore: ["v*-*"]
pull_request:
branches: ["main"]
workflow_dispatch:
inputs:
ForceRelease:
description: "Force a release! Use when changes hapen out of sync and `src` and `docs` folder changes are not detected."
required: false
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: pwsh
jobs:
# Setup & Configuration
Setup:
name: "Setup & Configuration "
runs-on: ubuntu-latest
outputs:
GitVersion_BranchName: ${{ steps.gitversion.outputs.GitVersion_BranchName }}
GitVersion_SemVer: ${{ steps.gitversion.outputs.GitVersion_SemVer }}
GitVersion_PreReleaseLabel: ${{ steps.gitversion.outputs.GitVersion_PreReleaseLabel }}
GitVersion_AssemblySemVer: ${{ steps.gitversion.outputs.GitVersion_AssemblySemVer }}
GitVersion_InformationalVersion: ${{ steps.gitversion.outputs.GitVersion_InformationalVersion }}
GitVersion_NuGetVersion: ${{ steps.gitversion.outputs.GitVersion_NuGetVersion }}
GitVersion_PreReleaseNumber: ${{ steps.gitversion.outputs.GitVersion_PreReleaseNumber }}
GitVersion_MajorMinorPatch: ${{ steps.gitversion.outputs.GitVersion_MajorMinorPatch }}
nkdAgility_Ring: ${{ steps.nkdagility.outputs.Ring }}
nkdAgility_AzureSitesEnvironment: ${{ steps.nkdagility.outputs.AzureSitesEnvironment }}
nkdAgility_AzureSitesConfig: ${{ steps.nkdagility.outputs.AzureSitesConfig }}
nkdAgility_BLOB_URL_BIT: ${{ steps.nkdagility.outputs.BLOB_URL_BIT }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: List folders
shell: pwsh
run: |
Get-ChildItem -Path "${{ github.workspace }}" -Directory -Force | Select-Object -ExpandProperty FullName
- uses: actions/upload-artifact@v4
with:
name: Scripts
path: "./.powershell/**"
if-no-files-found: error
include-hidden-files: true
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.0.0
with:
versionSpec: "5.x"
includePrerelease: true
- name: Execute GitVersion
id: gitversion
uses: gittools/actions/gitversion/execute@v3.0.0
with:
useConfigFile: true
configFilePath: .github/GitVersion.yml
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.NKDAGILITY_BOT_APP_ID }}
private-key: ${{ secrets.NKDAGILITY_BOT_CLIENTSECRET }}
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
content:
- 'content/**'
- name: "Build NKDAgility Outputs"
shell: pwsh
id: nkdagility
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
# Get Branch Name
Write-Output "::group::Get Branch Name"
Write-Output "-------------------------------------------"
$branchName = "${{ github.head_ref || github.ref_name }}"
Write-Output "We are running on: $branchName!"
$branchSafeName = $branchName.Replace("/", "-")
Write-Output "branchSafeName: $branchSafeName!"
Write-Output "-------------------------------------------"
Write-Output "::endgroup::"
# Ring Setup
Write-Output "::group::Ring Control Setup"
Write-Output "-------------------------------------------"
Write-Output "Ring Control Setup"
Write-Output "-------------------------------------------"
$Ring = "Canary"
$docs_deploy_folder = "./azure-devops-migration-tools/";
$docs_baseURL = "/learn/azure-devops-migration-tools"
$BLOB_URL_BIT = "/blob"
switch ($Env:GitVersion_PreReleaseLabel) {
"" {
$Ring = "Production";
$AzureSitesEnvironment = ""
$AzureSitesConfig = "production"
$docs_baseURL = "/"
}
"Preview" {
$Ring = "Preview";
$AzureSitesEnvironment = "preview";
$AzureSitesConfig = "preview"
$docs_baseURL = "/preview"
}
default {
$Ring = "Canary";
$AzureSitesEnvironment = "canary-${{ github.event.pull_request.number }}"
$AzureSitesConfig = "canary"
$BLOB_URL_BIT = 'https://nkdagilityblobs.blob.core.windows.net/$web'
$docs_baseURL = "/canary/$branchSafeName"
}
}
Write-Output "We are running for the $Ring Ring!"
echo "Ring=$Ring" >> $env:GITHUB_OUTPUT
Write-Output "We are running for the $AzureSitesEnvironment AzureSitesEnvironment!"
echo "AzureSitesEnvironment=$AzureSitesEnvironment" >> $env:GITHUB_OUTPUT
Write-Output "We are running for the $AzureSitesConfig AzureSitesConfig!"
echo "AzureSitesConfig=$AzureSitesConfig" >> $env:GITHUB_OUTPUT
Write-Output "We are running for the $BLOB_URL_BIT BLOB_URL_BIT!"
echo "BLOB_URL_BIT=$BLOB_URL_BIT" >> $env:GITHUB_OUTPUT
Write-Output "docs_baseURL=$docs_baseURL"
echo "docs_baseURL=$docs_baseURL" >> $env:GITHUB_OUTPUT
Write-Output "-------------------------------------------"
Write-Output "::endgroup::"
# Setup Validator
SetupSummeryStage:
name: "Build Run Data"
runs-on: ubuntu-latest
needs: Setup
steps:
- name: "Show Summery"
if: always()
shell: pwsh
id: nkdagility-summery
run: |
$markdown = @"
## ${{needs.Setup.outputs.GitVersion_SemVer}} (${{needs.Setup.outputs.nkdAgility_Ring}})
### NKDAgility
- nkdAgility_Ring: ${{needs.Setup.outputs.nkdAgility_Ring}}
- nkdAgility_AzureSitesEnvironment: ${{needs.Setup.outputs.nkdAgility_AzureSitesEnvironment}}
- nkdAgility_AzureSitesConfig: ${{needs.Setup.outputs.nkdAgility_AzureSitesConfig}}
- nkdAgility_BLOB_URL_BIT: ${{needs.Setup.outputs.nkdAgility_BLOB_URL_BIT}}
### GitVersion
- GitVersion_BranchName: ${{needs.Setup.outputs.GitVersion_BranchName}}
- GitVersion_SemVer: ${{needs.Setup.outputs.GitVersion_SemVer}}
- GitVersion_PreReleaseLabel: ${{needs.Setup.outputs.GitVersion_PreReleaseLabel}}
- GitVersion_AssemblySemVer: ${{needs.Setup.outputs.GitVersion_AssemblySemVer}}
- GitVersion_InformationalVersion: ${{needs.Setup.outputs.GitVersion_InformationalVersion}}
- GitVersion_NuGetVersion: ${{needs.Setup.outputs.GitVersion_NuGetVersion}}
"@
echo $markdown >> $Env:GITHUB_STEP_SUMMARY
# Spellcheck
Spellcheck:
name: "Spellcheck Site"
runs-on: ubuntu-latest
if: ${{ success() }}
needs: [Setup]
env:
GitVersion_SemVer: ${{ needs.Setup.outputs.GitVersion_SemVer }}
GitVersion_AssemblySemVer: ${{ needs.Setup.outputs.GitVersion_AssemblySemVer }}
GitVersion_InformationalVersion: ${{ needs.Setup.outputs.GitVersion_InformationalVersion }}
steps:
- uses: actions/checkout@v4
with:
submodules: true # Fetch Hugo themes (true OR recursive)
- uses: igsekor/pyspelling-any@v1.0.4
id: spellcheck
name: Spellcheck
with:
args: --report report.json
- uses: actions/upload-artifact@v4
with:
name: spellcheck
path: ./report.json
# Build Docs
BuildSite:
name: "Build Site"
runs-on: ubuntu-latest
if: ${{ success() }}
needs: [Setup]
env:
GitVersion_SemVer: ${{ needs.Setup.outputs.GitVersion_SemVer }}
GitVersion_AssemblySemVer: ${{ needs.Setup.outputs.GitVersion_AssemblySemVer }}
GitVersion_InformationalVersion: ${{ needs.Setup.outputs.GitVersion_InformationalVersion }}
steps:
- uses: actions/checkout@v4
with:
submodules: true # Fetch Hugo themes (true OR recursive)
- uses: cschleiden/replace-tokens@v1
with:
files: '["**/*.html", "**/*.yaml"]'
tokenPrefix: "#{"
tokenSuffix: "}#"
env:
GitVersion_SemVer: ${{ needs.Setup.outputs.GitVersion_SemVer }}
GitVersion_AssemblySemVer: ${{ needs.Setup.outputs.GitVersion_AssemblySemVer }}
GitVersion_InformationalVersion: ${{ needs.Setup.outputs.GitVersion_InformationalVersion }}
GitVersion.SemVer: ${{ needs.Setup.outputs.GitVersion_SemVer }}
nkdAgility_AzureSitesConfig: ${{ needs.Setup.outputs.nkdAgility_AzureSitesConfig }}
PR_Number: ${{ github.event.number }}
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: "latest"
extended: true
- name: Build
run: |
Write-Host "Building site for ${{ (needs.Setup.outputs.nkdAgility_AzureSitesConfig) }}";
$env:HUGO_ENV = "${{ (needs.Setup.outputs.nkdAgility_AzureSitesConfig) }}";
hugo --source site --config hugo.yaml,hugo.${{ (needs.Setup.outputs.nkdAgility_AzureSitesConfig) }}.yaml --logLevel info; # --minify
- name: Copy Files
shell: pwsh
run: |
Get-ChildItem -Path "${{ github.workspace }}" -Directory | Select-Object -ExpandProperty FullName
Copy-Item -Path "./staticwebapp.config.json" -Destination ./public/
Get-ChildItem -Path "./" -Filter "staticwebapp.config.*.json" | ForEach-Object {
Copy-Item -Path $_.FullName -Destination "./public/"
}
- name: Check if folder size exceeds 500MB
shell: pwsh
run: |
$folder = "./public/"
$size = (Get-ChildItem -Recurse -File -Path $folder | Measure-Object -Property Length -Sum).Sum
# Example: Perform an action if the folder is larger than 500MB (524288000 bytes)
if ($size -gt 524288000 ) {
Write-Host "Folder is larger than 500MB"
# Add additional actions or logic here
} else {
Write-Host "Folder is under 500MB"
}
- uses: actions/upload-artifact@v4
with:
name: Site
path: ./public/**/*
# Build Api
BuildApi:
name: "Build Api"
runs-on: ubuntu-latest
if: ${{ false }}
needs: [Setup]
env:
GitVersion_SemVer: ${{ needs.Setup.outputs.GitVersion_SemVer }}
GitVersion_AssemblySemVer: ${{ needs.Setup.outputs.GitVersion_AssemblySemVer }}
GitVersion_InformationalVersion: ${{ needs.Setup.outputs.GitVersion_InformationalVersion }}
steps:
- uses: actions/checkout@v4
with:
submodules: true # Fetch Hugo themes (true OR recursive)
- name: Setup DotNet Environment
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x
- name: Check if folder size exceeds 500MB
shell: pwsh
run: |
dotnet build functions/functions.csproj --configuration Release --output ./api/
- uses: actions/upload-artifact@v4
with:
name: API
path: ./api/**/*
# Offload Images
OffloadImages:
name: "Ofload Site Images to Blob Storage"
runs-on: ubuntu-latest
if: ${{ success() }}
needs: [BuildSite, Setup]
env:
GitVersion_SemVer: ${{ needs.Setup.outputs.GitVersion_SemVer }}
GitVersion_AssemblySemVer: ${{ needs.Setup.outputs.GitVersion_AssemblySemVer }}
GitVersion_InformationalVersion: ${{ needs.Setup.outputs.GitVersion_InformationalVersion }}
steps:
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: Scripts
path: ./.powershell/
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: Site
path: ./_site
- name: List folders
shell: pwsh
run: |
Get-ChildItem -Path "${{ github.workspace }}" -Directory -Force | Select-Object -ExpandProperty FullName
- name: "Sync Images to Blob Storage"
shell: pwsh
run: |
. ./.powershell/_includes/ImagesToBlobStorage.ps1
Upload-ImageFiles -LocalPath $env:LOCAL_IMAGE_PATH -BlobUrlBase $env:BLOB_STORAGE_URL -AzureSASToken $env:AZURE_BLOB_STORAGE_SAS_TOKEN
env:
LOCAL_IMAGE_PATH: "./_site/"
BLOB_STORAGE_URL: "https://nkdagilityblobs.blob.core.windows.net/$web"
AZURE_BLOB_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_BLOB_STORAGE_SAS_TOKEN }}
AZCOPY_FAIL_ON_ERROR: "true"
- name: "Rewrite Image Links"
shell: pwsh
run: |
. ./.powershell/_includes/ImagesToBlobStorage.ps1
Rewrite-ImageLinks -LocalPath $env:LOCAL_IMAGE_PATH -BlobUrl $env:BLOB_URL_BIT
env:
LOCAL_IMAGE_PATH: "./_site/"
BLOB_URL_BIT: ${{needs.Setup.outputs.nkdAgility_BLOB_URL_BIT}}
- name: "Delete Local Images"
shell: pwsh
run: |
. ./.powershell/_includes/ImagesToBlobStorage.ps1
Delete-LocalImageFiles -LocalPath $env:LOCAL_IMAGE_PATH
env:
LOCAL_IMAGE_PATH: "./_site/"
# - name: "Build NKDAgility Outputs"
# shell: pwsh
# run: ./.powershell/build/Sync-BlobStorageImages.ps1
# env:
# LOCAL_IMAGE_PATH: "./_site/"
# BLOB_URL_BIT: "/blob"
# BLOB_STORAGE_URL: "https://nkdagilityblobs.blob.core.windows.net/`$web"
# AZURE_BLOB_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_BLOB_STORAGE_SAS_TOKEN }}
# AZCOPY_FAIL_ON_ERROR: "true"
- uses: actions/upload-artifact@v4
with:
name: Site-Blobbed
path: ./_site/**/*
# Release to Docs
Publsh:
name: "Publish Site"
runs-on: ubuntu-latest
needs: [Setup, BuildSite, Spellcheck, OffloadImages]
if: ${{ success() }}
outputs:
static_web_app_url: ${{ steps.azureDeploy.outputs.static_web_app_url }}
steps:
- uses: actions/checkout@v4
with:
submodules: true # Fetch Hugo themes (true OR recursive)
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: Site-Blobbed
path: ./_site
- name: Download a single artifact
if: ${{ false }}
uses: actions/download-artifact@v4
with:
name: API
path: ./_api
- name: Merge Configuration Files
run: |
# Find all files matching the pattern in a safe way
$files = Get-ChildItem -Path "." -Recurse -Filter "staticwebapp.*.json" -ErrorAction Stop
if ($files.Count -eq 0) {
Write-Host "No files matching the pattern 'staticwebapp.*.json' were found."
exit 1
}
# Output each file's full name (for verification/debugging purposes)
$files | ForEach-Object {
Write-Host "Found file: $($_.FullName)"
}
# Paths to main and environment-specific config files
$rootConfig = "./_site/staticwebapp.config.json"
$environmentConfig = "./_site/staticwebapp.config.${{ (needs.Setup.outputs.nkdAgility_AzureSitesConfig) }}.json"
$routesConfig = "./_site/staticwebapp.config.routes.json"
# Check if both target files exist
if ((Test-Path -Path $rootConfig -ErrorAction Stop) -and (Test-Path -Path $environmentConfig -ErrorAction Stop)) {
try {
# Run jq to merge files and capture the output
$mergedContent = & jq -s 'reduce .[] as $item ({}; . * $item)' $rootConfig $environmentConfig $routesConfig
if ($mergedContent -ne "") {
# Write the merged content to the output file
$mergedContent | Set-Content -Path "./staticwebapp.config.json"
Write-Host "Merged JSON files successfully."
}
else {
Write-Host "jq command produced empty output. Check JSON structures in input files."
exit 1
}
}
catch {
Write-Host "Error merging JSON files with jq: $_"
exit 1
}
}
else {
Write-Host "One or both of the specified config files were not found:"
if (!(Test-Path -Path $rootConfig)) { Write-Host " - $rootConfig not found" }
if (!(Test-Path -Path $environmentConfig)) { Write-Host " - $environmentConfig not found" }
exit 1
}
# Verify and read the merged file content
try {
$content = Get-Content -Path "./staticwebapp.config.json" -ErrorAction Stop
Write-Host "Content of merged config file:"
Write-Output $content
}
catch {
Write-Host "Error reading the merged config file: $_"
exit 1
}
- name: "Find files"
shell: pwsh
run: |
Get-ChildItem -Path ".\" -File
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.NKDAGILITY_BOT_APP_ID }}
private-key: ${{ secrets.NKDAGILITY_BOT_CLIENTSECRET }}
- name: Build and Deploy
uses: Azure/static-web-apps-deploy@v1
id: azureDeploy
env:
VERBOSE: true
with:
repo_token: ${{ steps.app-token.outputs.token }}
action: "upload"
app_location: ./_site
api_location: ./functions
skip_app_build: true
skip_api_build: false
output_location: ""
deployment_environment: ${{ (needs.Setup.outputs.nkdAgility_AzureSitesEnvironment) }}
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
- name: "Show Summery"
if: always()
shell: pwsh
id: nkdagility-summery
run: |
$markdown = @"
## ${{needs.Setup.outputs.GitVersion_SemVer}} (${{needs.Setup.outputs.nkdAgility_Ring}})
Deployed to [${{steps.azureDeploy.outputs.static_web_app_url}}](${{steps.azureDeploy.outputs.static_web_app_url}})
"@
echo $markdown >> $Env:GITHUB_STEP_SUMMARY