-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathrun_netlify.sh
61 lines (49 loc) · 2.01 KB
/
run_netlify.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
#!/bin/bash
# run pull request preview site with netlify
# install required packages
pip install mkdocs-material \
mkdocs-git-revision-date-plugin \
mkdocs-mermaid2-plugin \
mkdocs-rss-plugin \
mkdocs-minify-plugin \
mkdocs-macros-plugin \
mkdocs-git-committers-plugin-2 \
mkdocs-git-revision-date-localized-plugin \
mkdocs-awesome-pages-plugin \
mkdocs-redirects \
mkdocs-print-site-plugin \
mkdocs-swagger-ui-tag \
pyyaml
# Ensure the git repository is up to date.
git fetch origin main
# Get the current build commit SHA
CURRENT_COMMIT_SHA=$(git rev-parse HEAD)
echo "Current commit SHA: $CURRENT_COMMIT_SHA"
# Get the latest commit SHA of the main branch
MAIN_COMMIT_SHA=$(git rev-parse origin/main)
echo "Main commit SHA: $MAIN_COMMIT_SHA"
# Get the list of changed files and convert it to a space-separated string.
CHANGED_FILES=$(git diff --name-only $MAIN_COMMIT_SHA $CURRENT_COMMIT_SHA | tr '\n' ' ')
# Add the list of modified files to the environment variable.
export CHANGED_FILES
# Print environment variables to confirm
echo "CHANGED_FILES environment variable:"
echo "$CHANGED_FILES"
# Generate the navigation for the docs
python scripts/generate_nav.py
# Perform different operations based on the modified files.
if echo "$CHANGED_FILES" | grep -q 'docs/zh/docs/'; then
echo "Chinese docs were modified, running mkdocs build for Chinese docs..."
mkdocs build -f docs/zh/mkdocs.yml -d ../../public/
fi
if echo "$CHANGED_FILES" | grep -q 'docs/en/docs/'; then
echo "English docs were modified, running mkdocs build for English docs..."
mkdocs build -f docs/en/mkdocs.yml -d ../../public/en/
fi
# Check if the public/ directory exists, and create it if it does not.
if [ ! -d "public" ]; then
echo "Public directory not found. Creating public/ directory."
mkdir -p public/en/
echo "<html><body><h1>Welcome to the public directory</h1></body></html>" > public/index.html
echo "<html><body><h1>Welcome to the public directory</h1></body></html>" > public/en/index.html
fi