Skip to content

Commit fc399d4

Browse files
authored
Build: Deployment improvements
* Clean up workspace on deploy * Stop release if issues are find during deployment - - - - - - - - - - - - - - - - - - - - - - - Fix #783 Fix #717 Close #835
1 parent e5bff91 commit fc399d4

File tree

6 files changed

+185
-24
lines changed

6 files changed

+185
-24
lines changed

.deployment

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[config]
2+
command = deploy.cmd

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

deploy.cmd

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off
2+
3+
:: ----------------------
4+
:: KUDU Deployment Script
5+
:: Version: 1.0.17
6+
:: ----------------------
7+
8+
:: Prerequisites
9+
:: -------------
10+
11+
:: Verify node.js installed
12+
where node 2>nul >nul
13+
IF %ERRORLEVEL% NEQ 0 (
14+
echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
15+
goto error
16+
)
17+
18+
:: Setup
19+
:: -----
20+
21+
setlocal enabledelayedexpansion
22+
23+
SET ARTIFACTS=%~dp0%..\artifacts
24+
25+
IF NOT DEFINED DEPLOYMENT_SOURCE (
26+
SET DEPLOYMENT_SOURCE=%~dp0%.
27+
)
28+
29+
IF NOT DEFINED DEPLOYMENT_TARGET (
30+
SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
31+
)
32+
33+
IF NOT DEFINED NEXT_MANIFEST_PATH (
34+
SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest
35+
36+
IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
37+
SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
38+
)
39+
)
40+
41+
IF NOT DEFINED KUDU_SYNC_CMD (
42+
:: Install kudu sync
43+
echo Installing Kudu Sync
44+
call npm install kudusync -g --silent
45+
IF !ERRORLEVEL! NEQ 0 goto error
46+
47+
:: Locally just running "kuduSync" would also work
48+
SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd
49+
)
50+
goto Deployment
51+
52+
:: Utility Functions
53+
:: -----------------
54+
55+
:SelectNodeVersion
56+
57+
IF DEFINED KUDU_SELECT_NODE_VERSION_CMD (
58+
:: The following are done only on Windows Azure Websites environment
59+
call %KUDU_SELECT_NODE_VERSION_CMD% "%DEPLOYMENT_SOURCE%" "%DEPLOYMENT_TARGET%" "%DEPLOYMENT_TEMP%"
60+
IF !ERRORLEVEL! NEQ 0 goto error
61+
62+
IF EXIST "%DEPLOYMENT_TEMP%\__nodeVersion.tmp" (
63+
SET /p NODE_EXE=<"%DEPLOYMENT_TEMP%\__nodeVersion.tmp"
64+
IF !ERRORLEVEL! NEQ 0 goto error
65+
)
66+
67+
IF EXIST "%DEPLOYMENT_TEMP%\__npmVersion.tmp" (
68+
SET /p NPM_JS_PATH=<"%DEPLOYMENT_TEMP%\__npmVersion.tmp"
69+
IF !ERRORLEVEL! NEQ 0 goto error
70+
)
71+
72+
IF NOT DEFINED NODE_EXE (
73+
SET NODE_EXE=node
74+
)
75+
76+
SET NPM_CMD="!NODE_EXE!" "!NPM_JS_PATH!"
77+
) ELSE (
78+
SET NPM_CMD=npm
79+
SET NODE_EXE=node
80+
)
81+
82+
goto :EOF
83+
84+
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
85+
:: Deployment
86+
:: ----------
87+
88+
:Deployment
89+
echo Handling node.js deployment.
90+
91+
:: 1. KuduSync
92+
IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" (
93+
call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
94+
IF !ERRORLEVEL! NEQ 0 goto error
95+
)
96+
97+
:: 2. Select node version
98+
call :SelectNodeVersion
99+
100+
:: 3. Clean up previous deployments
101+
IF EXIST "%DEPLOYMENT_TARGET%\node_modules\" (
102+
pushd "%DEPLOYMENT_TARGET%"
103+
call :ExecuteCmd RD /S /Q "node_modules"
104+
IF !ERRORLEVEL! NEQ 0 goto error
105+
popd
106+
)
107+
108+
IF EXIST "%DEPLOYMENT_TARGET%\package-lock.json" (
109+
pushd "%DEPLOYMENT_TARGET%"
110+
call :ExecuteCmd DEL "package-lock.json"
111+
IF !ERRORLEVEL! NEQ 0 goto error
112+
popd
113+
)
114+
115+
116+
:: 4. Install npm packages
117+
IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
118+
pushd "%DEPLOYMENT_TARGET%"
119+
call :ExecuteCmd !NPM_CMD! install --production
120+
IF !ERRORLEVEL! NEQ 0 goto error
121+
popd
122+
)
123+
124+
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
125+
goto end
126+
127+
:: Execute command routine that will echo out when error
128+
:ExecuteCmd
129+
setlocal
130+
set _CMD_=%*
131+
call %_CMD_%
132+
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
133+
exit /b %ERRORLEVEL%
134+
135+
:error
136+
endlocal
137+
echo An error has occurred during web site deployment.
138+
call :exitSetErrorLevel
139+
call :exitFromFunction 2>nul
140+
141+
:exitSetErrorLevel
142+
exit /b 1
143+
144+
:exitFromFunction
145+
()
146+
147+
:end
148+
endlocal
149+
echo Finished successfully.

helpers/postinstall.js

+22-18
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22
* Post Install Script
33
* Copies a set of files from the `@hint/artwork` asset repository into this one
44
*/
5-
const shell = require('shelljs');
6-
const mkdirp = require('mkdirp');
5+
try {
6+
const shell = require('shelljs');
7+
const mkdirp = require('mkdirp');
78

8-
const baseSrcPath = 'node_modules/@hint/artwork/src/';
9-
const baseTargetPath = 'src/webhint-theme/source/images/';
9+
const baseSrcPath = 'node_modules/@hint/artwork/src/';
10+
const baseTargetPath = 'src/webhint-theme/source/images/';
1011

11-
const fileSrcAndTargets = {
12-
'other/confused/confused.svg': 'nellie-confused.svg',
13-
'other/developing/developing.svg': 'developer-nellie.svg',
14-
'other/octocat/octocat_1.svg': 'nellie-octocat.svg',
15-
'other/searching/searching.svg': 'nellie-searching.svg',
16-
'other/sunglasses/sunglasses.svg': 'nellie-customizable.svg',
17-
'other/working/working.svg': 'nellie-construction.svg'
18-
};
12+
const fileSrcAndTargets = {
13+
'other/confused/confused.svg': 'nellie-confused.svg',
14+
'other/developing/developing.svg': 'developer-nellie.svg',
15+
'other/octocat/octocat_1.svg': 'nellie-octocat.svg',
16+
'other/searching/searching.svg': 'nellie-searching.svg',
17+
'other/sunglasses/sunglasses.svg': 'nellie-customizable.svg',
18+
'other/working/working.svg': 'nellie-construction.svg'
19+
};
1920

20-
mkdirp.sync(baseTargetPath);
21+
mkdirp.sync(baseTargetPath);
2122

22-
Object.entries(fileSrcAndTargets).forEach((entry) => {
23-
const srcPath = entry[0];
24-
const targetPath = entry[1];
23+
Object.entries(fileSrcAndTargets).forEach((entry) => {
24+
const srcPath = entry[0];
25+
const targetPath = entry[1];
2526

26-
shell.cp(`${baseSrcPath}${srcPath}`, `${baseTargetPath}${targetPath}`);
27-
});
27+
shell.cp(`${baseSrcPath}${srcPath}`, `${baseTargetPath}${targetPath}`);
28+
});
29+
} catch (e) {
30+
console.log(`Couldn't copy images, probably install in "--production" mode`);
31+
}

helpers/update-site.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ prepare_site_dist_dir() {
2323
helpers
2424
dist
2525
package.json
26-
package-lock.json
2726
src
2827
web.config
2928
)
@@ -69,6 +68,13 @@ main () {
6968
prepare_site_dist_dir \
7069
&& update_website
7170

71+
if [ $? -eq 0 ]
72+
then
73+
echo "Successfully deployed website"
74+
else
75+
echo "Could not deploy site" >&2
76+
fi
77+
7278
rm -rf "$TMP_DIR"
7379
}
7480

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77
"express": "^4.17.1",
88
"globby": "^10.0.1",
99
"highlight.js": "^9.15.10",
10-
"hint": "^5.2.3",
1110
"js-yaml": "^3.13.1",
12-
"klaw": "^3.0.0",
1311
"lodash": "^4.17.15",
14-
"mkdirp": "^0.5.1",
1512
"moment": "^2.24.0",
1613
"request": "^2.88.0",
17-
"shelljs": "^0.8.3",
1814
"strip-indent": "^3.0.0",
1915
"xss-filters": "^1.2.7"
2016
},
@@ -53,14 +49,17 @@
5349
"hexo-renderer-handlebars": "^2.0.2",
5450
"hexo-server": "^1.0.0",
5551
"hexo-util": "^1.2.0",
52+
"hint": "^5.3.0",
5653
"json2yaml": "^1.1.0",
5754
"markdownlint-cli": "^0.18.0",
5855
"marked": "^0.7.0",
5956
"md-2-json": "^1.0.6",
57+
"mkdirp": "^0.5.1",
6058
"mktemp": "^1.0.0",
6159
"normalize-path": "^3.0.0",
6260
"npm-run-all": "^4.1.3",
6361
"remove-markdown": "^0.3.0",
62+
"shelljs": "^0.8.3",
6463
"stylelint": "^11.0.0",
6564
"sw-precache": "^5.2.1",
6665
"typescript": "^3.6.3",
@@ -90,7 +89,7 @@
9089
"watch": "gulp watch",
9190
"test": "npm run lint && npm run build",
9291
"test-local": "hint http://localhost:8080 --tracking=off",
93-
"test-staging": "hint https://sonarwhal-staging.azurewebsites.net --tracking=on",
92+
"test-staging": "npx hint https://sonarwhal-staging.azurewebsites.net --tracking=on",
9493
"update-site": "node helpers/update-site.js",
9594
"postinstall": "node helpers/postinstall.js"
9695
}

0 commit comments

Comments
 (0)