2017-05-19 21:58:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
TARGET_DIR='gh-pages'
|
|
|
|
TARGET_BRANCH='master'
|
2020-10-13 23:12:19 +02:00
|
|
|
TARGET_REPO_URL="https://$GITHUB_TOKEN@github.com/chartjs/chartjs.github.io.git"
|
2017-05-19 21:58:34 +02:00
|
|
|
|
2020-10-13 23:12:19 +02:00
|
|
|
VERSION=$1
|
2017-05-19 21:58:34 +02:00
|
|
|
|
2020-05-05 21:19:57 +02:00
|
|
|
function move_sample_scripts {
|
|
|
|
local subdirectory=$1
|
|
|
|
for f in $(find ./samples/$subdirectory -name '*.html'); do
|
|
|
|
sed -i -E "s/((\.\.\/)+dist\/)/..\/\1$subdirectory\//" $f
|
|
|
|
done
|
|
|
|
}
|
2020-03-06 00:05:02 +01:00
|
|
|
|
2020-05-05 21:19:57 +02:00
|
|
|
function update_with_tag {
|
|
|
|
local tag=$1
|
|
|
|
rm -rf "docs/$tag"
|
|
|
|
cp -r ../dist/docs docs/$tag
|
|
|
|
rm -rf "samples/$tag"
|
|
|
|
cp -r ../samples samples/$tag
|
2020-03-06 00:05:02 +01:00
|
|
|
|
2020-05-05 21:19:57 +02:00
|
|
|
move_sample_scripts $tag
|
2020-03-06 00:05:02 +01:00
|
|
|
|
2020-05-05 21:19:57 +02:00
|
|
|
deploy_versioned_files $tag
|
|
|
|
}
|
2020-03-06 00:05:02 +01:00
|
|
|
|
2020-05-05 21:19:57 +02:00
|
|
|
# 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/
|
2020-05-27 23:14:17 +02:00
|
|
|
# https://www.chartjs.org/dist/$tag/chart.*js
|
2020-05-05 21:19:57 +02:00
|
|
|
function update_tagged_files {
|
|
|
|
if [ "$VERSION" == "master" ]; then
|
|
|
|
update_with_tag master
|
|
|
|
elif [[ "$VERSION" =~ ^[^-]+$ ]]; then
|
2020-10-13 23:12:19 +02:00
|
|
|
update_with_tag latest
|
2020-05-05 21:19:57 +02:00
|
|
|
else
|
|
|
|
update_with_tag next
|
|
|
|
fi
|
2017-05-19 21:58:34 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 21:19:57 +02:00
|
|
|
function deploy_versioned_files {
|
|
|
|
local version=$1
|
2020-05-25 22:54:22 +02:00
|
|
|
local in_files='../dist/chart*.js'
|
2020-05-05 21:19:57 +02:00
|
|
|
local out_path='./dist'
|
|
|
|
rm -rf $out_path/$version
|
|
|
|
mkdir -p $out_path/$version
|
|
|
|
cp -r $in_files $out_path/$version
|
2017-05-19 21:58:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Clone the repository and checkout the gh-pages branch
|
|
|
|
git clone $TARGET_REPO_URL $TARGET_DIR
|
|
|
|
cd $TARGET_DIR
|
|
|
|
git checkout $TARGET_BRANCH
|
|
|
|
|
2020-05-05 21:19:57 +02:00
|
|
|
# Copy distribution files
|
|
|
|
deploy_versioned_files $VERSION
|
2017-05-19 21:58:34 +02:00
|
|
|
|
2020-05-05 21:19:57 +02:00
|
|
|
update_tagged_files
|
2017-05-19 21:58:34 +02:00
|
|
|
|
2020-05-05 21:19:57 +02:00
|
|
|
git add --all
|
2017-05-19 21:58:34 +02:00
|
|
|
|
|
|
|
git remote add auth-origin $TARGET_REPO_URL
|
2020-10-13 23:12:19 +02:00
|
|
|
git config --global user.email "$GH_AUTH_EMAIL"
|
2017-05-19 21:58:34 +02:00
|
|
|
git config --global user.name "Chart.js"
|
2020-10-13 23:12:19 +02:00
|
|
|
git commit -m "Deploy $VERSION from $GITHUB_REPOSITORY" -m "Commit: $GITHUB_SHA"
|
2017-05-19 21:58:34 +02:00
|
|
|
git push -q auth-origin $TARGET_BRANCH
|
|
|
|
git remote rm auth-origin
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
cd ..
|
|
|
|
rm -rf $TARGET_DIR
|