Skip to content

Commit d111601

Browse files
fix: workflows
1 parent 6572935 commit d111601

2 files changed

Lines changed: 121 additions & 74 deletions

File tree

.github/workflows/cd.yml

Lines changed: 118 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name: Deploy to Windows IIS
77
# - One for WebApp
88
# - One for AdminPanel
99
# - One for API
10-
# 3. The following secrets configured in your GitHub repository:
10+
# 3. The following environment variables configured in your GitHub repository:
1111
# - WEBAPP_APP_POOL: Name of the IIS application pool for WebApp
1212
# - WEBAPP_SITE_PATH: Physical path where WebApp will be deployed
1313
# - ADMIN_APP_POOL: Name of the IIS application pool for AdminPanel
@@ -28,16 +28,37 @@ jobs:
2828
runs-on: self-hosted # Requires a Windows self-hosted runner
2929
environment: production
3030
steps:
31-
- name: Download WebApp artifacts
32-
uses: actions/download-artifact@v3
31+
- name: Check out code
32+
uses: actions/checkout@v4
33+
34+
- name: Setup .NET 6 and .NET 8
35+
uses: actions/setup-dotnet@v4
3336
with:
34-
name: webapp
35-
path: ./webapp
37+
dotnet-version: |
38+
6.0.x
39+
8.0.x
40+
41+
- name: Publish WebApp project
42+
run: dotnet publish ./src/2-Clients/WebApp/WebApp.csproj -c Release -o ./output/WebApp
43+
44+
- name: Create WebApp.zip
45+
run: |
46+
Compress-Archive -Path ./output/WebApp/* -DestinationPath ./output/WebApp.zip
47+
48+
- name: Debug variables
49+
shell: powershell
50+
run: |
51+
Write-Host "WEBAPP_APP_POOL: '${{ vars.WEBAPP_APP_POOL }}'"
52+
Write-Host "WEBAPP_SITE_PATH: '${{ vars.WEBAPP_SITE_PATH }}'"
3653
3754
- name: Stop IIS App Pool
38-
shell: pwsh
55+
shell: powershell
3956
run: |
40-
$appPoolName = "${{ secrets.WEBAPP_APP_POOL }}"
57+
$appPoolName = "${{ vars.WEBAPP_APP_POOL }}"
58+
if ([string]::IsNullOrEmpty($appPoolName)) {
59+
Write-Error "WEBAPP_APP_POOL variable is not configured"
60+
exit 1
61+
}
4162
Write-Host "Stopping IIS App Pool: $appPoolName"
4263
Stop-WebAppPool -Name $appPoolName
4364
@@ -57,9 +78,13 @@ jobs:
5778
}
5879
5980
- name: Backup existing deployment
60-
shell: pwsh
81+
shell: powershell
6182
run: |
62-
$deployPath = "${{ secrets.WEBAPP_SITE_PATH }}"
83+
$deployPath = "${{ vars.WEBAPP_SITE_PATH }}"
84+
if ([string]::IsNullOrEmpty($deployPath)) {
85+
Write-Error "WEBAPP_SITE_PATH variable is not configured"
86+
exit 1
87+
}
6388
if (Test-Path $deployPath) {
6489
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
6590
$backupPath = "${deployPath}_backup_${timestamp}"
@@ -68,16 +93,16 @@ jobs:
6893
}
6994
7095
- name: Deploy WebApp
71-
shell: pwsh
96+
shell: powershell
7297
run: |
73-
$deployPath = "${{ secrets.WEBAPP_SITE_PATH }}"
98+
$deployPath = "${{ vars.WEBAPP_SITE_PATH }}"
7499
New-Item -ItemType Directory -Force -Path $deployPath
75-
Expand-Archive -Path ./webapp/WebApp.zip -DestinationPath $deployPath -Force
100+
Expand-Archive -Path ./output/WebApp.zip -DestinationPath $deployPath -Force
76101
77102
- name: Start IIS App Pool
78-
shell: pwsh
103+
shell: powershell
79104
run: |
80-
$appPoolName = "${{ secrets.WEBAPP_APP_POOL }}"
105+
$appPoolName = "${{ vars.WEBAPP_APP_POOL }}"
81106
Start-WebAppPool -Name $appPoolName
82107
83108
# Wait for the app pool to start (max 20 seconds)
@@ -99,16 +124,37 @@ jobs:
99124
runs-on: self-hosted
100125
environment: production
101126
steps:
102-
- name: Download AdminPanel artifacts
103-
uses: actions/download-artifact@v3
127+
- name: Check out code
128+
uses: actions/checkout@v4
129+
130+
- name: Setup .NET 6 and .NET 8
131+
uses: actions/setup-dotnet@v4
104132
with:
105-
name: adminpanel
106-
path: ./adminpanel
133+
dotnet-version: |
134+
6.0.x
135+
8.0.x
136+
137+
- name: Publish AdminPanel project
138+
run: dotnet publish ./src/2-Clients/AdminPanel/AdminPanel.csproj -c Release -o ./output/AdminPanel
139+
140+
- name: Create AdminPanel.zip
141+
run: |
142+
Compress-Archive -Path ./output/AdminPanel/* -DestinationPath ./output/AdminPanel.zip
143+
144+
- name: Debug variables
145+
shell: powershell
146+
run: |
147+
Write-Host "ADMIN_APP_POOL: '${{ vars.ADMIN_APP_POOL }}'"
148+
Write-Host "ADMIN_SITE_PATH: '${{ vars.ADMIN_SITE_PATH }}'"
107149
108150
- name: Stop IIS App Pool
109-
shell: pwsh
151+
shell: powershell
110152
run: |
111-
$appPoolName = "${{ secrets.ADMIN_APP_POOL }}"
153+
$appPoolName = "${{ vars.ADMIN_APP_POOL }}"
154+
if ([string]::IsNullOrEmpty($appPoolName)) {
155+
Write-Error "ADMIN_APP_POOL variable is not configured"
156+
exit 1
157+
}
112158
Write-Host "Stopping IIS App Pool: $appPoolName"
113159
Stop-WebAppPool -Name $appPoolName
114160
@@ -128,9 +174,13 @@ jobs:
128174
}
129175
130176
- name: Backup existing deployment
131-
shell: pwsh
177+
shell: powershell
132178
run: |
133-
$deployPath = "${{ secrets.ADMIN_SITE_PATH }}"
179+
$deployPath = "${{ vars.ADMIN_SITE_PATH }}"
180+
if ([string]::IsNullOrEmpty($deployPath)) {
181+
Write-Error "ADMIN_SITE_PATH variable is not configured"
182+
exit 1
183+
}
134184
if (Test-Path $deployPath) {
135185
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
136186
$backupPath = "${deployPath}_backup_${timestamp}"
@@ -139,16 +189,16 @@ jobs:
139189
}
140190
141191
- name: Deploy AdminPanel
142-
shell: pwsh
192+
shell: powershell
143193
run: |
144-
$deployPath = "${{ secrets.ADMIN_SITE_PATH }}"
194+
$deployPath = "${{ vars.ADMIN_SITE_PATH }}"
145195
New-Item -ItemType Directory -Force -Path $deployPath
146-
Expand-Archive -Path ./adminpanel/AdminPanel.zip -DestinationPath $deployPath -Force
196+
Expand-Archive -Path ./output/AdminPanel.zip -DestinationPath $deployPath -Force
147197
148198
- name: Start IIS App Pool
149-
shell: pwsh
199+
shell: powershell
150200
run: |
151-
$appPoolName = "${{ secrets.ADMIN_APP_POOL }}"
201+
$appPoolName = "${{ vars.ADMIN_APP_POOL }}"
152202
Start-WebAppPool -Name $appPoolName
153203
154204
# Wait for the app pool to start (max 20 seconds)
@@ -170,16 +220,37 @@ jobs:
170220
runs-on: self-hosted
171221
environment: production
172222
steps:
173-
- name: Download API artifacts
174-
uses: actions/download-artifact@v3
223+
- name: Check out code
224+
uses: actions/checkout@v4
225+
226+
- name: Setup .NET 6 and .NET 8
227+
uses: actions/setup-dotnet@v4
175228
with:
176-
name: api
177-
path: ./api
229+
dotnet-version: |
230+
6.0.x
231+
8.0.x
232+
233+
- name: Publish Api project
234+
run: dotnet publish ./src/2-Clients/Api/Api.csproj -c Release -o ./output/Api
235+
236+
- name: Create Api.zip
237+
run: |
238+
Compress-Archive -Path ./output/Api/* -DestinationPath ./output/Api.zip
239+
240+
- name: Debug variables
241+
shell: powershell
242+
run: |
243+
Write-Host "API_APP_POOL: '${{ vars.API_APP_POOL }}'"
244+
Write-Host "API_SITE_PATH: '${{ vars.API_SITE_PATH }}'"
178245
179246
- name: Stop IIS App Pool
180-
shell: pwsh
247+
shell: powershell
181248
run: |
182-
$appPoolName = "${{ secrets.API_APP_POOL }}"
249+
$appPoolName = "${{ vars.API_APP_POOL }}"
250+
if ([string]::IsNullOrEmpty($appPoolName)) {
251+
Write-Error "API_APP_POOL variable is not configured"
252+
exit 1
253+
}
183254
Write-Host "Stopping IIS App Pool: $appPoolName"
184255
Stop-WebAppPool -Name $appPoolName
185256
@@ -199,9 +270,13 @@ jobs:
199270
}
200271
201272
- name: Backup existing deployment
202-
shell: pwsh
273+
shell: powershell
203274
run: |
204-
$deployPath = "${{ secrets.API_SITE_PATH }}"
275+
$deployPath = "${{ vars.API_SITE_PATH }}"
276+
if ([string]::IsNullOrEmpty($deployPath)) {
277+
Write-Error "API_SITE_PATH variable is not configured"
278+
exit 1
279+
}
205280
if (Test-Path $deployPath) {
206281
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
207282
$backupPath = "${deployPath}_backup_${timestamp}"
@@ -210,16 +285,16 @@ jobs:
210285
}
211286
212287
- name: Deploy API
213-
shell: pwsh
288+
shell: powershell
214289
run: |
215-
$deployPath = "${{ secrets.API_SITE_PATH }}"
290+
$deployPath = "${{ vars.API_SITE_PATH }}"
216291
New-Item -ItemType Directory -Force -Path $deployPath
217-
Expand-Archive -Path ./api/Api.zip -DestinationPath $deployPath -Force
292+
Expand-Archive -Path ./output/Api.zip -DestinationPath $deployPath -Force
218293
219294
- name: Start IIS App Pool
220-
shell: pwsh
295+
shell: powershell
221296
run: |
222-
$appPoolName = "${{ secrets.API_APP_POOL }}"
297+
$appPoolName = "${{ vars.API_APP_POOL }}"
223298
Start-WebAppPool -Name $appPoolName
224299
225300
# Wait for the app pool to start (max 20 seconds)
@@ -247,7 +322,7 @@ jobs:
247322
# - Create three websites/applications in IIS
248323
# - Note down the physical paths and app pool names
249324
#
250-
# 3. Add the following secrets to your GitHub repository:
325+
# 3. Add the following environment variables to your GitHub repository:
251326
# - WEBAPP_APP_POOL: The name of your WebApp's application pool
252327
# - WEBAPP_SITE_PATH: The physical path where WebApp files should be deployed
253328
# - ADMIN_APP_POOL: The name of your AdminPanel's application pool
@@ -257,13 +332,10 @@ jobs:
257332
#
258333
# 4. The workflow will:
259334
# - Run on the self-hosted runner
335+
# - Publish the projects
336+
# - Create zip files
260337
# - Stop the appropriate app pool
261338
# - Backup existing deployment
262339
# - Deploy new files
263340
# - Start the app pool
264341
# - Monitor app pool status
265-
#
266-
# Note: This workflow assumes your build process creates zip files named:
267-
# - WebApp.zip
268-
# - AdminPanel.zip
269-
# - Api.zip

.github/workflows/ci.yml

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# If you're deploying to a different platform (Linux, Cloud, etc.),
33
# you'll need to modify this configuration accordingly.
44

5-
name: Build and publish
5+
name: Build and Test
66

77
on:
88
push:
@@ -33,30 +33,5 @@ jobs:
3333
- name: Unit Test
3434
run: ./build.ps1 RunUnitTests --skip LintCheck
3535

36-
- name: Publish WebApp project
37-
run: dotnet publish ./src/2-Clients/WebApp/WebApp.csproj -c Release -o ./output/WebApp
38-
39-
- name: Publish AdminPanel project
40-
run: dotnet publish ./src/2-Clients/AdminPanel/AdminPanel.csproj -c Release -o ./output/AdminPanel
41-
42-
- name: Publish Api project
43-
run: dotnet publish ./src/2-Clients/Api/Api.csproj -c Release -o ./output/Api
44-
45-
- name: Create WebApp.zip
46-
run: |
47-
Compress-Archive -Path ./output/WebApp/* -DestinationPath ./output/WebApp.zip
48-
49-
- name: Create AdminPanel.zip
50-
run: |
51-
Compress-Archive -Path ./output/AdminPanel/* -DestinationPath ./output/AdminPanel.zip
52-
53-
- name: Create Api.zip
54-
run: |
55-
Compress-Archive -Path ./output/Api/* -DestinationPath ./output/Api.zip
56-
57-
# Note: This workflow assumes Windows-based deployment.
58-
# For other platforms, you might need to:
59-
# 1. Change the runner (e.g., ubuntu-latest for Linux)
60-
# 2. Modify the build commands (e.g., use bash scripts instead of PowerShell)
61-
# 3. Adjust the artifact packaging (e.g., use tar for Linux)
62-
# 4. Update the deployment steps in your CD workflow
36+
# Note: This workflow focuses on building and testing.
37+
# The CD workflow will handle publishing and deployment.

0 commit comments

Comments
 (0)