Skip to content

Commit dddd792

Browse files
authored
Add docs release prep script (#41435)
* Add docs release prep script * Fix indentation * Add argument * Remote empty site dir, update completion text
1 parent c5bec4e commit dddd792

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed

build/docs-prep.sh

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#!/bin/bash
2+
3+
# Colors for output
4+
RED='\033[0;31m'
5+
GREEN='\033[0;32m'
6+
YELLOW='\033[0;33m'
7+
BLUE='\033[0;34m'
8+
NC='\033[0m' # No Color
9+
10+
# Default branch suffix
11+
BRANCH_SUFFIX="release"
12+
13+
# Check if a custom version parameter was provided
14+
if [ $# -eq 1 ]; then
15+
BRANCH_SUFFIX="$1"
16+
fi
17+
18+
# Branch name to create
19+
NEW_BRANCH="gh-pages-${BRANCH_SUFFIX}"
20+
21+
# Function to print colored messages
22+
print_success() {
23+
echo -e "${GREEN}$1${NC}"
24+
}
25+
26+
print_error() {
27+
echo -e "${RED}$1${NC}"
28+
exit 1
29+
}
30+
31+
print_info() {
32+
echo -e "${BLUE}$1${NC}"
33+
}
34+
35+
print_warning() {
36+
echo -e "${YELLOW}$1${NC}"
37+
}
38+
39+
# Function to execute command with error handling
40+
execute() {
41+
print_info "Running: $1"
42+
eval $1
43+
if [ $? -ne 0 ]; then
44+
print_error "Failed to execute: $1"
45+
else
46+
print_success "Successfully executed: $1"
47+
fi
48+
}
49+
50+
# Check if /tmp/_site directory exists from a previous run
51+
if [ -d "/tmp/_site" ]; then
52+
print_warning "Found existing /tmp/_site directory. Removing it…"
53+
rm -rf /tmp/_site
54+
fi
55+
56+
# Main process
57+
print_info "Starting documentation deployment process…"
58+
59+
# Step 1: Build documentation
60+
print_info "Building documentation with npm run docs…"
61+
npm run docs
62+
if [ $? -ne 0 ]; then
63+
print_error "Documentation build failed!"
64+
fi
65+
print_success "Documentation built successfully"
66+
67+
# Step 2: Move _site to /tmp/
68+
print_info "Moving _site to temporary location…"
69+
execute "mv _site /tmp/"
70+
71+
# Step 3: Switch to gh-pages branch
72+
print_info "Checking out gh-pages branch…"
73+
git checkout gh-pages
74+
if [ $? -ne 0 ]; then
75+
print_error "Failed to checkout gh-pages branch. Make sure it exists."
76+
fi
77+
print_success "Switched to gh-pages branch"
78+
79+
# Step 4: Create a new branch for the update
80+
print_info "Creating new branch ${NEW_BRANCH}"
81+
execute "git checkout -b ${NEW_BRANCH}"
82+
83+
# Step 5: Move root files
84+
print_info "Moving root files from temporary location…"
85+
ROOT_FILES=("404.html" "CNAME" "apple-touch-icon.png" "favicon.ico" "index.html" "robots.txt" "sitemap-0.xml" "sitemap-index.xml" "sw.js")
86+
for file in "${ROOT_FILES[@]}"; do
87+
if [ -f "/tmp/_site/$file" ]; then
88+
execute "mv /tmp/_site/$file ."
89+
else
90+
print_warning "File /tmp/_site/$file not found. Skipping."
91+
fi
92+
done
93+
94+
# Step 6: Move directories with cleanup
95+
print_info "Moving directories from temporary location…"
96+
DIRS=("about" "components" "docsref" "examples" "getting-started" "migration")
97+
for dir in "${DIRS[@]}"; do
98+
if [ -d "/tmp/_site/$dir" ]; then
99+
if [ -d "$dir" ]; then
100+
execute "rm -rf $dir"
101+
fi
102+
execute "mv /tmp/_site/$dir ."
103+
else
104+
print_warning "Directory /tmp/_site/$dir not found. Skipping."
105+
fi
106+
done
107+
108+
# Step 7: Handle special doc directories
109+
print_info "Handling special documentation directories…"
110+
SPECIAL_DOCS=("docs/getting-started" "docs/versions")
111+
for dir in "${SPECIAL_DOCS[@]}"; do
112+
if [ -d "/tmp/_site/$dir" ]; then
113+
if [ -d "$dir" ]; then
114+
execute "rm -rf $dir"
115+
fi
116+
# Make sure parent directory exists
117+
parent_dir=$(dirname "$dir")
118+
mkdir -p "$parent_dir"
119+
execute "mv /tmp/_site/$dir $parent_dir/"
120+
else
121+
print_warning "Directory /tmp/_site/$dir not found. Skipping."
122+
fi
123+
done
124+
125+
# Step 8: Move docs index.html
126+
if [ -f "/tmp/_site/docs/index.html" ]; then
127+
execute "mv /tmp/_site/docs/index.html docs/index.html"
128+
else
129+
print_warning "File /tmp/_site/docs/index.html not found. Skipping."
130+
fi
131+
132+
# Step 9: Handle docs/5.3
133+
if [ -d "/tmp/_site/docs/5.3" ]; then
134+
if [ -d "docs/5.3" ]; then
135+
execute "rm -rf docs/5.3"
136+
fi
137+
execute "mv /tmp/_site/docs/5.3 docs/"
138+
else
139+
print_warning "Directory /tmp/_site/docs/5.3 not found. Skipping."
140+
fi
141+
142+
# Clean up remaining files in /tmp/_site if any
143+
if [ -d "/tmp/_site" ]; then
144+
remaining_files=$(find /tmp/_site -type f | wc -l)
145+
remaining_dirs=$(find /tmp/_site -type d | wc -l)
146+
if [ $remaining_files -gt 0 ] || [ $remaining_dirs -gt 1 ]; then
147+
print_warning "There are still some files or directories in /tmp/_site that weren't moved."
148+
print_warning "You may want to inspect /tmp/_site to see if anything important was missed."
149+
else
150+
print_info "Cleaning up temporary directory…"
151+
rm -rf /tmp/_site
152+
print_success "Temporary directory cleaned up"
153+
fi
154+
fi
155+
156+
# Step 10: Remove empty site directory if it exists
157+
if [ -d "site" ]; then
158+
print_info "Removing empty site directory…"
159+
execute "rm -rf site"
160+
fi
161+
162+
print_success "Docs prep complete!"
163+
print_info "Review changes before committing and pushing."
164+
print_info "Next steps:"
165+
print_info " 1. Run a local server to review changes"
166+
print_info " 2. Check browser and web inspector for any errors"
167+
print_info " 3. git add ."
168+
print_info " 4. git commit -m \"Update documentation\""
169+
print_info " 5. git push origin ${NEW_BRANCH}"

0 commit comments

Comments
 (0)