docs(deploy-preview): Re-enable deploy previews for the doc
This re-enable deploy-previews through Netlify. It will check if changes where made to the ./docs folder and build + deploy the preview if so. Otherwise, it will deploy a dummy preview. This also removes the netlify script to deploy in production whenever we push to master, as this is now handled by Travis.
This commit is contained in:
parent
e8e85b57dc
commit
df7c60ac17
6 changed files with 32 additions and 81 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -8,3 +8,4 @@ yarn-error.log
|
|||
dist-es5-module/
|
||||
tmp
|
||||
docs/.textlintcache
|
||||
.netlify
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
#!/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
|
||||
12
netlify.toml
12
netlify.toml
|
|
@ -5,13 +5,7 @@
|
|||
NODE_ENV = "development"
|
||||
YARN_VERSION = "1.9.4"
|
||||
|
||||
# Deploy documentation website on each commit on master
|
||||
[context.master]
|
||||
command = "./docs/scripts/netlify-master"
|
||||
|
||||
# Deploy previews on each PR
|
||||
# Disabled for security reasons. Should be enabled back when main deploy is
|
||||
# moved to Travis
|
||||
# [context.deploy-preview]
|
||||
# command = "./docs/scripts/netlify-deploy-preview"
|
||||
# publish = "docs/dist"
|
||||
[context.deploy-preview]
|
||||
command = "./scripts/netlify/deploy-preview"
|
||||
publish = "docs/dist"
|
||||
|
|
|
|||
15
scripts/netlify/changes-in-docs-since-master
Executable file
15
scripts/netlify/changes-in-docs-since-master
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
# Compare current branch with master to see if there are changes in the docs/
|
||||
# folder
|
||||
set -x
|
||||
|
||||
# Remote urls are not always set on Netlify
|
||||
git remote set-url origin https://github.com/algolia/docsearch.git
|
||||
git fetch
|
||||
|
||||
CHANGES_IN_DOCS="$(git diff --name-only origin/master | grep '^docs/')"
|
||||
if [ "$CHANGES_IN_DOCS" = "" ]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
|
||||
|
|
@ -4,30 +4,20 @@
|
|||
#
|
||||
# Note: Check the following link for a list of available environment variables:
|
||||
# https://www.netlify.com/docs/continuous-deployment/#build-environment-variables
|
||||
set -x
|
||||
|
||||
if [ "$CONTEXT" != "deploy-preview" ]; then
|
||||
echo "This script should only be run on Netlify."
|
||||
exit 1
|
||||
if ! ./scripts/netlify/is-deploy-preview; then
|
||||
echo "✘ This script should only be run on Netlify, for deploy previews";
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Compare current branch with master to see if there are changes in the docs/
|
||||
# folder
|
||||
git remote set-url origin https://github.com/algolia/docsearch.git
|
||||
git fetch
|
||||
git diff --name-status origin/master | grep 'docs/' 1>/dev/null
|
||||
DOCS_FOLDER_HAS_CHANGED=$?
|
||||
|
||||
cd ./docs || exit
|
||||
|
||||
# No change, we create a simple preview
|
||||
if [ "$DOCS_FOLDER_HAS_CHANGED" = "1" ]; then
|
||||
mkdir -p ./dist
|
||||
if ! ./scripts/netlify/changes-in-docs-since-master; then
|
||||
echo "✘ This PR does not have any changes done in ./docs."
|
||||
mkdir -p ./docs/dist
|
||||
echo "No deploy preview available as this PR does not change the documentation." > ./dist/index.html
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# Full build if documentation changed
|
||||
cd ./docs || exit
|
||||
yarn install
|
||||
yarn run build
|
||||
|
||||
5
scripts/netlify/is-deploy-preview
Executable file
5
scripts/netlify/is-deploy-preview
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
if [ "$CONTEXT" = "deploy-preview" ]; then
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
Loading…
Reference in a new issue