Add: clean-destination input to optionally clear destination folder during IIS deployment

- Introduces a new input to allow cleanup of destination folder while retaining specific files and folders (`appsettings.json`, `web.config`, and `store`).
- Updates error handling for IIS site and app pool stop commands to continue execution on failure.
This commit is contained in:
2026-06-07 15:06:05 +02:00
parent 55b2e0f545
commit 2b860fbc27

View File

@@ -22,6 +22,10 @@ inputs:
description: Elenco di file da escludere dal mirroring (separati da virgola, punto e virgola o newline). description: Elenco di file da escludere dal mirroring (separati da virgola, punto e virgola o newline).
required: false required: false
default: appsettings.json default: appsettings.json
clean-destination:
description: Se 'true', elimina tutto il contenuto della cartella di destinazione (dopo aver fermato IIS) tranne appsettings.json, web.config e la cartella store.
required: false
default: 'false'
runs: runs:
using: composite using: composite
@@ -99,15 +103,27 @@ runs:
try { try {
& $appcmd stop site "/site.name:$site" & $appcmd stop site "/site.name:$site"
if ($LASTEXITCODE -ne 0) { throw "stop site fallito ($LASTEXITCODE)" } if ($LASTEXITCODE -ne 0) {
Write-Warning "stop site fallito ($LASTEXITCODE) - si prosegue comunque"
} else {
$siteStopped = $true $siteStopped = $true
}
& $appcmd stop apppool "/apppool.name:$appPool" & $appcmd stop apppool "/apppool.name:$appPool"
if ($LASTEXITCODE -ne 0) { throw "stop apppool fallito ($LASTEXITCODE)" } if ($LASTEXITCODE -ne 0) {
Write-Warning "stop apppool fallito ($LASTEXITCODE) - si prosegue comunque"
} else {
$poolStopped = $true $poolStopped = $true
}
New-Item -ItemType Directory -Force -Path $dst | Out-Null New-Item -ItemType Directory -Force -Path $dst | Out-Null
if ('${{ inputs.clean-destination }}' -eq 'true') {
$keepItems = @('appsettings.json', 'web.config', 'store')
Get-ChildItem -Path $dst | Where-Object { $_.Name -notin $keepItems } | Remove-Item -Recurse -Force
Write-Host "Pulizia destinazione completata (keep: $($keepItems -join ', '))"
}
& robocopy @robocopyArgs & robocopy @robocopyArgs
$robocopyExitCode = $LASTEXITCODE $robocopyExitCode = $LASTEXITCODE
if ($robocopyExitCode -ge 8) { if ($robocopyExitCode -ge 8) {