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