Files
Actions/deploy-iis/action.yml
alberto 72fcf2f74f Aggiunge nuove azioni per il versionamento e il deploy
Sono state aggiunte azioni per estrarre la versione da un tag,
pubblicare un progetto .NET e distribuire su IIS.
Queste azioni semplificano il processo di build e deploy
per i progetti .NET, migliorando l'integrazione con Gitea Actions.
2026-05-14 21:31:39 +02:00

129 lines
3.7 KiB
YAML

name: Deploy IIS
description: Ferma sito e application pool IIS, sincronizza i file pubblicati e riavvia i servizi.
inputs:
source-path:
description: Cartella sorgente da distribuire su IIS.
required: true
destination-path:
description: Cartella di destinazione sul server IIS.
required: true
site-name:
description: Nome del sito IIS da fermare e riavviare.
required: true
app-pool-name:
description: Nome dell'application pool IIS da fermare e riavviare.
required: true
exclude-dirs:
description: Elenco di directory da escludere dal mirroring (separate da virgola, punto e virgola o newline).
required: false
default: store
exclude-files:
description: Elenco di file da escludere dal mirroring (separati da virgola, punto e virgola o newline).
required: false
default: appsettings.json
runs:
using: composite
steps:
- name: Deploy su IIS
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$appcmd = Join-Path $env:SystemRoot 'System32\inetsrv\appcmd.exe'
$src = '${{ inputs.source-path }}'
$dst = '${{ inputs.destination-path }}'
$site = '${{ inputs.site-name }}'
$appPool = '${{ inputs.app-pool-name }}'
function Split-InputList {
param([string]$Value)
if ([string]::IsNullOrWhiteSpace($Value)) {
return @()
}
return @(
$Value -split '[,;\r\n]+'
| ForEach-Object { $_.Trim() }
| Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
)
}
if (-not (Test-Path -LiteralPath $appcmd)) {
throw "appcmd.exe non trovato: $appcmd"
}
foreach ($entry in @{
'source-path' = $src
'destination-path' = $dst
'site-name' = $site
'app-pool-name' = $appPool
}.GetEnumerator()) {
if ([string]::IsNullOrWhiteSpace($entry.Value)) {
throw "Input '$($entry.Key)' mancante."
}
}
if (-not (Test-Path -LiteralPath $src)) {
throw "Cartella sorgente non trovata: $src"
}
$excludeDirs = Split-InputList '${{ inputs.exclude-dirs }}'
$excludeFiles = Split-InputList '${{ inputs.exclude-files }}'
$robocopyArgs = @(
$src
$dst
'/MIR'
'/R:2'
'/W:1'
'/NFL'
'/NDL'
'/NP'
)
if ($excludeDirs.Count -gt 0) {
$robocopyArgs += '/XD'
$robocopyArgs += $excludeDirs
}
if ($excludeFiles.Count -gt 0) {
$robocopyArgs += '/XF'
$robocopyArgs += $excludeFiles
}
$siteStopped = $false
$poolStopped = $false
try {
& $appcmd stop site "/site.name:$site"
if ($LASTEXITCODE -ne 0) { throw "stop site fallito ($LASTEXITCODE)" }
$siteStopped = $true
& $appcmd stop apppool "/apppool.name:$appPool"
if ($LASTEXITCODE -ne 0) { throw "stop apppool fallito ($LASTEXITCODE)" }
$poolStopped = $true
New-Item -ItemType Directory -Force -Path $dst | Out-Null
& robocopy @robocopyArgs
$robocopyExitCode = $LASTEXITCODE
if ($robocopyExitCode -ge 8) {
throw "robocopy fallito ($robocopyExitCode)"
}
}
finally {
if ($poolStopped) {
& $appcmd start apppool "/apppool.name:$appPool"
if ($LASTEXITCODE -ne 0) { throw "start apppool fallito ($LASTEXITCODE)" }
}
if ($siteStopped) {
& $appcmd start site "/site.name:$site"
if ($LASTEXITCODE -ne 0) { throw "start site fallito ($LASTEXITCODE)" }
}
}