Skip to content

Commit 3d8b3db

Browse files
committed
fix: Update DocC generation to use xcodebuild docbuild
- Changed from swift package generate-documentation to xcodebuild docbuild - Added docc transform-for-static-hosting step - Improved error handling and fallback behavior - Follows same pattern as 'me' project for GitHub Pages publishing
1 parent 08f7563 commit 3d8b3db

File tree

1 file changed

+58
-26
lines changed

1 file changed

+58
-26
lines changed

scripts/publish-docc-to-github-pages.sh

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

33
# 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)
66

77
set -e
88

@@ -63,30 +63,59 @@ echo ""
6363
# Change to repository root
6464
cd "$REPO_ROOT"
6565

66-
# Generate DocC documentation
66+
# Generate DocC documentation using xcodebuild
6767
echo -e "${GREEN}Generating DocC documentation...${NC}"
68-
swift package --version || echo "Swift package manager check"
6968

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"
7373

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}"
7682

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)
8285

83-
# Check .build directory as fallback
8486
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=""
86115
fi
87116
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=""
90119
fi
91120

92121
# Clone or update the GitHub Pages repository
@@ -147,31 +176,31 @@ else
147176
fi
148177

149178
# 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/
151180
DOCS_DIR="${PACKAGE_NAME,,}" # Convert to lowercase
152181
mkdir -p "$DOCS_DIR"
153182

154183
echo "Using documentation directory: $DOCS_DIR"
155184
echo ""
156185

157186
# 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"
161190
echo "Destination: $CLONE_DIR/$DOCS_DIR"
162191

163192
# Remove existing documentation
164193
rm -rf "$CLONE_DIR/$DOCS_DIR"/*
165194

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}"
169198
exit 1
170199
}
171200

172201
echo -e "${GREEN}Documentation copied successfully${NC}"
173202
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}"
175204
# Create a simple static HTML site as fallback
176205
cat > "$CLONE_DIR/$DOCS_DIR/index.html" << 'EOF'
177206
<!DOCTYPE html>
@@ -277,3 +306,6 @@ else
277306
echo "Documentation will be available at: https://${GITHUB_USER}.github.io/${DOCS_DIR}/"
278307
fi
279308

309+
# Cleanup
310+
cd "$REPO_ROOT"
311+
rm -rf "$DOCBUILD_DIR" "$STATIC_DOCS_DIR" 2>/dev/null || true

0 commit comments

Comments
 (0)