From 2b860fbc27c96930032686cd3ee5414ba28a99ba Mon Sep 17 00:00:00 2001 From: alberto Date: Sun, 7 Jun 2026 15:06:05 +0200 Subject: [PATCH] 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. --- deploy-iis/action.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/deploy-iis/action.yml b/deploy-iis/action.yml index 72899c6..e834fa6 100644 --- a/deploy-iis/action.yml +++ b/deploy-iis/action.yml @@ -22,6 +22,10 @@ inputs: description: Elenco di file da escludere dal mirroring (separati da virgola, punto e virgola o newline). required: false 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: using: composite @@ -99,15 +103,27 @@ runs: try { & $appcmd stop site "/site.name:$site" - if ($LASTEXITCODE -ne 0) { throw "stop site fallito ($LASTEXITCODE)" } - $siteStopped = $true + if ($LASTEXITCODE -ne 0) { + Write-Warning "stop site fallito ($LASTEXITCODE) - si prosegue comunque" + } else { + $siteStopped = $true + } & $appcmd stop apppool "/apppool.name:$appPool" - if ($LASTEXITCODE -ne 0) { throw "stop apppool fallito ($LASTEXITCODE)" } - $poolStopped = $true + if ($LASTEXITCODE -ne 0) { + Write-Warning "stop apppool fallito ($LASTEXITCODE) - si prosegue comunque" + } else { + $poolStopped = $true + } 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 $robocopyExitCode = $LASTEXITCODE if ($robocopyExitCode -ge 8) {