Skip to content

Commit a925457

Browse files
committed
🔧 (main.yaml): enhance image offloading workflow with cleanup and logging
Refactor the GitHub Actions workflow to include a cleanup step for local data files and improve logging. The job name is updated to reflect the new functionality. Introduce a new PowerShell script `CleanupDataFiles.ps1` to handle the deletion of local data files with improved error handling and logging. This change aims to streamline the workflow by ensuring local files are cleaned up after offloading, reducing storage usage, and providing better insight into the process through logging.
1 parent 7c5a4ab commit a925457

File tree

2 files changed

+52
-23
lines changed

2 files changed

+52
-23
lines changed

‎.github/workflows/main.yaml

+25-23
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ jobs:
296296

297297
# Offload Images
298298
OffloadImages:
299-
name: "Ofload Site Images to Blob Storage"
299+
name: "Cleanup and Ofload to Blob Storage"
300300
runs-on: ubuntu-latest
301301
if: ${{ success() }}
302302
needs: [BuildSite, Setup]
@@ -323,6 +323,11 @@ jobs:
323323
shell: pwsh
324324
run: |
325325
. ./.powershell/_includes/ImagesToBlobStorage.ps1
326+
if ($env:ACTIONS_STEP_DEBUG -eq "true") {
327+
$levelSwitch.MinimumLevel = 'Debug'
328+
} else {
329+
$levelSwitch.MinimumLevel = 'Information'
330+
}
326331
Upload-ImageFiles -LocalPath $env:LOCAL_IMAGE_PATH -BlobUrlBase $env:BLOB_STORAGE_URL -AzureSASToken $env:AZURE_BLOB_STORAGE_SAS_TOKEN
327332
env:
328333
LOCAL_IMAGE_PATH: "./_site/"
@@ -333,43 +338,40 @@ jobs:
333338
shell: pwsh
334339
run: |
335340
. ./.powershell/_includes/ImagesToBlobStorage.ps1
341+
if ($env:ACTIONS_STEP_DEBUG -eq "true") {
342+
$levelSwitch.MinimumLevel = 'Debug'
343+
} else {
344+
$levelSwitch.MinimumLevel = 'Information'
345+
}
336346
Rewrite-ImageLinks -LocalPath $env:LOCAL_IMAGE_PATH -BlobUrl $env:BLOB_URL_BIT
337347
env:
338348
LOCAL_IMAGE_PATH: "./_site/"
339349
BLOB_URL_BIT: ${{needs.Setup.outputs.nkdAgility_BLOB_URL_BIT}}
340-
- name: "Delete Local Images"
350+
- name: "Clean Local Images"
341351
shell: pwsh
342352
run: |
343353
. ./.powershell/_includes/ImagesToBlobStorage.ps1
354+
if ($env:ACTIONS_STEP_DEBUG -eq "true") {
355+
$levelSwitch.MinimumLevel = 'Debug'
356+
} else {
357+
$levelSwitch.MinimumLevel = 'Information'
358+
}
344359
$deletedImagesCount = Delete-LocalImageFiles -LocalPath $env:LOCAL_IMAGE_PATH
345360
346361
env:
347362
LOCAL_IMAGE_PATH: "./_site/"
348-
- name: "Delete Local Data Files"
363+
- name: "Clean Local Data Files"
349364
shell: pwsh
350365
run: |
351-
Write-InfoLog "Deleting all data file files locally..."
352-
Get-ChildItem -Path $env:LOCAL_IMAGE_PATH -Recurse -Include data.captions.*.srt, data.captions.json, data.json, data.index.classifications.json | ForEach-Object {
353-
try {
354-
$count++
355-
Remove-Item -Path $_.FullName -Force
356-
Write-DebugLog "Deleted: $($_.FullName)"
357-
}
358-
catch {
359-
Write-ErrorLog "Error deleting file $($_.FullName): $_"
360-
}
366+
. ./.powershell/_includes/CleanupDataFiles.ps1
367+
if ($env:ACTIONS_STEP_DEBUG -eq "true") {
368+
$levelSwitch.MinimumLevel = 'Debug'
369+
} else {
370+
$levelSwitch.MinimumLevel = 'Information'
361371
}
372+
$deletedCount = Delete-LocalDataFiles -LocalPath $env:LOCAL_DATA_PATH
362373
env:
363-
LOCAL_IMAGE_PATH: "./_site/resources/"
364-
# - name: "Build NKDAgility Outputs"
365-
# shell: pwsh
366-
# run: ./.powershell/build/Sync-BlobStorageImages.ps1
367-
# env:
368-
# LOCAL_IMAGE_PATH: "./_site/"
369-
# BLOB_URL_BIT: "/blob"
370-
# BLOB_STORAGE_URL: "https://nkdagilityblobs.blob.core.windows.net/`$web"
371-
# AZURE_BLOB_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_BLOB_STORAGE_SAS_TOKEN }}
372-
# AZCOPY_FAIL_ON_ERROR: "true"
374+
LOCAL_DATA_PATH: "./_site/resources/"
373375
- uses: actions/upload-artifact@v4
374376
with:
375377
name: Site-Blobbed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Helpers
2+
. ./.powershell/_includes/LoggingHelper.ps1
3+
4+
function Delete-LocalDataFiles {
5+
param (
6+
[string]$LocalPath
7+
)
8+
$count = 0
9+
try {
10+
Write-InfoLog "Deleting all data file files locally from '$LocalPath'..."
11+
Get-ChildItem -Path $env:LOCAL_IMAGE_PATH -Recurse -Include data.captions.*.srt, data.captions.json, data.json, data.index.classifications.json | ForEach-Object {
12+
try {
13+
$count++
14+
Remove-Item -Path $_.FullName -Force
15+
Write-DebugLog "Deleted: $($_.FullName)"
16+
}
17+
catch {
18+
Write-ErrorLog "Error deleting file $($_.FullName): $_"
19+
}
20+
}
21+
}
22+
catch {
23+
Write-ErrorLog "Error during file deletion: $_"
24+
}
25+
Write-InfoLog "Deleted: $count"
26+
return $count;
27+
}

0 commit comments

Comments
 (0)