-
Notifications
You must be signed in to change notification settings - Fork 2
141 lines (130 loc) · 5.81 KB
/
build-and-deploy-dev.yml
File metadata and controls
141 lines (130 loc) · 5.81 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
name: Deploy DLS DEV to IIS
env:
# set apppool and site name from IIS
AppPoolName : dlsweb-dev
SiteName : 'dls-dev'
# set to site files. In this case, the part of the path after E:/web/
SitePath : dls-dev
DOTNET_INSTALL_DIR: '~/AppData/Local/Microsoft/dotnet'
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
on:
push:
branches:
- 'DEV'
workflow_dispatch:
jobs:
deploy-to-dev:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core SDK 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Add TechnologyEnhancedLearning as nuget package source
run: |
$nugetSources = dotnet nuget list source | Out-String;
if($nugetSources -like "*TechnologyEnhancedLearning*")
{
# Update the source (in case PAT has been updated)
dotnet nuget update source TechnologyEnhancedLearning --source https://pkgs.dev.azure.com/e-LfH/_packaging/LearningHubFeed/nuget/v3/index.json --username 'kevin.whittaker' --password ${{ secrets.AZURE_DEVOPS_PAT }} --store-password-in-clear-text
}
else
{
# Add the source
dotnet nuget add source https://pkgs.dev.azure.com/e-LfH/_packaging/LearningHubFeed/nuget/v3/index.json --name TechnologyEnhancedLearning --username 'kevin.whittaker' --password ${{ secrets.AZURE_DEVOPS_PAT }} --store-password-in-clear-text
}
- name: Dotnet publish
run: |
dotnet publish DigitalLearningSolutions.sln -c Release -o E:/web/${{env.SitePath}}-NEW
- name: Copy app_offline and web config to publish folder
run: |
Copy-Item E:/web/Offline/app_offline.htm E:/web/${{env.SitePath}}-NEW -Recurse -Force;
Copy-Item E:/web/Offline/app_offline.htm E:/web/${{env.SitePath}} -Recurse -Force;
if (Test-Path -Path E:/web/${{env.SitePath}})
{
Remove-Item -Path 'E:/web/${{env.SitePath}}-NEW/web.config' -Force;
Copy-Item E:/web/${{env.SitePath}}/web.config E:/web/${{env.SitePath}}-NEW -Recurse -Force;
}
if (Test-Path -Path E:/web/${{env.SitePath}}-PREVIOUS){
Remove-Item -LiteralPath 'E:/web/${{env.SitePath}}-PREVIOUS' -Force -Recurse
}
- name: Sleep for 5 seconds
run: Start-Sleep -s 5
- name: Switch deployment and published folders restarting apppool/webapp if necessary
run: |
Import-Module WebAdministration;
$currentRetry = 1;
$backupRetry = 1;
$success = $false;
$backupSuccess = $false;
do{
echo "Attempting folder rename $currentRetry"
try {
Rename-Item -Path 'E:/web/${{env.SitePath}}' -NewName '${{env.SitePath}}-PREVIOUS'
Rename-Item -Path 'E:/web/${{env.SitePath}}-NEW' -NewName '${{env.SitePath}}'
$success = $true;
}
catch {
echo "Rename failed due to following Catch error:`n"
echo $PSItem.Exception.Message
echo "`n"
Start-Sleep -s 2
$currentRetry = $currentRetry + 1;
}
finally {
if ($currentRetry -ge 10) {
echo "Rename keeps failing; restarting AppPool/Site as last resort`n"
echo "Attempting to restart AppPool`n"
do{
$status = Get-WebAppPoolState -name '${{env.AppPoolName}}'
if ($status.Value -eq "Stopped") {
start-WebAppPool ${{env.AppPoolName}}
echo "AppPool restarted`n---------`n"
$backupSuccess = $true;
}
else {
if ($backupRetry -ge 10) {
throw "AppPool restart keeps failing."
}
echo "AppPool not stopped yet; Re-attempt #$backupRetry"
Start-Sleep -s 10
$backupRetry = $backupRetry + 1;
}
}
while (!$backupSuccess -and $backupRetry -le 10)
$backupRetry = 1;
$backupSuccess = $false;
echo "Attempting to restart Website`n"
do{
$status = Get-WebsiteState -name '${{env.SiteName}}'
if ($status.Value -eq "Stopped") {
start-iissite ${{env.SiteName}}
echo "Website restarted`n---------`n"
$backupSuccess = $true;
}
else {
if ($backupRetry -ge 10) {
throw "Website restart keeps failing. Please look into Server"
}
echo "Website not stopped yet; Re-attempt #$backupRetry"
Start-Sleep -s 10
$backupRetry = $backupRetry + 1;
}
}
while (!$backupSuccess -and $backupRetry -le 10)
}
}
}
while (!$success -and $currentRetry -le 10)
- name: Remove Offline and remove previous deployment folder
run: |
if (Test-Path -Path 'E:/web/${{env.SitePath}}-PREVIOUS')
{
Remove-Item -LiteralPath 'E:/web/${{env.SitePath}}-PREVIOUS' -Force -Recurse
}
Remove-Item 'E:/web/${{env.SitePath}}/app_offline.htm' -Force