From 9981116caa6521af1aa40cabd2b64648d4bc2976 Mon Sep 17 00:00:00 2001 From: sadegh Farokhi <47900503+syntax24@users.noreply.github.com> Date: Tue, 4 Nov 2025 18:33:18 +0330 Subject: [PATCH] Create dad-mehrPublish --- .github/workflows/dad-mehrPublish | 67 +++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/dad-mehrPublish diff --git a/.github/workflows/dad-mehrPublish b/.github/workflows/dad-mehrPublish new file mode 100644 index 00000000..36cd3291 --- /dev/null +++ b/.github/workflows/dad-mehrPublish @@ -0,0 +1,67 @@ +name: Build & Deploy .NET App to IIS + +on: + push: + branches: + - master + +jobs: + build-and-deploy: + runs-on: windows-latest + + steps: + # ===================== CHECKOUT CODE ===================== + - name: Checkout code + uses: actions/checkout@v4 + + # ===================== SETUP .NET SDK ===================== + - name: Setup .NET SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + + # ===================== RESTORE DEPENDENCIES ===================== + - name: Restore dependencies + run: dotnet restore + + # ===================== BUILD PROJECT ===================== + - name: Build Project + run: dotnet build --configuration Release + + # ===================== PUBLISH PROJECT ===================== + - name: Publish Project + shell: powershell + run: | + $publishFolder = "$(System.DefaultWorkingDirectory)\publish" + Write-Host "Publishing to folder: $publishFolder" + dotnet publish --configuration Release --output "$publishFolder" --no-build /p:EnvironmentName=Production + + # ===================== DEPLOY TO IIS SERVER ===================== + - name: Deploy to IIS via Web Deploy + shell: powershell + env: + REMOTE_HOST: ${{ secrets.REMOTE_HOST }} + REMOTE_USER: ${{ secrets.REMOTE_USER }} + REMOTE_PASS: ${{ secrets.REMOTE_PASS }} + run: | + $publishFolder = Resolve-Path "./publish" + $siteName = "dad-mehr" + $destinationPath = "C:\inetpub\wwwroot\dad-mehr" + + Write-Host "Stopping IIS site $siteName ..." + & "C:\Windows\System32\inetsrv\appcmd.exe" stop site "$siteName" | Out-Null + + Write-Host "Deploying to $destinationPath ..." + & "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" ` + -verb:sync ` + -source:contentPath="$publishFolder" ` + -dest:contentPath="$destinationPath",computerName="https://${{ env.REMOTE_HOST }}:8172/msdeploy.axd?site=$siteName",userName="${{ env.REMOTE_USER }}",password="${{ env.REMOTE_PASS }}",authType="Basic" ` + -allowUntrusted ` + -enableRule:DoNotDeleteRule ` + -enableRule:AppOffline ` + -usechecksum + + Write-Host "Starting IIS site $siteName ..." + & "C:\Windows\System32\inetsrv\appcmd.exe" start site "$siteName" | Out-Null + + Write-Host "✅ Deployment completed successfully."