1+ name : Deploy DLS UAT to IIS
2+
3+ env :
4+ # set apppool and site name from IIS
5+ AppPoolName : dlsweb-uar
6+ SiteName : ' dls-uar-uat'
7+ # set to site files. In this case, the part of the path after E:/web/
8+ SitePath : dls-uat
9+ DOTNET_INSTALL_DIR : ' ~/AppData/Local/Microsoft/dotnet'
10+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE : true
11+ on :
12+ push :
13+ branches :
14+ - ' UAT'
15+ workflow_dispatch :
16+
17+ jobs :
18+ deploy-to-uat :
19+
20+ runs-on : self-hosted
21+
22+ steps :
23+ - uses : actions/checkout@v4
24+
25+ - name : Setup .NET Core SDK 6.0
26+ uses : actions/setup-dotnet@v4
27+ with :
28+ dotnet-version : 6.0.x
29+ - name : Setup node
30+ uses : actions/setup-node@v4
31+ with :
32+ node-version : 20
33+
34+ - name : Add TechnologyEnhancedLearning as nuget package source
35+ run : |
36+ $nugetSources = dotnet nuget list source | Out-String;
37+ if(!($nugetSources -like "*TechnologyEnhancedLearning*"))
38+ {
39+ 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;
40+ }
41+
42+ - name : Dotnet publish
43+ run : |
44+ dotnet publish DigitalLearningSolutions.sln -c Release -o E:/web/${{env.SitePath}}-NEW
45+
46+ - name : Copy app_offline and web config to publish folder
47+ run : |
48+ Copy-Item E:/web/Offline/app_offline.htm E:/web/${{env.SitePath}}-NEW -Recurse -Force;
49+ Copy-Item E:/web/Offline/app_offline.htm E:/web/${{env.SitePath}} -Recurse -Force;
50+ if (Test-Path -Path E:/web/${{env.SitePath}})
51+ {
52+ Remove-Item -Path 'E:/web/${{env.SitePath}}-NEW/web.config' -Force;
53+ Copy-Item E:/web/${{env.SitePath}}/web.config E:/web/${{env.SitePath}}-NEW -Recurse -Force;
54+ }
55+ if (Test-Path -Path E:/web/${{env.SitePath}}-PREVIOUS){
56+ Remove-Item -LiteralPath 'E:/web/${{env.SitePath}}-PREVIOUS' -Force -Recurse
57+ }
58+
59+ - name : Sleep for 5 seconds
60+ run : Start-Sleep -s 5
61+
62+ - name : Switch deployment and published folders restarting apppool/webapp if necessary
63+ run : |
64+
65+ Import-Module WebAdministration;
66+ $currentRetry = 1;
67+ $backupRetry = 1;
68+ $success = $false;
69+ $backupSuccess = $false;
70+ do{
71+ echo "Attempting folder rename $currentRetry"
72+ try {
73+ Rename-Item -Path 'E:/web/${{env.SitePath}}' -NewName '${{env.SitePath}}-PREVIOUS'
74+ Rename-Item -Path 'E:/web/${{env.SitePath}}-NEW' -NewName '${{env.SitePath}}'
75+ $success = $true;
76+ }
77+ catch {
78+ echo "Rename failed due to following Catch error:`n"
79+ echo $PSItem.Exception.Message
80+ echo "`n"
81+ Start-Sleep -s 2
82+ $currentRetry = $currentRetry + 1;
83+ }
84+ finally {
85+ if ($currentRetry -ge 10) {
86+ echo "Rename keeps failing; restarting AppPool/Site as last resort`n"
87+ echo "Attempting to restart AppPool`n"
88+ do{
89+ $status = Get-WebAppPoolState -name '${{env.AppPoolName}}'
90+ if ($status.Value -eq "Stopped") {
91+ start-WebAppPool ${{env.AppPoolName}}
92+ echo "AppPool restarted`n---------`n"
93+ $backupSuccess = $true;
94+ }
95+ else {
96+ if ($backupRetry -ge 10) {
97+ throw "AppPool restart keeps failing."
98+ }
99+ echo "AppPool not stopped yet; Re-attempt #$backupRetry"
100+ Start-Sleep -s 10
101+ $backupRetry = $backupRetry + 1;
102+ }
103+ }
104+ while (!$backupSuccess -and $backupRetry -le 10)
105+ $backupRetry = 1;
106+ $backupSuccess = $false;
107+ echo "Attempting to restart Website`n"
108+ do{
109+ $status = Get-webtate -name '${{env.SiteName}}'
110+ if ($status.Value -eq "Stopped") {
111+ start-iissite ${{env.SiteName}}
112+ echo "Website restarted`n---------`n"
113+ $backupSuccess = $true;
114+ }
115+ else {
116+ if ($backupRetry -ge 10) {
117+ throw "Website restart keeps failing. Please look into Server"
118+ }
119+ echo "Website not stopped yet; Re-attempt #$backupRetry"
120+ Start-Sleep -s 10
121+ $backupRetry = $backupRetry + 1;
122+ }
123+ }
124+ while (!$backupSuccess -and $backupRetry -le 10)
125+ }
126+ }
127+ }
128+ while (!$success -and $currentRetry -le 10)
129+
130+ - name : Remove Offline and remove previous deployment folder
131+ run : |
132+ if (Test-Path -Path 'E:/web/${{env.SitePath}}-PREVIOUS')
133+ {
134+ Remove-Item -LiteralPath 'E:/web/${{env.SitePath}}-PREVIOUS' -Force -Recurse
135+ }
136+ Remove-Item 'E:/web/${{env.SitePath}}/app_offline.htm' -Force
0 commit comments