diff --git a/.github/workflows/createrelease.yml b/.github/workflows/createrelease.yml index 249ad5d..70931f6 100644 --- a/.github/workflows/createrelease.yml +++ b/.github/workflows/createrelease.yml @@ -82,75 +82,88 @@ jobs: name: callbackhandler path: C:\Temp\callbackhandler - - name: Stop and Remove Existing Windows Service - shell: cmd + - name: Stop and Remove Existing Windows Service (if applicable) + shell: pwsh run: | - set servicename=CallbackHandler + $serviceName = "CallbackHandler" + + if (Get-Service $serviceName -ErrorAction SilentlyContinue) { + Write-Host "Stopping existing service..." + Stop-Service -Name $serviceName -Force -ErrorAction SilentlyContinue + Start-Sleep -Seconds 2 + + Write-Host "Deleting existing service..." + sc.exe delete $serviceName | Out-Null + } + else { + Write-Host "Service does not exist. Skipping remove." + } - sc query %servicename% >nul 2>&1 - if %errorlevel%==0 ( - echo Stopping service... - sc stop %servicename% - echo Deleting service... - sc delete %servicename% - ) else ( - echo Service does not exist. - ) - - name: Unzip the files - shell: cmd + shell: pwsh run: | - set target=C:\txnproc\CallbackHandler + $targetPath = "C:\txnproc\CallbackHandler" + $zipFile = "C:\Temp\callbackhandler\callbackhandler.zip" - if not exist "%target%" ( - mkdir "%target%" - ) + if (!(Test-Path $targetPath)) { + Write-Host "Creating target directory..." + New-Item -ItemType Directory -Path $targetPath -Force | Out-Null + } - tar -xf C:\Temp\callbackhandler\callbackhandler.zip -C "%target%" + Write-Host "Extracting files..." + Expand-Archive -Path $zipFile -DestinationPath $targetPath -Force - # Install .NET Runtime if needed. Adjust for the actual version (example: .NET 9 Runtime) - - name: Install .NET Runtime - shell: cmd + - name: Install .NET Runtime if needed + shell: pwsh run: | - set dotnetPath=C:\Program Files\dotnet\shared\Microsoft.NETCore.App - dir "%dotnetPath%\10*" >nul 2>&1 - if errorlevel 1 ( - echo Installing .NET 10 Runtime... - curl -L -o dotnet-runtime-10.exe https://download.visualstudio.microsoft.com/download/pr/6daeb1c2-6c1d-4c34-a4ba-5f12b5e3a884/dotnet-runtime-10.0.0-win-x64.exe - dotnet-runtime-10.exe /quiet - del dotnet-runtime-10.exe - ) else ( - echo .NET 10 Runtime already installed. - ) + # Detect .NET 10 runtime + $dotnetInstalled = (& dotnet --list-runtimes 2>$null | Select-String "Microsoft\.NETCore\.App 10" | Measure-Object).Count + + if ($dotnetInstalled -eq 0) { + Write-Host "Installing .NET 10 Runtime..." + + $installerUrl = "https://download.visualstudio.microsoft.com/download/pr/6daeb1c2-6c1d-4c34-a4ba-5f12b5e3a884/dotnet-runtime-10.0.0-win-x64.exe" + $installer = "dotnet-runtime-10.exe" + + Invoke-WebRequest -Uri $installerUrl -OutFile $installer + Start-Process ".\$installer" -ArgumentList "/quiet" -Wait + Remove-Item ".\$installer" + } + else { + Write-Host ".NET 10 Runtime already installed." + } - name: Install and Start Windows Service - shell: cmd + shell: pwsh run: | - set servicename=CallbackHandler - set servicedisplay=Transaction Processing - Callback Handler - set workdir=C:\Services\CallbackHandler - set dllname=CallbackHandler.dll - set exepath=C:\Windows\System32\dotnet.exe + $serviceName = "CallbackHandler" + $serviceDisplay = "Transaction Processing - Callback Handler" + $workingDir = "C:\Services\CallbackHandler" + $dllName = "CallbackHandler.dll" + $exePath = "C:\Windows\System32\dotnet.exe" + $binPath = "`"$exePath`" `"$workingDir\$dllName`"" - set fullcmd="%exepath% \"%workdir%\%dllname%\"" + # Ensure service directory exists + if (!(Test-Path $workingDir)) { + New-Item -ItemType Directory -Path $workingDir | Out-Null + } - echo Creating service... - sc create %servicename% binPath= "%fullcmd%" start= auto + Write-Host "Creating Windows service..." + sc.exe create $serviceName binPath= "$binPath" start= auto | Out-Null - echo Setting service description... - sc description %servicename% "%servicedisplay%" + Write-Host "Setting service description..." + sc.exe description $serviceName "$serviceDisplay" | Out-Null - echo Configuring failure actions... - sc failure %servicename% actions= restart/60000/restart/60000/restart/60000 reset= 86400 + Write-Host "Configuring restart on failure..." + sc.exe failure $serviceName actions= restart/60000/restart/60000/restart/60000 reset= 86400 | Out-Null + sc.exe failureflag $serviceName 1 | Out-Null - echo Setting failure flag (required on some systems)... - sc failureflag %servicename% 1 + Write-Host "Starting service..." + Start-Service -Name $serviceName - echo Starting service... - sc start %servicename% + Write-Host "Service status:" + Get-Service -Name - echo Status: - sc query %servicename% deployproduction: runs-on: [productionserver, windows]