1
0
Fork 0

Deploy documentation website on push to master

This commit is contained in:
Pixelastic 2018-08-27 20:01:56 +02:00
parent 0ef3621801
commit 36d176514d
10 changed files with 15331 additions and 14 deletions

2
.gitignore vendored
View file

@ -6,6 +6,4 @@ dist/
npm-debug.log*
yarn-error.log
dist-es5-module/
yarn.lock
tmp
docs/build/

View file

@ -57,7 +57,9 @@ them with auto-reload.
- `yarn docs:build` will build the docs website in `./docs/dist`.
- `yarn docs:serve` will do the same, but with live-reload enabled
- `yarn docs:deploy` will deploy the doc website
- `yarn docs:deploy` will deploy the doc website manually
Refer to `./docs/README.md` for more information
## Release

View file

@ -24,12 +24,18 @@ live-reload.
### Deploying the website
You can deploy the website by running `yarn run deploy` in this directory or
`yarn run docs:deploy` at the repository root.
You can deploy the website manually by running `yarn run deploy` in this
directory or `yarn run docs:deploy` at the repository root.
This will build the website and then commit the content of the `./dist` folder
to the `gh-pages` branch and push it to GitHub.
Netlify is configured to listen to all commits on `master` and
run `netlify-master` (see`netlify.toml` in the root). This script will check if
any changes were made in the `./docs` subfolder. If no changes were made, it
will finish, otherwise it will build the website and push it to
`gh-pages`.
## Internals
The documentation generation is not using any existing static websites

View file

@ -9,7 +9,7 @@
"lint:css": "./scripts/lint-css",
"lint:md": "./scripts/lint-md",
"lint:md:fix": "./scripts/lint-md-fix",
"prepush": "./scripts/prepush",
"prepush": "yarn lint",
"serve": "babel-node ./scripts/serve.js"
},
"devDependencies": {
@ -34,6 +34,7 @@
"eslint-plugin-prettier": "2.6.2",
"front-matter": "2.3.0",
"fs-extra": "7.0.0",
"gh-pages": "1.2.0",
"glob": "7.1.2",
"husky": "0.14.3",
"inquirer": "6.2.0",
@ -43,9 +44,6 @@
"markdown-it-anchor": "5.0.2",
"markdown-it-highlightjs": "3.0.0",
"normalize.css": "8.0.0",
"p-all": "1.0.0",
"p-each-series": "1.0.0",
"p-map": "1.2.0",
"pify": "3.0.0",
"postcss": "6.0.23",
"postcss-clean": "1.1.0",
@ -53,7 +51,9 @@
"postcss-nested": "3.0.0",
"prettier": "1.14.2",
"pug": "2.0.3",
"puppeteer": "1.7.0",
"p-all": "1.0.0",
"p-each-series": "1.0.0",
"p-map": "1.2.0",
"remark-cli": "5.0.0",
"remark-frontmatter": "1.2.1",
"remark-lint-no-trailing-spaces": "2.0.0",

View file

@ -1,2 +0,0 @@
#!/usr/bin/env sh
yarn lint

7090
docs/yarn.lock Normal file

File diff suppressed because it is too large Load diff

10
netlify.toml Normal file
View file

@ -0,0 +1,10 @@
[Settings]
[build]
[build.environment]
NODE_ENV = "development"
YARN_VERSION = "1.9.4"
# Deploy documentation website on each commit on master
[context.master]
command = "./scripts/netlify-master"

View file

@ -10,7 +10,6 @@
"docs:build": "cd ./docs && yarn build",
"docs:serve": "cd ./docs && yarn serve",
"docs:deploy": "cd ./docs && yarn deploy",
"doctoc": "doctoc --maxlevel 3 README.md CONTRIBUTING.md",
"lint": "./scripts/lint",
"release": "./scripts/release",
"release:beta": "./scripts/release-beta",
@ -49,7 +48,6 @@
"babel-preset-stage-3": "6.24.1",
"conventional-changelog-cli": "2.0.5",
"cssnano": "4.1.0",
"doctoc": "1.3.1",
"eslint": "5.4.0",
"eslint-config-algolia": "13.1.0",
"eslint-config-prettier": "2.10.0",

54
scripts/netlify-master Executable file
View file

@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -e
# This file is run on Netlify for every new push on master (check netlify.toml
# for details)
# ===== STOP IF NO ./DOCS CHANGES
# We compare the date of last modification of the ./docs folder with the date of
# last deploy. If we have recent changes, we deploy, otherwise we skip
DOCS_UPDATE_LOCAL=$(git log -1 --pretty="format:%ct" ./docs)
DOCS_UPDATE_PRODUCTION=$(curl -s https://raw.githubusercontent.com/algolia/docsearch/gh-pages/last_update)
# This is the very first deploy, it should always go through
if ! [[ $DOCS_UPDATE_PRODUCTION =~ ^[0-9]*$ ]]; then
DOCS_UPDATE_PRODUCTION=0
fi
# Check if the local changes are fresher than the last push
TIME_DIFFERENCE=$((DOCS_UPDATE_LOCAL - DOCS_UPDATE_PRODUCTION));
if [[ $TIME_DIFFERENCE -le 0 ]]; then
echo "Documentation deployment is skipped: no new content";
exit 0
fi
# ===== BUILD
cd ./docs
yarn build
# ==== DEPLOY TO GH-PAGES
# Configuring the user making the push
git config --global user.email "algobot@users.noreply.github.com"
git config --global user.name "algobot"
# Adding the remote:
# Note: We need to wrap it in a conditional to not re-add a remote that already
# exists (can happen with the way Netlify caches builds). Attempting to add
# a remote that already exists will generate an error.
if ! git config remote.origin.url > /dev/null; then
git remote add origin git@github.com:algolia/docsearch.git
fi
# Configure the ssh private key
# The public key is configured as part of GitHub Deploy keys.
# The private key is stored in an environment variable (with underscore instead
# of newlines as Netlify does not allow for new lines). We convert it and store
# it in a file, then tell git to use it
mkdir -p ~/.ssh
echo -e "${GITHUB_DEPLOY_KEY_PRIVATE//_/\\n}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no"
# We add a file that contains the last updated date, to use on the next deploy
echo "$DOCS_UPDATE_LOCAL" > ./dist/last_update
yarn gh-pages -d dist

8161
yarn.lock Normal file

File diff suppressed because it is too large Load diff