1- name : CI/CD Deploy to Windows VM
1+ name : Manual Deploy to Windows VM
22
33on :
4- workflow_dispatch : # <-- enables manual run from GitHub UI
5- push :
6- branches :
7- - main # deploy to PROD
8- - TestDeployment # deploy to TEST ENV-PROD deployment1
4+ workflow_dispatch :
5+ inputs :
6+ environment :
7+ type : choice
8+ description : Select deployment environment
9+ options :
10+ - TEST
11+ - PROD
12+ required : true
913
1014jobs :
11- build-and -deploy :
15+ manual -deploy :
1216 runs-on : windows-latest
1317
1418 steps :
@@ -26,52 +30,41 @@ jobs:
2630 - name : Publish app
2731 run : dotnet publish -c Release -o ./publish
2832
29- # 4. Set environment variables correctly
30- - name : Set environment variables
33+ # 4. Set environment variables based on dropdown
34+ - name : Configure environment variables
3135 shell : pwsh
3236 run : |
33- if ("${{ github.ref_name }}" -eq "TestDeployment ") {
37+ if ("${{ github.event.inputs.environment }}" -eq "TEST ") {
3438 "VM_HOST=${{ secrets.TEST_VM_HOST }}" | Out-File -FilePath $env:GITHUB_ENV -Append
3539 "VM_USER=${{ secrets.TEST_VM_USER }}" | Out-File -FilePath $env:GITHUB_ENV -Append
3640 "VM_PASSWORD=${{ secrets.TEST_VM_PASSWORD }}" | Out-File -FilePath $env:GITHUB_ENV -Append
37- } else {
41+ Write-Host "Deploying to TEST environment"
42+ }
43+ else {
3844 "VM_HOST=${{ secrets.PROD_VM_HOST }}" | Out-File -FilePath $env:GITHUB_ENV -Append
3945 "VM_USER=${{ secrets.PROD_VM_USER }}" | Out-File -FilePath $env:GITHUB_ENV -Append
4046 "VM_PASSWORD=${{ secrets.PROD_VM_PASSWORD }}" | Out-File -FilePath $env:GITHUB_ENV -Append
47+ Write-Host "Deploying to PROD environment"
4148 }
4249
43- # 5. Debug check (just to confirm secrets are being set — safe version)
44- - name : Debug env
45- shell : pwsh
46- run : |
47- Write-Host "VM_HOST = $env:VM_HOST"
48- Write-Host "VM_USER = $env:VM_USER"
49- if ($env:VM_PASSWORD) {
50- Write-Host "VM_PASSWORD is set (length = $($env:VM_PASSWORD.Length))"
51- } else {
52- Write-Host "VM_PASSWORD is EMPTY!"
53- }
54-
55- # 6. Copy files to VM
56- - name : Copy files
50+ # 5. Copy files to VM
51+ - name : Copy files to VM
5752 shell : pwsh
5853 run : |
59- # Allow connecting to remote host
6054 Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value $env:VM_HOST -Force
6155 $securePassword = ConvertTo-SecureString $env:VM_PASSWORD -AsPlainText -Force
6256 $creds = New-Object System.Management.Automation.PSCredential ($env:VM_USER, $securePassword)
63- #Ignore certificate issues
6457 $opts = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
6558 $session = New-PSSession -ComputerName $env:VM_HOST -UseSSL -SessionOption $opts -Credential $creds
66- # Clear old files on VM
6759 Invoke-Command -Session $session -ScriptBlock {
68- Remove-Item "C:\inetpub\wwwroot\MigrationToolV1.0" -Recurse -Force -ErrorAction SilentlyContinue
69- New-Item -ItemType Directory -Path "C:\inetpub\wwwroot\MigrationToolV1.0" -Force
60+ Remove-Item "C:\inetpub\wwwroot\MigrationToolV1.0" -Recurse -Force -ErrorAction SilentlyContinue
61+ New-Item -ItemType Directory -Path "C:\inetpub\wwwroot\MigrationToolV1.0" -Force
7062 }
7163 Copy-Item -Path "./publish/*" -Destination "C:\inetpub\wwwroot\MigrationToolV1.0" -Recurse -ToSession $session
64+
7265 Remove-PSSession $session
7366
74- # 7 . Restart IIS
67+ # 6 . Restart IIS
7568 - name : Restart IIS
7669 shell : pwsh
7770 run : |
8073 $creds = New-Object System.Management.Automation.PSCredential ($env:VM_USER, $securePassword)
8174 $opts = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
8275 Invoke-Command -ComputerName $env:VM_HOST -UseSSL -SessionOption $opts -Credential $creds -ScriptBlock {iisreset}
83-
0 commit comments