Skip to content

Commit cd1add7

Browse files
molantalrra
authored andcommitted
Fix: Use webhint before deploying to production
Fix #51 Close #487
1 parent 49a31bd commit cd1add7

File tree

7 files changed

+4977
-45
lines changed

7 files changed

+4977
-45
lines changed

.hintrc

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"extends": [
3+
"web-recommended"
4+
],
5+
"ignoredUrls": [
6+
{
7+
"domain": "^https?://cdn\\.jsdelivr\\.net/.*",
8+
"hints": [
9+
"*"
10+
]
11+
},
12+
{
13+
"domain": "^https?://.*\\.google-analytics\\.com/.*",
14+
"hints": [
15+
"*"
16+
]
17+
},
18+
{
19+
"domain": "^https?://fonts\\.googleapis\\.com/.*",
20+
"hints": [
21+
"*"
22+
]
23+
}
24+
],
25+
"hints": {
26+
"html-checker": "off"
27+
}
28+
}

.travis.yml

+18-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,30 @@
33
#
44
# https://docs.travis-ci.com
55

6-
after_success:
7-
- npm run travis-update
8-
96
env:
107
global:
118

129
# DOC_SEARCH_ID & DOC_SEARCH_KEY
1310
- secure: "Jjq86BkxLcYQcw8V12p01Jd+X9pZD4aZL8ILzGFp0FBEqJRtgpIJe57Z5zB/gkZxAfrgZxKW3SaFMy8OizGPnA7xO0AYyH/KDv3P/xGlGbV8VtAHLvrA/WI2NNZSQf8c+UEBqK4ZiXrbkI62xlEED6WxRrqXSBGhYKZhXI7EsCSxdMW6+19IeiolNSpKL3CExglS7p7UzGSE+BIRZWmo5ya4bMkahR2Q5yoY3wAc2FKb4KWCH55bF/0crRDbCAw5Nvp1YVGT2EnHuBHck0Z5Hwy+/5LUOYB3uLNXUqfsRRkIQA653/01l18BNCQfO2mtFeNKjah51+BoZkMUAo4+1ebWTt0R0l5M3qKfrjUDxD8FJNYLMx20Vx8xx1LRrQzwXagB7J8OZ8LciYcbJWH86nQnSI9AOAQgc7f07CM/alTq2b8sPY1rgf9l8rx2Sj+jgPsFOlNOrYxQnQSLtiEj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gmBx7keYnUaWVucX2gHsEZCMo0cPaUJxHAWhEekPG2iswzbvZhdWHdQdH9+GTUtN5r6oCL0MNDMHT04C2IgWHR8DFlT9kTDz4eojc3pjoU+pciWDRXC8NATM6orJrG7cAII9/queBlTVfa+BTtyHbL8jiHHQmEDnv3TwE/DIYY3Nwf2Zaw9YL/nPlKtEqQKl49dE51gYfT/BhzO8c3nRjOH6Vwep289H5IIQhfyTCilzV6wnFDu06iiINDpveP350LMQKNbPNHySJVBFdbSS88sAjorFbfpX0lqUFB07i/sjbQkZwwmP+U="
17+
18+
# GIT_USER_EMAIL, GIT_USER_NAME, GIT_PASSWORD
19+
- secure: "OINn8LhTK6hTngwlxjum3k6Zuh08vfqSFbVhkNZnE9VlSZ+B3my1mmVSQYYBfo3lZXfEtiFuweVOIR/1Eh6FUK5r5+dGrNdg61I8eOhY4iVpNmaePTp6CdcHduVWAYolJEcbb//45FlLZAbEDXPVClg1By2fgOqg6RMHxIOZwSb4SFKCq4EXqjS3LNYhxUva+pUGhxxp1fEcX/vBz38HYar+JpSqZ/WO19RPaYOdXBfPCCLIgEYvtrEylupRVKybqL9rCzY1dZ9lipdrtm4Whs141RqHj7yxg1iyA+Qa9T9NqTOilVl349W9Bf24mt5p58iP0h3zc3HWK197Kwf8EJsSat5CnzXRRGM636FrrxlYol6QKyEa7IDolvJVryKT5mOE/2rwdPkdfteXm3IK3h49hniXR72eNO5oNFaNsrKp6w+LM4mu4q3XxXdloJr+26wc1BptRRU4XJrg4Qvdlx19ALkbu93mo1eW+aabKJeAnMj53LV7h4JSQqITP/DQWJRaKu9Zu4JHQHsZ4VnoyOqvf+OojO4fpWs/2YnyxIeOMYDB5EScBPljWPF2BDQFwqaJDN5DZegLWXx6XssZ2ObryfHPUNAlZ0spU5Jb0+O84LVvgf0RIgwIAChZww/I27/EFdcwt9woVdvRi/ViinydbZHa9vyUA9imG2NSRMo="
20+
21+
script:
22+
- npm test
23+
24+
after_success:
25+
- npm run travis-update
26+
- npm run test-staging
27+
28+
after_script:
29+
- npm run swap
1730

1831
language: node_js
1932

.travis/swap.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Add the Azue CLI 2.0 source and install
2+
# https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest
3+
AZ_REPO=$(lsb_release -cs)
4+
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | \
5+
sudo tee /etc/apt/sources.list.d/azure-cli.list
6+
7+
curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
8+
9+
sudo apt-get install apt-transport-https
10+
sudo apt-get update && sudo apt-get install azure-cli
11+
12+
# Use a scoped service principal to access Azure
13+
az login --service-principal -u $AZURE_SERVICE_PRINCIPAL -p $AZURE_SERVICE_PRINCIPAL_PASSWORD --tenant $AZURE_TENANT
14+
15+
# Swap slots, default is production
16+
az webapp deployment slot swap -g sonarwhal -n sonarwhal --slot staging
17+
18+
# Run the DocSearch scraper only is this is a cron job.
19+
# https://docs.travis-ci.com/user/cron-jobs/
20+
21+
if [ "$TRAVIS_EVENT_TYPE" == "cron" ]; then
22+
npm run travis-docsearch-scraper
23+
fi

.travis/update-site.sh

+27-33
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,31 @@ prepare_site_dist_dir() {
2020
done
2121
}
2222

23-
run_docsearch_scraper() {
24-
25-
# Run the DocSearch scraper only is this is a cron job.
26-
# https://docs.travis-ci.com/user/cron-jobs/
27-
28-
if [ "$TRAVIS_EVENT_TYPE" == "cron" ]; then
29-
npm run travis-docsearch-scraper
30-
fi
31-
23+
update_website() {
24+
# Move to temp folder
25+
cd "$TMP_DIR"
26+
27+
git config --global user.email "$GIT_USER_EMAIL" \
28+
&& git config --global user.name "$GIT_USER_NAME" \
29+
&& git init \
30+
&& git add -A \
31+
&& git commit --message "Hey server, this content is for you! [skip ci]" \
32+
&& git push --quiet --force --set-upstream "https://$GIT_USER_NAME:$GIT_PASSWORD@sonarwhal-staging.scm.azurewebsites.net:443/sonarwhal.git" master
3233
}
3334

34-
set_up_ssh() {
35-
$(npm bin)/set-up-ssh \
36-
--key "$encrypted_1b2b8f95b98b_key" \
37-
--iv "$encrypted_1b2b8f95b98b_iv" \
38-
--path-encrypted-key ".travis/github-deploy-key.enc"
39-
}
35+
remove_sensitive_information() {
4036

41-
update_website_branch() {
37+
declare -r CENSOR_TEXT="[secure]";
4238

43-
# Automatically update the content from the `website` branch.
44-
#
45-
# Note: The SSH key is stored on Travis CI, but will need to be
46-
# added once the project is open sourced.
47-
#
48-
# https://docs.travis-ci.com/user/private-dependencies/
39+
while IFS="" read -r line; do
4940

41+
for text in "$@"; do
42+
line="${line//${text}/$CENSOR_TEXT}"
43+
done
5044

51-
"$(npm bin)/update-branch" --commands "echo" \
52-
--commit-message "Hey server, this content is for you! [skip ci]" \
53-
--directory "$TMP_DIR" \
54-
--distribution-branch "website" \
55-
--source-branch "master"
45+
printf "%s\n" "$line"
46+
47+
done
5648

5749
}
5850

@@ -71,12 +63,14 @@ fi
7163

7264
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7365

74-
declare -r TMP_DIR="$(mktemp -d XXXXX)"
66+
main () {
67+
declare -r TMP_DIR="$(mktemp -d XXXXX)"
7568

76-
run_docsearch_scraper
69+
prepare_site_dist_dir \
70+
&& update_website
7771

78-
set_up_ssh \
79-
&& prepare_site_dist_dir \
80-
&& update_website_branch
72+
rm -rf "$TMP_DIR"
73+
}
8174

82-
rm -rf "$TMP_DIR"
75+
main "$@" \
76+
&> >(remove_sensitive_information "$GH_USER_EMAIL" "$GIT_USER_NAME" "$GIT_PASSWORD")

architecture/server.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ The deployment process is fully automated:
6363

6464
1. `master` branch build is triggered in [Travis][travis] (e.g. by code
6565
or documentation change).
66-
1. build passes and executes [`.travis/update-site.sh`][site-update].
67-
This script will copy the required files for the deployment to the
68-
`website` branch.
69-
1. Azure App Service is configured for [continuous deployment][cd] from
70-
a GitHub source. Once it receives the notification the content is
71-
automatically downloaded and published.
66+
1. build passes and executes `.travis/update-site.sh`.
67+
This script will copy the required files for the deployment and push
68+
them into a local Git on Azure in the staging environment.
69+
1. The staging environment will be tested with `webhint` to make sure
70+
everything is alrigh. If so, the code will get into production via
71+
`.travis/swap.sh`.
7272

7373
## Production configuration
7474

@@ -159,9 +159,9 @@ IIS manages the custom error page via the following entries in `web.config`:
159159
[hexo]: https://hexo.io
160160
[letsencrypt install]: https://github.com/sjkp/letsencrypt-siteextension/wiki/How-to-install
161161
[letsencrypt]: https://letsencrypt.org
162-
[site-update]: https://github.com/webhintio/webhint.io/blob/272a59c150a6462d4047bdc63019c339fcfaead0/.travis/update-site.sh
163162
[siteextenstion]: https://github.com/sjkp/letsencrypt-siteextension
164163
[webhint]: https://webhint.io
165164
[webhint-repo]: https://github.com/webhintio/hint
166165
[travis]: https://travis-ci.org/webhint/webhint.io
167166
[trigger-update]: https://github.com/webhintio/hint/blob/0cfb1bb49c847eb4d5ed54691dbb88cb796694bf/.travis/trigger-site-update.sh
167+

0 commit comments

Comments
 (0)