-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdeploy.sh
executable file
·46 lines (38 loc) · 1.38 KB
/
deploy.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
#!/bin/bash
#
# This script deploys main branch commits to gh-pages root directory and other branches to
# sub-directory /branch/<branch-name>.
#
# Rendered branches can be accessed via https://learn.libre.solar/branch/<branch-name>
#
# See here for documentation of Travis CI environment variables:
# https://docs.travis-ci.com/user/environment-variables/
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})
# adjust link/directory settings in vuepress
if [ $BRANCH_NAME != "main" ]; then
printf "\nPreparing deployment for branch $BRANCH_NAME\n"
sed -i -e "s/base: '\/'/base: '\/branch\/$BRANCH_NAME\/'/g" docs/.vuepress/config.js
sed -i -e "s/docsBranch: 'master'/docsBranch: '$BRANCH_NAME'/g" docs/.vuepress/config.js
else
printf "\nPreparing deployment for main branch\n"
fi
# build the website
npm run docs:build
printf "\n\n"
# get previous gh-pages deployment including all PR and branch folders
rm -rf gh-pages
git clone -b gh-pages https://github.com/LibreSolar/learn.libre.solar gh-pages
# compile folders correctly
if [ $BRANCH_NAME != "main" ]; then
mkdir -p gh-pages/branch
rm -rf "gh-pages/branch/$BRANCH_NAME"
cp -r docs/.vuepress/dist "gh-pages/branch/$BRANCH_NAME"
else
if [ -d "gh-pages/branch" ]; then
mv gh-pages/branch docs/.vuepress/dist/
fi
rm -rf gh-pages
mv docs/.vuepress/dist gh-pages
fi
echo "Preparation and build done."
exit 0