Skip to content

Commit b6f7ec7

Browse files
mdojulien-deramond
andauthored
Streamline release prep script (#41539)
* Streamline release prep script * Delete local branch if already existing --------- Co-authored-by: Julien Déramond <juderamond@gmail.com>
1 parent f63e549 commit b6f7ec7

1 file changed

Lines changed: 30 additions & 54 deletions

File tree

build/docs-prep.sh

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ fi
1818
# Branch name to create
1919
NEW_BRANCH="gh-pages-${BRANCH_SUFFIX}"
2020

21+
# Get the current docs version from config
22+
DOCS_VERSION=$(node -p "require('js-yaml').load(require('fs').readFileSync('config.yml', 'utf8')).docs_version")
23+
2124
# Function to print colored messages
2225
print_success() {
2326
echo -e "${GREEN}$1${NC}"
@@ -89,66 +92,39 @@ fi
8992
print_success "Pulled latest changes from origin/gh-pages"
9093

9194
# Step 4: Create a new branch for the update
95+
print_info "Checking if branch ${NEW_BRANCH} exists and deleting it if it does…"
96+
if git show-ref --verify --quiet refs/heads/${NEW_BRANCH}; then
97+
execute "git branch -D ${NEW_BRANCH}"
98+
else
99+
print_info "Branch ${NEW_BRANCH} does not exist, proceeding with creation…"
100+
fi
92101
print_info "Creating new branch ${NEW_BRANCH}"
93102
execute "git checkout -b ${NEW_BRANCH}"
94103

95-
# Step 5: Move root files
96-
print_info "Moving root files from temporary location…"
97-
ROOT_FILES=("404.html" "CNAME" "apple-touch-icon.png" "favicon.ico" "index.html" "robots.txt" "sitemap-0.xml" "sitemap-index.xml" "sw.js")
98-
for file in "${ROOT_FILES[@]}"; do
99-
if [ -f "/tmp/_site/$file" ]; then
100-
execute "mv /tmp/_site/$file ."
101-
else
102-
print_warning "File /tmp/_site/$file not found. Skipping."
103-
fi
104-
done
105-
106-
# Step 6: Move directories with cleanup
107-
print_info "Moving directories from temporary location…"
108-
DIRS=("about" "components" "docsref" "examples" "getting-started" "migration")
109-
for dir in "${DIRS[@]}"; do
110-
if [ -d "/tmp/_site/$dir" ]; then
111-
if [ -d "$dir" ]; then
112-
execute "rm -rf $dir"
113-
fi
114-
execute "mv /tmp/_site/$dir ."
115-
else
116-
print_warning "Directory /tmp/_site/$dir not found. Skipping."
117-
fi
118-
done
119-
120-
# Step 7: Handle special doc directories
121-
print_info "Handling special documentation directories…"
122-
SPECIAL_DOCS=("docs/getting-started" "docs/versions")
123-
for dir in "${SPECIAL_DOCS[@]}"; do
124-
if [ -d "/tmp/_site/$dir" ]; then
125-
if [ -d "$dir" ]; then
126-
execute "rm -rf $dir"
127-
fi
128-
# Make sure parent directory exists
129-
parent_dir=$(dirname "$dir")
130-
mkdir -p "$parent_dir"
131-
execute "mv /tmp/_site/$dir $parent_dir/"
132-
else
133-
print_warning "Directory /tmp/_site/$dir not found. Skipping."
134-
fi
135-
done
104+
# Step 5: Move all root-level files from Astro build
105+
find /tmp/_site -maxdepth 1 -type f -exec mv {} . \;
136106

137-
# Step 8: Move docs index.html
138-
if [ -f "/tmp/_site/docs/index.html" ]; then
139-
execute "mv /tmp/_site/docs/index.html docs/index.html"
140-
else
141-
print_warning "File /tmp/_site/docs/index.html not found. Skipping."
142-
fi
107+
# Step 6: Move all top-level directories except 'docs' (which needs special handling)
108+
find /tmp/_site -maxdepth 1 -type d ! -name "_site" ! -name "docs" -exec sh -c 'dir=$(basename "$1"); rm -rf "$dir"; mv "$1" .' _ {} \;
143109

144-
# Step 9: Handle docs/5.3
145-
if [ -d "/tmp/_site/docs/5.3" ]; then
146-
if [ -d "docs/5.3" ]; then
147-
execute "rm -rf docs/5.3"
110+
# Step 7: Handle docs directory specially
111+
if [ -d "/tmp/_site/docs" ]; then
112+
# Replace only the current version's docs
113+
if [ -d "docs/$DOCS_VERSION" ]; then
114+
rm -rf "docs/$DOCS_VERSION"
148115
fi
149-
execute "mv /tmp/_site/docs/5.3 docs/"
150-
else
151-
print_warning "Directory /tmp/_site/docs/5.3 not found. Skipping."
116+
mv "/tmp/_site/docs/$DOCS_VERSION" "docs/"
117+
118+
# Handle docs root files
119+
find /tmp/_site/docs -maxdepth 1 -type f -exec mv {} docs/ \;
120+
121+
# Handle special docs directories (getting-started, versions)
122+
for special_dir in getting-started versions; do
123+
if [ -d "/tmp/_site/docs/$special_dir" ]; then
124+
rm -rf "docs/$special_dir"
125+
mv "/tmp/_site/docs/$special_dir" "docs/"
126+
fi
127+
done
152128
fi
153129

154130
# Clean up remaining files in /tmp/_site if any

0 commit comments

Comments
 (0)