Skip to content

CICD-Dep

CICD-Dep #9

Workflow file for this run

name: CI/CD Deploy to Windows VM
on:
push:
branches:
- main # deploy to PROD
- TestDeployment # deploy to TEST ENV V1.0
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
# 1. Checkout
- name: Checkout
uses: actions/checkout@v4
# 2. Setup .NET
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
# 3. Build & publish
- name: Publish app
run: dotnet publish -c Release -o ./publish
# 4. Set environment variables correctly
- name: Set environment variables
shell: pwsh
run: |
if ("${{ github.ref_name }}" -eq "TestDeployment") {
"VM_HOST=${{ secrets.TEST_VM_HOST }}" | Out-File -FilePath $env:GITHUB_ENV -Append
"VM_USER=${{ secrets.TEST_VM_USER }}" | Out-File -FilePath $env:GITHUB_ENV -Append
"VM_PASSWORD=${{ secrets.TEST_VM_PASSWORD }}" | Out-File -FilePath $env:GITHUB_ENV -Append
} else {
"VM_HOST=${{ secrets.PROD_VM_HOST }}" | Out-File -FilePath $env:GITHUB_ENV -Append
"VM_USER=${{ secrets.PROD_VM_USER }}" | Out-File -FilePath $env:GITHUB_ENV -Append
"VM_PASSWORD=${{ secrets.PROD_VM_PASSWORD }}" | Out-File -FilePath $env:GITHUB_ENV -Append
}
# 5. Debug check (just to confirm secrets are being set — safe version)
- name: Debug env
shell: pwsh
run: |
Write-Host "VM_HOST = $env:VM_HOST"
Write-Host "VM_USER = $env:VM_USER"
if ($env:VM_PASSWORD) {
Write-Host "VM_PASSWORD is set (length = $($env:VM_PASSWORD.Length))"
} else {
Write-Host "VM_PASSWORD is EMPTY!"
}
# 6. Copy files to VM

Check failure on line 54 in .github/workflows/deploy.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/deploy.yml

Invalid workflow file

You have an error in your yaml syntax on line 54
- name: Copy files
shell: pwsh
run: |
$securePassword = ConvertTo-SecureString $env:VM_PASSWORD -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($env:VM_USER, $securePassword)
$session = New-PSSession -ComputerName $env:VM_HOST -UseSSL -Credential $creds
Copy-Item -Path "./publish/*" -Destination "C:\inetpub\wwwroot\MigrationToolV1.0" -Recurse -ToSession $session
Remove-PSSession $session
# 7. Restart IIS
- name: Restart IIS
shell: pwsh
run: |
$securePassword = ConvertTo-SecureString $env:VM_PASSWORD -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($env:VM_USER, $securePassword)
Invoke-Command -ComputerName $env:VM_HOST -Credential $creds -ScriptBlock { iisreset }