name: Build and Deploy CPRNIMS on: push: branches: [ main ] jobs: build-and-deploy: runs-on: windows:host steps: - name: Checkout uses: actions/checkout@v4 - name: Clean previous publish output shell: pwsh run: | Remove-Item -Recurse -Force "c:\ci-output\webapi" -ErrorAction SilentlyContinue Remove-Item -Recurse -Force "c:\ci-output\webapps" -ErrorAction SilentlyContinue - name: Publish WebApi shell: pwsh run: dotnet publish .\CPRNIMS.WebApi\CPRNIMS.WebApi.csproj -c Release -o c:\ci-output\webapi - name: Publish WebApps shell: pwsh run: dotnet publish .\CPRNIMS.WebApps\CPRNIMS.WebApps.csproj -c Release -o c:\ci-output\webapps - name: Stop app pools shell: pwsh run: | Import-Module WebAdministration Stop-WebAppPool -Name "CPRNIMS-Api" -ErrorAction SilentlyContinue Stop-WebAppPool -Name "CPRNIMS-Web" -ErrorAction SilentlyContinue Start-Sleep -Seconds 3 - name: Deploy WebApi files shell: pwsh run: | robocopy "c:\ci-output\webapi" "C:\inetpub\cprnims-api" /MIR /R:3 /W:5 if ($LASTEXITCODE -ge 8) { throw "robocopy failed for WebApi with exit code $LASTEXITCODE" } - name: Deploy WebApps files shell: pwsh run: | robocopy "c:\ci-output\webapps" "C:\inetpub\cprnims-web" /MIR /R:3 /W:5 if ($LASTEXITCODE -ge 8) { throw "robocopy failed for WebApps with exit code $LASTEXITCODE" } - name: Start app pools shell: pwsh run: | Import-Module WebAdministration Start-WebAppPool -Name "CPRNIMS-Api" Start-WebAppPool -Name "CPRNIMS-Web" - name: Verify app pools are running shell: pwsh run: | Import-Module WebAdministration $api = Get-WebAppPoolState -Name "CPRNIMS-Api" $web = Get-WebAppPoolState -Name "CPRNIMS-Web" Write-Host "CPRNIMS-Api: $($api.Value)" Write-Host "CPRNIMS-Web: $($web.Value)" if ($api.Value -ne "Started" -or $web.Value -ne "Started") { throw "One or more app pools failed to start" }