This guide explains how to set up and use the rustdoc documentation generation and GitHub Pages deployment for this project.
The project uses:
- rustdoc for API documentation generation
- GitHub Actions for automated builds and deployment
- GitHub Pages for hosting the documentation
- Nix for local documentation generation
Using Nix (recommended):
# Build and open documentation in your browser
nix run .#docs
# Or build documentation manually
cargo doc --all-features --no-deps --document-private-items --openUsing cargo directly:
# Generate and open documentation
cargo doc --all-features --open
# Generate with private items (internal docs)
cargo doc --all-features --document-private-items --open
# Generate with docs.rs style
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --open# Build the documentation package
nix build .#docs
# View the generated documentation
firefox ./result/share/doc/index.html-
Enable GitHub Pages in Repository Settings
- Go to:
Settings→Pages - Under "Source", select: GitHub Actions
- Save the settings
- Go to:
-
Trigger Documentation Build
- Push to the
mainbranch - Or manually trigger:
Actions→Documentation→Run workflow
- Push to the
-
Access Your Documentation
- Once deployed, documentation will be available at:
https://<org>.github.io/<repo>/- Example:
https://singularity-ng.github.io/singularity-language-registry/
- Once deployed, documentation will be available at:
-
Verify GitHub Pages is Enabled
- Check with your GitHub Enterprise administrator
- GitHub Pages must be enabled at the enterprise or organization level
-
Enable in Repository Settings
- Go to:
Settings→Pages - Under "Source", select: GitHub Actions
- Save the settings
- Go to:
-
Update Base URL (if needed)
- If your GitHub Enterprise uses a custom domain, update the documentation URL in
Cargo.toml:
[package] documentation = "https://<your-gh-enterprise-domain>/pages/<org>/<repo>/"
- If your GitHub Enterprise uses a custom domain, update the documentation URL in
-
Trigger Documentation Build
- Push to the
mainbranch - Or manually trigger the workflow
- Push to the
The documentation workflow (.github/workflows/docs.yml) runs when:
- Code is pushed to the
mainbranch - Documentation-related files are modified (
src/**,Cargo.toml) - Manually triggered via GitHub Actions UI
-
Build Documentation
- Uses
cargo +nightly docfor advanced features - Enables
--document-private-itemsfor complete API coverage - Applies docs.rs styling with
--cfg docsrs - Generates documentation for all features
- Uses
-
Create Landing Page
- Auto-generates
index.htmlthat redirects to the crate documentation - Adds
.nojekyllfile to disable Jekyll processing
- Auto-generates
-
Deploy to GitHub Pages
- Uploads documentation artifacts
- Deploys to GitHub Pages environment
- Provides deployment URL in workflow summary
The project includes metadata for optimal documentation:
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]This enables:
- All feature flags in documentation
- docs.rs-style conditional compilation
- Code example scraping (nightly feature)
-
Document Public APIs
/// Brief one-line description. /// /// Detailed explanation with examples. /// /// # Examples /// /// ``` /// use singularity_language_registry::Language; /// let lang = Language::new("Rust"); /// ``` pub struct Language { }
-
Use Doc Links
/// See [`Language`] for more information. /// Check the [`detect`] function for usage.
-
Add Examples
- Document examples with
///or//! - Use
# Examplessection in doc comments - Add doctests that are automatically run by
cargo test
- Document examples with
The flake provides:
nix build .#docs- Build documentation package
nix run .#docs- Build and open documentation in browser
nix flake check- Runsdoccheck to ensure documentation builds
The development shell includes rustdoc and related tools:
nix develop
cargo doc --open-
Check for doc warnings
RUSTDOCFLAGS="-D warnings" cargo doc --all-features -
Fix broken doc links
- Ensure all
[links]in documentation are valid - Use
cargo rustdocfor detailed error messages
- Ensure all
-
Check feature flags
- Some docs may require specific features
- Use
--all-featuresto include everything
-
Verify workflow ran successfully
- Check
Actionstab for workflow status - Review logs for any errors
- Check
-
Check GitHub Pages settings
- Ensure "Source" is set to "GitHub Actions"
- Verify GitHub Pages is enabled for your organization/enterprise
-
Clear browser cache
- GitHub Pages may cache old content
- Hard refresh:
Ctrl+Shift+R(Linux/Windows) orCmd+Shift+R(Mac)
If deployment fails with permission errors:
-
Check repository settings
- Go to:
Settings→Actions→General - Under "Workflow permissions", select: Read and write permissions
- Enable: Allow GitHub Actions to create and approve pull requests
- Go to:
-
Verify Pages permissions
- The workflow requires
pages: writeandid-token: write - These are set in the workflow file
- The workflow requires
For testing or one-off deployments:
# Build documentation
cargo doc --all-features --no-deps
# Add redirect index page
cat > target/doc/index.html <<'EOF'
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=singularity_language_registry/index.html">
<title>Redirecting...</title>
</head>
<body>
<p>Redirecting to <a href="singularity_language_registry/index.html">documentation</a>...</p>
</body>
</html>
EOF
# Add .nojekyll
touch target/doc/.nojekyll
# Deploy manually (using gh-pages or your preferred method)Documentation is also checked in the main CI workflow (.github/workflows/ci.yml):
- name: Check documentation
run: cargo doc --all-features --no-depsThis ensures documentation always builds successfully before merging PRs.
For issues specific to:
- Documentation generation: Check rustdoc errors with
cargo doc --verbose - GitHub Actions: Review workflow logs in the Actions tab
- GitHub Pages: Verify settings and consult GitHub Enterprise admin
- Nix builds: Run
nix flake checkfor detailed diagnostics