diff --git a/.travis.yml b/.travis.yml index 299ff6ad3fc..2d2c108d5ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ services: script: - gulp build - gulp test --coverage + - ./scripts/docs-config.sh - npm run docs - npm run typedoc - gulp package diff --git a/scripts/deploy.sh b/scripts/deploy.sh index aa2e2b29626..7cafdce8c0b 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -5,9 +5,10 @@ set -e TARGET_DIR='gh-pages' TARGET_BRANCH='master' TARGET_REPO_URL="https://$GITHUB_AUTH_TOKEN@github.com/chartjs/chartjs.github.io.git" -VERSION_REGEX='[[:digit:]]+.[[:digit:]]+.[[:digit:]]+(-.*)?' +# Note: this code also exists in docs-config.sh # Make sure that this script is executed only for the release and master branches +VERSION_REGEX='[[:digit:]]+.[[:digit:]]+.[[:digit:]]+(-.*)?' if [[ "$TRAVIS_BRANCH" =~ ^release.*$ ]]; then # Travis executes this script from the repository root, so at the same level than package.json VERSION=$(node -p -e "require('./package.json').version") @@ -35,10 +36,9 @@ function update_with_tag { move_sample_scripts $tag deploy_versioned_files $tag - - sed -i -e "s/VERSION/$tag/g" "docs/$tag/docusaurus.config.js" } +# Note: this code also exists in docs-config.sh # tag is next|latest|master # https://www.chartjs.org/docs/$tag/ # https://www.chartjs.org/samples/$tag/ diff --git a/scripts/docs-config.sh b/scripts/docs-config.sh new file mode 100755 index 00000000000..ed557f3577a --- /dev/null +++ b/scripts/docs-config.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +# Note: this code also exists in deploy.sh +# Make sure that this script is executed only for the release and master branches +VERSION_REGEX='[[:digit:]]+.[[:digit:]]+.[[:digit:]]+(-.*)?' +if [[ "$TRAVIS_BRANCH" =~ ^release.*$ ]]; then + # Travis executes this script from the repository root, so at the same level than package.json + VERSION=$(node -p -e "require('./package.json').version") +elif [ "$TRAVIS_BRANCH" == "master" ]; then + VERSION="master" +else + echo "Skipping docs configuration because this is not the master or release branch" + exit 0 +fi + +# Note: this code also exists in deploy.sh +# tag is next|latest|master +# https://www.chartjs.org/docs/$tag/ +function update_config { + local tag='' + if [ "$VERSION" == "master" ]; then + tag=master + elif [[ "$VERSION" =~ ^[^-]+$ ]]; then + tag=lastest + else + tag=next + fi + sed -i -e "s/VERSION/$tag/g" "docs/docusaurus.config.js" +} + +update_config