-
Notifications
You must be signed in to change notification settings - Fork 0
331 lines (274 loc) · 12.1 KB
/
Copy pathbuild-deploy.yml
File metadata and controls
331 lines (274 loc) · 12.1 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
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@v7
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
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 unit tests
run: dotnet run --project src/MyBlog.Tests/MyBlog.Tests.csproj
e2e-tests:
runs-on: ubuntu-latest
needs: build-test
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
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: Install Playwright browsers
run: |
pwsh src/MyBlog.E2E/bin/Release/net10.0/playwright.ps1 install chromium --with-deps
- name: Start MyBlog application
run: |
dotnet run --project src/MyBlog.Web/MyBlog.Web.csproj -c Release --no-build --no-launch-profile > app.log 2>&1 &
echo $! > app.pid
env:
ASPNETCORE_URLS: http://localhost:5000
ASPNETCORE_ENVIRONMENT: Development
Authentication__DefaultAdminPassword: ChangeMe123!
- name: Wait for application to be ready
run: |
echo "Waiting for application to start..."
for i in {1..60}; do
if curl -sf http://localhost:5000/ > /dev/null 2>&1; then
echo "Application is ready!"
curl -v http://localhost:5000/ 2>&1 | head -20
break
fi
echo "Attempt $i/60: Application not ready yet..."
sleep 2
if [ $i -eq 60 ]; then
echo "Application failed to start within timeout"
echo "Application logs:"
cat app.log || echo "No logs available"
exit 1
fi
done
- name: Run E2E tests
run: dotnet run --project src/MyBlog.E2E/MyBlog.E2E.csproj -c Release --no-build
env:
MYBLOG_BASE_URL: http://localhost:5000
PLAYWRIGHT_HEADLESS: true
- name: Stop application
if: always()
run: |
if [ -f app.pid ]; then
kill $(cat app.pid) || true
fi
- name: Show application logs on failure
if: failure()
run: |
echo "=== Application Logs ==="
cat app.log || echo "No logs available"
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
with:
name: e2e-test-results
path: |
src/MyBlog.E2E/TestResults/
test-results/
app.log
retention-days: 7
deploy:
needs: [build-test, e2e-tests]
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@v7
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
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: Inject OTLP configuration into web.config
shell: pwsh
env:
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }}
OTLP_ENDPOINT: ${{ secrets.OTLP_ENDPOINT }}
run: |
$webConfigPath = "./publish/web.config"
if (-not (Test-Path $webConfigPath)) {
Write-Host "web.config not found at $webConfigPath — skipping OTLP injection"
exit 0
}
Write-Host "=== Current web.config ==="
Get-Content $webConfigPath
Write-Host "==========================="
[xml]$xml = Get-Content $webConfigPath
# Navigate to the aspNetCore element using XPath to handle any structure
$aspNetCore = $xml.SelectSingleNode('//aspNetCore')
if (-not $aspNetCore) {
Write-Host "No aspNetCore element found in web.config — skipping OTLP injection"
exit 0
}
# Create or get environmentVariables element
$envVars = $aspNetCore.SelectSingleNode('environmentVariables')
if (-not $envVars) {
$envVars = $xml.CreateElement('environmentVariables')
$aspNetCore.AppendChild($envVars) | Out-Null
}
# Add OTLP API key if configured
if (-not [string]::IsNullOrWhiteSpace($env:HONEYCOMB_API_KEY)) {
$envVar = $xml.CreateElement('environmentVariable')
$envVar.SetAttribute('name', 'Otlp__ApiKey')
$envVar.SetAttribute('value', $env:HONEYCOMB_API_KEY)
$envVars.AppendChild($envVar) | Out-Null
Write-Host "Added Otlp__ApiKey to web.config"
} else {
Write-Host "No HONEYCOMB_API_KEY secret configured — OTLP export will be disabled"
}
# Add OTLP endpoint (default to Honeycomb US if secret not specified)
$endpoint = if (-not [string]::IsNullOrWhiteSpace($env:OTLP_ENDPOINT)) { $env:OTLP_ENDPOINT } else { "https://api.honeycomb.io" }
$envVar2 = $xml.CreateElement('environmentVariable')
$envVar2.SetAttribute('name', 'Otlp__Endpoint')
$envVar2.SetAttribute('value', $endpoint)
$envVars.AppendChild($envVar2) | Out-Null
Write-Host "Added Otlp__Endpoint=$endpoint to web.config"
$xml.Save((Resolve-Path $webConfigPath).Path)
Write-Host "=== Updated web.config ==="
Get-Content $webConfigPath
Write-Host "==========================="
- 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'"
& $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!"
deploynice:
needs: [build-test, e2e-tests]
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@v7
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
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: Inject OTLP configuration into web.config
shell: pwsh
env:
HONEYCOMB_API_KEY: ${{ secrets.NICE_HONEYCOMB_API_KEY }}
OTLP_ENDPOINT: ${{ secrets.NICE_OTLP_ENDPOINT }}
run: |
$webConfigPath = "./publish/web.config"
if (-not (Test-Path $webConfigPath)) {
Write-Host "web.config not found at $webConfigPath — skipping OTLP injection"
exit 0
}
Write-Host "=== Current web.config ==="
Get-Content $webConfigPath
Write-Host "==========================="
[xml]$xml = Get-Content $webConfigPath
# Navigate to the aspNetCore element using XPath to handle any structure
$aspNetCore = $xml.SelectSingleNode('//aspNetCore')
if (-not $aspNetCore) {
Write-Host "No aspNetCore element found in web.config — skipping OTLP injection"
exit 0
}
# Create or get environmentVariables element
$envVars = $aspNetCore.SelectSingleNode('environmentVariables')
if (-not $envVars) {
$envVars = $xml.CreateElement('environmentVariables')
$aspNetCore.AppendChild($envVars) | Out-Null
}
# Add OTLP API key if configured
if (-not [string]::IsNullOrWhiteSpace($env:HONEYCOMB_API_KEY)) {
$envVar = $xml.CreateElement('environmentVariable')
$envVar.SetAttribute('name', 'Otlp__ApiKey')
$envVar.SetAttribute('value', $env:HONEYCOMB_API_KEY)
$envVars.AppendChild($envVar) | Out-Null
Write-Host "Added Otlp__ApiKey to web.config"
} else {
Write-Host "No NICE_HONEYCOMB_API_KEY secret configured — OTLP export will be disabled"
}
# Add OTLP endpoint (default to Honeycomb US if secret not specified)
$endpoint = if (-not [string]::IsNullOrWhiteSpace($env:OTLP_ENDPOINT)) { $env:OTLP_ENDPOINT } else { "https://api.honeycomb.io" }
$envVar2 = $xml.CreateElement('environmentVariable')
$envVar2.SetAttribute('name', 'Otlp__Endpoint')
$envVar2.SetAttribute('value', $endpoint)
$envVars.AppendChild($envVar2) | Out-Null
Write-Host "Added Otlp__Endpoint=$endpoint to web.config"
$xml.Save((Resolve-Path $webConfigPath).Path)
Write-Host "=== Updated web.config ==="
Get-Content $webConfigPath
Write-Host "==========================="
- name: Deploy via WebDeploy
shell: pwsh
env:
NICE_DEPLOY_SOURCE: ${{ github.workspace }}\publish
NICE_DEPLOY_SITE: ${{ secrets.NICE_WEBSITE_NAME }}
NICE_DEPLOY_HOST: ${{ secrets.NICE_SERVER_COMPUTER_NAME }}
NICE_DEPLOY_USER: ${{ secrets.NICE_SERVER_USERNAME }}
NICE_DEPLOY_PASSWORD: ${{ secrets.NICE_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:NICE_DEPLOY_HOST..."
Write-Host "Note: Using AppOffline rule to prevent file-in-use errors"
$sourceArg = "-source:contentPath=$env:NICE_DEPLOY_SOURCE"
$destArg = "-dest:contentPath=$env:NICE_DEPLOY_SITE,computerName=https://$($env:NICE_DEPLOY_HOST):8172/MsDeploy.axd?site=$env:NICE_DEPLOY_SITE,userName=$env:NICE_DEPLOY_USER,password=$env:NICE_DEPLOY_PASSWORD,AuthType='Basic'"
& $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!"