Skip to content

Commit 1896bcb

Browse files
committed
fix: Add Swift DocC Plugin and use swift package generate-documentation
- Added swift-docc-plugin dependency to Package.swift - Changed from xcodebuild docbuild to swift package generate-documentation - Removed invalid -packagePath option that was causing failures - Documentation is now generated directly with transform-for-static-hosting flag
1 parent 704404b commit 1896bcb

2 files changed

Lines changed: 19 additions & 60 deletions

File tree

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ let package = Package(
1717
targets: ["DesignAlgorithmsKit"]),
1818
],
1919
dependencies: [
20-
// No external dependencies - pure Swift implementation
20+
// Swift DocC Plugin for documentation generation
21+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
2122
],
2223
targets: [
2324
.target(

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

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -71,76 +71,34 @@ DOCBUILD_DIR="${REPO_ROOT}/.docbuild"
7171
rm -rf "$DOCBUILD_DIR"
7272
mkdir -p "$DOCBUILD_DIR"
7373

74-
# Build documentation using xcodebuild docbuild
75-
echo "Building documentation with xcodebuild..."
74+
# Generate documentation using Swift DocC Plugin
75+
echo "Generating documentation with Swift DocC Plugin..."
7676
cd "$REPO_ROOT"
7777

7878
# Resolve package dependencies first
7979
swift package resolve
8080

81-
# Try to build documentation - for Swift packages, we need to open it as a package
82-
# First try with an Xcode project if it exists
83-
if [ -f "${PACKAGE_NAME}.xcodeproj/project.pbxproj" ]; then
84-
echo "Using existing Xcode project..."
85-
BUILD_CMD="xcodebuild docbuild -scheme ${PACKAGE_NAME} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
86-
elif [ -f "${PACKAGE_NAME}.xcworkspace/contents.xcworkspacedata" ]; then
87-
echo "Using existing Xcode workspace..."
88-
BUILD_CMD="xcodebuild docbuild -workspace ${PACKAGE_NAME}.xcworkspace -scheme ${PACKAGE_NAME} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
89-
else
90-
echo "No Xcode project found, generating one..."
91-
# Try to generate Xcode project (may not be available in newer Swift versions)
92-
swift package generate-xcodeproj 2>/dev/null || {
93-
echo "Note: generate-xcodeproj not available, will try opening package directly..."
94-
}
95-
96-
if [ -f "${PACKAGE_NAME}.xcodeproj/project.pbxproj" ]; then
97-
BUILD_CMD="xcodebuild docbuild -scheme ${PACKAGE_NAME} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
98-
else
99-
# Last resort: try opening the package directory as a project
100-
echo "Attempting to build documentation directly from package..."
101-
BUILD_CMD="xcodebuild -resolvePackageDependencies -packagePath ${REPO_ROOT} && xcodebuild docbuild -packagePath ${REPO_ROOT} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
102-
fi
103-
fi
104-
105-
# Execute the build command
106-
if eval "$BUILD_CMD" 2>&1; then
107-
echo -e "${GREEN}DocC documentation built successfully${NC}"
108-
109-
# Find the .doccarchive
110-
DOCS_ARCHIVE=$(find "$DOCBUILD_DIR" -name "*.doccarchive" -type d | head -1)
81+
# Generate documentation using swift package generate-documentation
82+
# This requires the swift-docc-plugin to be added to Package.swift
83+
if swift package --allow-writing-to-directory "$DOCBUILD_DIR" \
84+
generate-documentation \
85+
--target "$PACKAGE_NAME" \
86+
--output-path "$DOCBUILD_DIR" \
87+
--transform-for-static-hosting \
88+
--hosting-base-path "/${PACKAGE_NAME,,}" 2>&1; then
89+
echo -e "${GREEN}DocC documentation generated successfully${NC}"
11190

112-
if [ -z "$DOCS_ARCHIVE" ]; then
113-
# Try alternative location
114-
DOCS_ARCHIVE=$(find "$DOCBUILD_DIR" -name "*.doccarchive" -type d | head -1)
115-
fi
91+
# The documentation is already transformed for static hosting in DOCBUILD_DIR
92+
STATIC_DOCS_DIR="$DOCBUILD_DIR"
11693

117-
if [ -n "$DOCS_ARCHIVE" ] && [ -d "$DOCS_ARCHIVE" ]; then
118-
echo "Found DocC archive: $DOCS_ARCHIVE"
119-
120-
# Transform archive for static hosting
121-
STATIC_DOCS_DIR="${REPO_ROOT}/.static-docs"
122-
rm -rf "$STATIC_DOCS_DIR"
123-
mkdir -p "$STATIC_DOCS_DIR"
124-
125-
echo "Transforming archive for static hosting..."
126-
if command -v docc >/dev/null 2>&1; then
127-
docc process-archive transform-for-static-hosting \
128-
"$DOCS_ARCHIVE" \
129-
--output-path "$STATIC_DOCS_DIR" \
130-
--hosting-base-path "/${PACKAGE_NAME,,}" || {
131-
echo -e "${YELLOW}Warning: docc transform failed, using archive directly${NC}"
132-
STATIC_DOCS_DIR="$DOCS_ARCHIVE"
133-
}
134-
else
135-
echo -e "${YELLOW}Warning: docc command not found, using archive directly${NC}"
136-
STATIC_DOCS_DIR="$DOCS_ARCHIVE"
137-
fi
94+
if [ -d "$STATIC_DOCS_DIR" ] && [ -n "$(ls -A "$STATIC_DOCS_DIR" 2>/dev/null)" ]; then
95+
echo "Found generated documentation in: $STATIC_DOCS_DIR"
13896
else
139-
echo -e "${YELLOW}DocC archive not found, creating static fallback site${NC}"
97+
echo -e "${YELLOW}Documentation directory is empty, creating static fallback site${NC}"
14098
STATIC_DOCS_DIR=""
14199
fi
142100
else
143-
echo -e "${YELLOW}xcodebuild docbuild failed, creating static fallback site${NC}"
101+
echo -e "${YELLOW}swift package generate-documentation failed, creating static fallback site${NC}"
144102
STATIC_DOCS_DIR=""
145103
fi
146104

0 commit comments

Comments
 (0)