|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | 3 | # Script to generate DocC documentation and publish it to GitHub Pages |
4 | | -# This script generates documentation using swift package generate-documentation |
5 | | -# and publishes it to a GitHub Pages repository |
| 4 | +# This script generates documentation using xcodebuild docbuild |
| 5 | +# and publishes it to a GitHub Pages repository (rickhohler.github.io) |
6 | 6 |
|
7 | 7 | set -e |
8 | 8 |
|
@@ -63,30 +63,59 @@ echo "" |
63 | 63 | # Change to repository root |
64 | 64 | cd "$REPO_ROOT" |
65 | 65 |
|
66 | | -# Generate DocC documentation |
| 66 | +# Generate DocC documentation using xcodebuild |
67 | 67 | echo -e "${GREEN}Generating DocC documentation...${NC}" |
68 | | -swift package --version || echo "Swift package manager check" |
69 | 68 |
|
70 | | -# Try to generate documentation |
71 | | -DOCS_ARCHIVE="" |
72 | | -DERIVED_DATA="$HOME/Library/Developer/Xcode/DerivedData" |
| 69 | +# Create a temporary directory for docbuild output |
| 70 | +DOCBUILD_DIR="${REPO_ROOT}/.docbuild" |
| 71 | +rm -rf "$DOCBUILD_DIR" |
| 72 | +mkdir -p "$DOCBUILD_DIR" |
73 | 73 |
|
74 | | -if swift package generate-documentation --target "$PACKAGE_NAME" 2>&1; then |
75 | | - echo -e "${GREEN}DocC documentation generated successfully${NC}" |
| 74 | +# Build documentation using xcodebuild docbuild |
| 75 | +echo "Building documentation with xcodebuild..." |
| 76 | +# For Swift packages, we need to use -packagePath instead of -scheme |
| 77 | +if xcodebuild docbuild \ |
| 78 | + -packagePath "$REPO_ROOT" \ |
| 79 | + -derivedDataPath "$DOCBUILD_DIR" \ |
| 80 | + -destination 'generic/platform=macOS' 2>&1; then |
| 81 | + echo -e "${GREEN}DocC documentation built successfully${NC}" |
76 | 82 |
|
77 | | - # Find documentation archive |
78 | | - if [ -d "$DERIVED_DATA" ]; then |
79 | | - # Find most recent .doccarchive |
80 | | - DOCS_ARCHIVE=$(find "$DERIVED_DATA" -name "*.doccarchive" -type d -mtime -1 2>/dev/null | head -1) |
81 | | - fi |
| 83 | + # Find the .doccarchive |
| 84 | + DOCS_ARCHIVE=$(find "$DOCBUILD_DIR" -name "*.doccarchive" -type d | head -1) |
82 | 85 |
|
83 | | - # Check .build directory as fallback |
84 | 86 | if [ -z "$DOCS_ARCHIVE" ]; then |
85 | | - DOCS_ARCHIVE=$(find .build -name "*.doccarchive" -type d 2>/dev/null | head -1) |
| 87 | + # Try alternative location |
| 88 | + DOCS_ARCHIVE=$(find "$DOCBUILD_DIR" -name "*.doccarchive" -type d | head -1) |
| 89 | + fi |
| 90 | + |
| 91 | + if [ -n "$DOCS_ARCHIVE" ] && [ -d "$DOCS_ARCHIVE" ]; then |
| 92 | + echo "Found DocC archive: $DOCS_ARCHIVE" |
| 93 | + |
| 94 | + # Transform archive for static hosting |
| 95 | + STATIC_DOCS_DIR="${REPO_ROOT}/.static-docs" |
| 96 | + rm -rf "$STATIC_DOCS_DIR" |
| 97 | + mkdir -p "$STATIC_DOCS_DIR" |
| 98 | + |
| 99 | + echo "Transforming archive for static hosting..." |
| 100 | + if command -v docc >/dev/null 2>&1; then |
| 101 | + docc process-archive transform-for-static-hosting \ |
| 102 | + "$DOCS_ARCHIVE" \ |
| 103 | + --output-path "$STATIC_DOCS_DIR" \ |
| 104 | + --hosting-base-path "/${PACKAGE_NAME,,}" || { |
| 105 | + echo -e "${YELLOW}Warning: docc transform failed, using archive directly${NC}" |
| 106 | + STATIC_DOCS_DIR="$DOCS_ARCHIVE" |
| 107 | + } |
| 108 | + else |
| 109 | + echo -e "${YELLOW}Warning: docc command not found, using archive directly${NC}" |
| 110 | + STATIC_DOCS_DIR="$DOCS_ARCHIVE" |
| 111 | + fi |
| 112 | + else |
| 113 | + echo -e "${YELLOW}DocC archive not found, creating static fallback site${NC}" |
| 114 | + STATIC_DOCS_DIR="" |
86 | 115 | fi |
87 | 116 | else |
88 | | - echo -e "${YELLOW}DocC generation not available, creating static documentation site${NC}" |
89 | | - DOCS_ARCHIVE="" |
| 117 | + echo -e "${YELLOW}xcodebuild docbuild failed, creating static fallback site${NC}" |
| 118 | + STATIC_DOCS_DIR="" |
90 | 119 | fi |
91 | 120 |
|
92 | 121 | # Clone or update the GitHub Pages repository |
@@ -147,31 +176,31 @@ else |
147 | 176 | fi |
148 | 177 |
|
149 | 178 | # Determine the documentation directory |
150 | | -# For Swift packages, we'll publish to a subdirectory like /DesignAlgorithmsKit/ |
| 179 | +# For Swift packages, we'll publish to a subdirectory like /designalgorithmskit/ |
151 | 180 | DOCS_DIR="${PACKAGE_NAME,,}" # Convert to lowercase |
152 | 181 | mkdir -p "$DOCS_DIR" |
153 | 182 |
|
154 | 183 | echo "Using documentation directory: $DOCS_DIR" |
155 | 184 | echo "" |
156 | 185 |
|
157 | 186 | # Copy documentation to GitHub Pages repository |
158 | | -if [ -n "$DOCS_ARCHIVE" ] && [ -d "$DOCS_ARCHIVE" ]; then |
159 | | - echo -e "${GREEN}Copying DocC archive to GitHub Pages...${NC}" |
160 | | - echo "Source: $DOCS_ARCHIVE" |
| 187 | +if [ -n "$STATIC_DOCS_DIR" ] && [ -d "$STATIC_DOCS_DIR" ]; then |
| 188 | + echo -e "${GREEN}Copying DocC documentation to GitHub Pages...${NC}" |
| 189 | + echo "Source: $STATIC_DOCS_DIR" |
161 | 190 | echo "Destination: $CLONE_DIR/$DOCS_DIR" |
162 | 191 |
|
163 | 192 | # Remove existing documentation |
164 | 193 | rm -rf "$CLONE_DIR/$DOCS_DIR"/* |
165 | 194 |
|
166 | | - # Copy the entire .doccarchive contents |
167 | | - cp -R "$DOCS_ARCHIVE"/* "$CLONE_DIR/$DOCS_DIR/" || { |
168 | | - echo -e "${RED}Error: Failed to copy documentation archive${NC}" |
| 195 | + # Copy the entire documentation contents |
| 196 | + cp -R "$STATIC_DOCS_DIR"/* "$CLONE_DIR/$DOCS_DIR/" || { |
| 197 | + echo -e "${RED}Error: Failed to copy documentation${NC}" |
169 | 198 | exit 1 |
170 | 199 | } |
171 | 200 |
|
172 | 201 | echo -e "${GREEN}Documentation copied successfully${NC}" |
173 | 202 | else |
174 | | - echo -e "${YELLOW}DocC archive not found, creating static fallback site${NC}" |
| 203 | + echo -e "${YELLOW}DocC documentation not found, creating static fallback site${NC}" |
175 | 204 | # Create a simple static HTML site as fallback |
176 | 205 | cat > "$CLONE_DIR/$DOCS_DIR/index.html" << 'EOF' |
177 | 206 | <!DOCTYPE html> |
|
277 | 306 | echo "Documentation will be available at: https://${GITHUB_USER}.github.io/${DOCS_DIR}/" |
278 | 307 | fi |
279 | 308 |
|
| 309 | +# Cleanup |
| 310 | +cd "$REPO_ROOT" |
| 311 | +rm -rf "$DOCBUILD_DIR" "$STATIC_DOCS_DIR" 2>/dev/null || true |
0 commit comments