skip to Main Content

So I have been browsing the web for a while now and can’t seem to find an answer on how to build the native DocC Xcode documentation using a CLI command.

Both the xcodebuild commands and Fastlane do not provide a command to build the documentation – as far as I know.

The docs are supposed to be built inside a CI/CD Github Actions workflow. If there are other methods to accomplish this, any help is appreciated.

3

Answers


  1. Chosen as BEST ANSWER

    Apple has added a new command to xcodebuild tools:

    xcodebuild docbuild
    

    You can also take a look at the WWDC presentation "Host and automate your DocC documentation". Start watching from 7:06 min onwards for DocC automation: https://developer.apple.com/videos/play/wwdc2021/10236/


  2. To complement the initial answer, I’d like to mention this complete summary of all the WWDC21 videos regarding DocC that contains precious information about automation. 🤓

    Indeed, there’s a feature in Xcode 13 for building documentation through the command line that includes the docbuild action with many possible options as described below. 🤩
    enter image description here
    Besides, Xcode 14 fosters the DocC archive content deployment at the root of a web server thanks to its new compatibility with most web servers. 🤩
    enter image description here

    Even if a solution has already been provided by @Colin 👍, I deemed it important to append some information that may be crucial for some. 😉

    Login or Signup to reply.
  3. Host and Automate your DocC documentation ☁️

    Tl;dr

    I tweaked the xcodebuild docbuild for modular projects as below:

    xcodebuild -project ModularSlothCreator.xcodeproj -derivedDataPath docsData -scheme ModularSlothCreator -destination 'platform=iOS Simulator,name=iPhone 13 Pro Max' -parallelizeTargets docbuild
    

    I also tweaked the docc site generation using the transform-for-static-hosting flag:

    $(xcrun --find docc) process-archive transform-for-static-hosting "$ARCHIVE" --hosting-base-path ModularSlothCreator/$ARCHIVE_NAME --output-path docs/$ARCHIVE_NAME
    

    BONUS: Automate DocC with GitHub Pages and CI 🍀

    I’ve updated the original demo showcased at WWDC with support for static hosting of modular App targets (rather than only supporting a single Swift Package announced at WWDC) using GitHub Pages without needing to define a server configuration for convenience in my blog post.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search