-
Notifications
You must be signed in to change notification settings - Fork 11.9k
/
Copy pathdeploy-docs.sh
executable file
·74 lines (58 loc) · 1.67 KB
/
deploy-docs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
set -e
TARGET_DIR='gh-pages'
TARGET_BRANCH='master'
TARGET_REPO_URL="https://$GITHUB_TOKEN@github.com/chartjs/chartjs.github.io.git"
VERSION=$1
function move_sample_redirect {
local tag=$1
cp ../scripts/sample-redirect-template.html samples/$tag/index.html
sed -i -E "s/TAG/$tag/g" samples/$tag/index.html
}
function update_with_tag {
local tag=$1
rm -rf "docs/$tag"
cp -r ../dist/docs docs/$tag
rm -rf "samples/$tag"
mkdir "samples/$tag"
move_sample_redirect $tag
deploy_versioned_files $tag
}
# Note: this code also exists in docs-config.sh
# tag is next|latest|master
# https://www.chartjs.org/docs/$tag/
# https://www.chartjs.org/dist/$tag/chart.*js
function update_tagged_files {
if [ "$VERSION" == "master" ]; then
update_with_tag master
elif [[ "$VERSION" =~ ^[^-]+$ ]]; then
update_with_tag latest
else
update_with_tag next
fi
}
function deploy_versioned_files {
local version=$1
local in_files='../dist/chart*.js'
local out_path='./dist'
rm -rf $out_path/$version
mkdir -p $out_path/$version
cp -r $in_files $out_path/$version
}
# Clone the repository and checkout the gh-pages branch
git clone $TARGET_REPO_URL $TARGET_DIR
cd $TARGET_DIR
git checkout $TARGET_BRANCH
# Copy distribution files
deploy_versioned_files $VERSION
update_tagged_files
git add --all
git remote add auth-origin $TARGET_REPO_URL
git config --global user.email "$GH_AUTH_EMAIL"
git config --global user.name "Chart.js"
git commit -m "Deploy $VERSION from $GITHUB_REPOSITORY" -m "Commit: $GITHUB_SHA"
git push -q auth-origin $TARGET_BRANCH
git remote rm auth-origin
# Cleanup
cd ..
rm -rf $TARGET_DIR