File: docs-prep.sh

package info (click to toggle)
bootstrap-html 5.3.8%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,364 kB
  • sloc: javascript: 17,934; sh: 109; makefile: 49
file content (157 lines) | stat: -rwxr-xr-x 4,646 bytes parent folder | download | duplicates (2)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Default branch suffix
BRANCH_SUFFIX="release"

# Check if a custom version parameter was provided
if [ $# -eq 1 ]; then
  BRANCH_SUFFIX="$1"
fi

# Branch name to create
NEW_BRANCH="gh-pages-${BRANCH_SUFFIX}"

# Get the current docs version from config
DOCS_VERSION=$(node -p "require('js-yaml').load(require('fs').readFileSync('config.yml', 'utf8')).docs_version")

# Function to print colored messages
print_success() {
  echo -e "${GREEN}✓ $1${NC}"
}

print_error() {
  echo -e "${RED}✗ $1${NC}"
  exit 1
}

print_info() {
  echo -e "${BLUE}ℹ $1${NC}"
}

print_warning() {
  echo -e "${YELLOW}⚠ $1${NC}"
}

# Function to execute command with error handling
execute() {
  print_info "Running: $1"
  eval $1
  if [ $? -ne 0 ]; then
    print_error "Failed to execute: $1"
  else
    print_success "Successfully executed: $1"
  fi
}

# Check if /tmp/_site directory exists from a previous run
if [ -d "/tmp/_site" ]; then
  print_warning "Found existing /tmp/_site directory. Removing it…"
  rm -rf /tmp/_site
fi

# Main process
print_info "Starting documentation deployment process…"

# Step 1: Build documentation
print_info "Building documentation with npm run docs…"
npm run docs
if [ $? -ne 0 ]; then
  print_error "Documentation build failed!"
fi
print_success "Documentation built successfully"

# Step 2: Move _site to /tmp/
print_info "Moving _site to temporary location…"
execute "mv _site /tmp/"

# Step 3: Switch to gh-pages branch
print_info "Checking out gh-pages branch…"
git checkout gh-pages
if [ $? -ne 0 ]; then
  print_error "Failed to checkout gh-pages branch. Make sure it exists."
fi
print_success "Switched to gh-pages branch"

git reset --hard origin/gh-pages
if [ $? -ne 0 ]; then
  print_error "Failed to reset to origin/gh-pages. Check your git configuration."
fi
print_success "Reset to origin/gh-pages"

git pull origin gh-pages
if [ $? -ne 0 ]; then
  print_error "Failed to pull from origin/gh-pages. Check your network connection and git configuration."
fi
print_success "Pulled latest changes from origin/gh-pages"

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

# Step 5: Move all root-level files from Astro build
find /tmp/_site -maxdepth 1 -type f -exec mv {} . \;

# Step 6: Move all top-level directories except 'docs' (which needs special handling)
find /tmp/_site -maxdepth 1 -type d ! -name "_site" ! -name "docs" -exec sh -c 'dir=$(basename "$1"); rm -rf "$dir"; mv "$1" .' _ {} \;

# Step 7: Handle docs directory specially
if [ -d "/tmp/_site/docs" ]; then
  # Replace only the current version's docs
  if [ -d "docs/$DOCS_VERSION" ]; then
    rm -rf "docs/$DOCS_VERSION"
  fi
  mv "/tmp/_site/docs/$DOCS_VERSION" "docs/"

  # Handle docs root files
  find /tmp/_site/docs -maxdepth 1 -type f -exec mv {} docs/ \;

  # Handle special docs directories (getting-started, versions)
  for special_dir in getting-started versions; do
    if [ -d "/tmp/_site/docs/$special_dir" ]; then
      rm -rf "docs/$special_dir"
      mv "/tmp/_site/docs/$special_dir" "docs/"
    fi
  done
fi

# Clean up remaining files in /tmp/_site if any
if [ -d "/tmp/_site" ]; then
  remaining_files=$(find /tmp/_site -type f | wc -l)
  remaining_dirs=$(find /tmp/_site -type d | wc -l)
  if [ $remaining_files -gt 0 ] || [ $remaining_dirs -gt 1 ]; then
    print_warning "There are still some files or directories in /tmp/_site that weren't moved."
    print_warning "You may want to inspect /tmp/_site to see if anything important was missed."
  else
    print_info "Cleaning up temporary directory…"
    rm -rf /tmp/_site
    print_success "Temporary directory cleaned up"
  fi
fi

# Step 10: Remove empty site directory if it exists
if [ -d "site" ]; then
  print_info "Removing empty site directory…"
  execute "rm -rf site"
fi

print_success "Docs prep complete!"
print_info "Review changes before committing and pushing."
print_info "Next steps:"
print_info "  1. Run a local server to review changes"
print_info "  2. Check browser and web inspector for any errors"
print_info "  3. git add ."
print_info "  4. git commit -m \"Update documentation\""
print_info "  5. git push origin ${NEW_BRANCH}"