test
This commit is contained in:
105
.github/workflows/dad-mehrPublish.yaml
vendored
105
.github/workflows/dad-mehrPublish.yaml
vendored
@@ -1,68 +1,75 @@
|
||||
name: Build & Deploy .NET App to IIS
|
||||
name: Deploy ASP.NET via WebDAV
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- WorskhopClassifiedPlan
|
||||
- WorkshopClassifiedPlan # برنچ مورد نظر تو
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
# ===================== CHECKOUT CODE =====================
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
# --- 1. 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'
|
||||
# --- 2. 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
|
||||
# --- 3. Restore dependencies
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
# ===================== BUILD PROJECT =====================
|
||||
- name: Build Project
|
||||
run: dotnet build --configuration Release
|
||||
# --- 4. Build
|
||||
- name: Build
|
||||
run: dotnet build --configuration Release
|
||||
|
||||
# ===================== PUBLISH PROJECT =====================
|
||||
- name: Publish Project
|
||||
shell: powershell
|
||||
run: |
|
||||
$publishFolder = Join-Path $env:GITHUB_WORKSPACE "publish"
|
||||
Write-Host "Publishing to folder: $publishFolder"
|
||||
dotnet publish --configuration Release --output "$publishFolder" --no-build /p:EnvironmentName=Production
|
||||
# --- 5. Publish
|
||||
- name: Publish project
|
||||
run: dotnet publish --configuration Release --output ./publish --no-build
|
||||
|
||||
# ===================== 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"
|
||||
# --- 6. Deploy via WebDAV
|
||||
- name: Upload files via WebDAV
|
||||
shell: powershell
|
||||
env:
|
||||
WEBDAV_URL: ${{ secrets.WEBDAV_URL }} # مثل: https://example.com/dad-mehr/
|
||||
WEBDAV_USER: ${{ secrets.WEBDAV_USER }}
|
||||
WEBDAV_PASS: ${{ secrets.WEBDAV_PASS }}
|
||||
IIS_SITE_NAME: dad-mehr
|
||||
run: |
|
||||
$ErrorActionPreference = "Stop"
|
||||
$publishFolder = Resolve-Path "./publish"
|
||||
$siteName = "${{ env.IIS_SITE_NAME }}"
|
||||
Write-Host "📦 Publish folder: $publishFolder"
|
||||
|
||||
# --- Stop IIS site remotely (اختیاری)
|
||||
Write-Host "🛑 Stopping IIS site $siteName ..."
|
||||
try {
|
||||
Invoke-WebRequest -Uri "${{ env.WEBDAV_URL }}/appcmd_stop.txt" -Method GET -ErrorAction Stop | Out-Null
|
||||
} catch { Write-Host "⚠️ Could not stop IIS remotely, continuing..." }
|
||||
|
||||
Write-Host "Stopping IIS site $siteName ..."
|
||||
& "C:\Windows\System32\inetsrv\appcmd.exe" stop site "$siteName" | Out-Null
|
||||
# --- Upload files using WebDAV
|
||||
$creds = New-Object System.Net.NetworkCredential("${{ env.WEBDAV_USER }}", "${{ env.WEBDAV_PASS }}")
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
$webclient.Credentials = $creds
|
||||
|
||||
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
|
||||
Get-ChildItem $publishFolder -Recurse | ForEach-Object {
|
||||
if (-not $_.PSIsContainer) {
|
||||
$relativePath = $_.FullName.Substring($publishFolder.Path.Length + 1).Replace("\", "/")
|
||||
$destUrl = "${{ env.WEBDAV_URL }}$relativePath"
|
||||
Write-Host "➡️ Uploading $relativePath ..."
|
||||
$webclient.UploadFile($destUrl, "PUT", $_.FullName)
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Starting IIS site $siteName ..."
|
||||
& "C:\Windows\System32\inetsrv\appcmd.exe" start site "$siteName" | Out-Null
|
||||
|
||||
Write-Host "✅ Deployment completed successfully."
|
||||
# --- Start IIS site remotely (اختیاری)
|
||||
Write-Host "🚀 Starting IIS site $siteName ..."
|
||||
try {
|
||||
Invoke-WebRequest -Uri "${{ env.WEBDAV_URL }}/appcmd_start.txt" -Method GET -ErrorAction Stop | Out-Null
|
||||
} catch { Write-Host "⚠️ Could not start IIS remotely, continuing..." }
|
||||
|
||||
Write-Host "✅ Deployment completed successfully."
|
||||
|
||||
Reference in New Issue
Block a user