-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (70 loc) · 2.87 KB
/
build-deploy.yml
File metadata and controls
88 lines (70 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Build, Test, and Deploy
on:
push:
branches: ['**']
pull_request:
branches: ['**']
jobs:
build-test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Restore dependencies
run: dotnet restore src/MyBlog.slnx
- name: Build solution
run: dotnet build src/MyBlog.slnx -c Release --no-restore
- name: Run tests
run:
dotnet run --project src/MyBlog.Tests/MyBlog.Tests.csproj
deploy:
needs: build-test
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop'
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Publish application
run: dotnet publish src/MyBlog.Web/MyBlog.Web.csproj -c Release -o ./publish -r win-x86 --self-contained false
- name: Deploy via WebDeploy
shell: pwsh
env:
DEPLOY_SOURCE: ${{ github.workspace }}\publish
DEPLOY_SITE: ${{ secrets.WEBSITE_NAME }}
DEPLOY_HOST: ${{ secrets.SERVER_COMPUTER_NAME }}
DEPLOY_USER: ${{ secrets.SERVER_USERNAME }}
DEPLOY_PASSWORD: ${{ secrets.SERVER_PASSWORD }}
run: |
$msdeployPath = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
if (-not (Test-Path $msdeployPath)) {
Write-Host "Installing Web Deploy..."
choco install webdeploy -y --no-progress
}
Write-Host "Deploying to $env:DEPLOY_HOST..."
Write-Host "Note: Using AppOffline rule to prevent file-in-use errors"
$sourceArg = "-source:contentPath=$env:DEPLOY_SOURCE"
$destArg = "-dest:contentPath=$env:DEPLOY_SITE,computerName=https://$($env:DEPLOY_HOST):8172/MsDeploy.axd?site=$env:DEPLOY_SITE,userName=$env:DEPLOY_USER,password=$env:DEPLOY_PASSWORD,AuthType='Basic'"
# Key fix: Added -enableRule:AppOffline to stop the app during deployment
# This creates app_offline.htm, waits for app to stop, deploys, then removes the file
& $msdeployPath -verb:sync $sourceArg $destArg `
-allowUntrusted `
-enableRule:DoNotDeleteRule `
-enableRule:AppOffline `
-retryAttempts:3 `
-retryInterval:3000
if ($LASTEXITCODE -ne 0) {
Write-Error "Deployment failed with exit code $LASTEXITCODE"
exit 1
}
Write-Host "Deployment completed successfully!"