The user wants a documentation-as-code (DaC) workflow. This implies treating documentation like software code: storing it in a version control system (like Git), using code review processes, automating testing/linting, and deploying it via CI/CD pipelines.
The request asks for specific components:
Lint Rules: Automated checks for style, grammar, formatting, and broken links.
Ownership: A clear system defining who is responsible for specific parts of the documentation.
Preview Deployments: Automatically generating a live preview of changes for every pull request (PR).
SLOs (Service Level Objectives): Defining reliability or quality targets for the documentation service (e.g., uptime, update latency).
Target Audience: Engineering teams or Technical Writers looking to implement a robust documentation system.
Tone: Professional, technical, structured, and actionable.
Structure of the Response:
I should organize this as a comprehensive guide or a blueprint.
Introduction: Briefly explain the philosophy of DaC.
The Stack (Assumptions): I need to pick a representative stack to make the examples concrete. A common choice is:
Repo: GitHub
Format: Markdown (MDX)
Static Site Generator (SSG): VitePress, Docusaurus, or MkDocs (I'll choose a generic approach but lean towards Markdown/Mermaid).
Implementation: Configuration files (vale.ini, .markdownlint.json) and CI steps.
Component 2: Ownership (CODEOWNERS):
Mechanism: GitHub's CODEOWNERS file.
Structure: Mapping paths to teams/users.
Integration: Requiring reviews from owners.
Component 3: Preview Deployments:
Mechanism: CI/CD workflow triggers on Pull Requests.
Tools: Vercel/Netlify (easiest) or custom cloud storage (S3 + CloudFront).
Outcome: A comment on the PR with a link to the preview URL.
Component 4: SLOs (Service Level Objectives):
Define: Availability (Uptime), Latency (Load time), Freshness (Time to update).
Measurement: Monitoring tools (Sentry, Datadog, or Vercel Analytics).
Workflow Diagram: A visual representation of the process (from Commit to Merge).
Summary/Checklist: A quick recap.
Drafting the Content - Details & Refinements:
Linting: Vale is great for enforcing style guides (Google, Microsoft, or custom). I should provide a sample rule.
Ownership: Emphasize that CODEOWNERS isn't just for code; it's crucial for docs to ensure the right SMEs (Subject Matter Experts) review API changes, for example.
Previews: Explain why this matters (visual regression testing, link checking).
SLOs: This is often overlooked in docs. I need to define what an SLO looks like for a static site. "Freshness" is a specific docs SLO—how long does it take for a merged PR to appear on the live site?
Refining the "SLOs" section:
Standard SLOs usually apply to the website serving the docs (Availability, Latency).
However, there are "Documentation Quality" SLOs that are arguably more important for DaC:
Coverage: % of APIs documented.
Freshness: Time between code release and docs update.
Broken Links: 0 tolerance policy in CI.
I will stick to the user's prompt order but expand SLOs to cover both system health and content freshness.
Self-Correction during drafting:
Initial thought: Just list tools.
Correction: The user wants a workflow. I need to show how these connect. I will provide file structures and CI snippets.
Plan:
Architecture Overview: High-level diagram (ASCII or description).
Step 1: Repo Structure & Ownership (The "Code" part).
Step 2: Linting & Validation (The "CI" part).
Step 3: Preview Deployments (The "CD" part).
Step 4: SLOs & Monitoring (The "Ops" part).
Let's write the response. I will assume a GitHub-centric workflow as it's the industry standard for DaC.
Linting details: Use markdownlint for syntax, vale for prose (e.g., "avoid passive voice").
Ownership details: Use CODEOWNERS to route API docs to Backend team and UI docs to Frontend team.
Preview details: Mention Netlify/Vercel for ease of use, or GH Pages for cost.
SLO details:
Availability: 99.9%.
Latency: < 500ms TTFB.
Docs specific: Update latency < 5 mins.
Final Polish: Ensure clear headings, code blocks for config examples, and a conclusion that ties it all together. The tone should be authoritative yet practical.
(Self-Correction on SLOs): The user specifically asked for SLOs for the workflow. That might mean "Time to First Review" or "Merge Frequency". But usually, in DevOps contexts, SLOs refer to the service reliability. I will cover both Service SLOs (Site speed) and Workflow SLOs (Time to deploy).
Let's execute.
This guide outlines a comprehensive Documentation-as-Code (DaC) workflow. This approach treats documentation with the same rigor as software, utilizing version control, automated testing, and continuous deployment.
We will assume a standard stack: Markdown/Mermaid for content, Git for version control, GitHub/GitLab for hosting, and a Static Site Generator (SSG) like VitePress, Docusaurus, or MkDocs.
1. Architecture Overview
The workflow follows the standard "Left-to-Right" DevOps cycle:
Author: Write in Markdown/MDX within the code repository (or a dedicated docs repo).
Validate (CI): Run linters, spell checkers, and link checkers on Pull Requests.
Review: Enforce Ownership rules (CODEOWNERS).
Deploy (CD):
Branch→Preview Deployment (Surge/Netlify/Vercel).
Main→Production Deployment.
2. The Workflow Setup
A. Repository Structure
Ideally, documentation lives in the same repository as the code it describes ("Docs like Code"), or in a dedicated monorepo.
Linting ensures consistency in style, formatting, and validity. We use three layers of checks.
Layer 1: Formatting (MarkdownLint)
Ensures consistent Markdown syntax (e.g., header styles, line lengths).
Tool:markdownlint-cli
Config (.markdownlint.json):
json
{
"default": true,
"MD013": false, // Disable line-length strictness
"MD033": false, // Allow inline HTML (common in React components)
"MD001": true // Headers should increment by 1
}
Layer 2: Prose & Style (Vale)
Enforces voice, tone, and grammar (e.g., "avoid passive voice," "no weasel words").
Tool:Vale
Config (.vale.ini):
ini
StylesPath = .vale/styles
MinAlertLevel = warning
[*.md]
BasedOnStyles = Vale, Google
Vale.Terms = NO # Disable specific terminology checks if needed
Google.Passive = error # Flag passive voice as an error
Layer 3: Validity (Link Checks)
Ensures no 404s exist within the documentation or linking to external sites.
To prevent documentation from becoming stale, ownership must be explicit. We use the CODEOWNERS file standard.
The CODEOWNERS file
Located in .github/CODEOWNERS (or root), this file forces specific teams to review changes to specific folders.
text
# .github/CODEOWNERS
# The API team must approve changes to API references
/docs/api/ @org/api-team
# The Developer Advocates own the guides
/docs/guides/ @org/devrel @org/tech-writers
# The Engineering Lead must approve architecture diagrams
/docs/architecture/ @org/cto
Workflow Result: When a PR is opened modifying /docs/api/, the @org/api-team is automatically requested for review. The PR cannot merge until they approve it.
5. Preview Deployments
Previews allow reviewers to see the rendered site (with navigation and styling) before merging code. This prevents "broken layout" surprises.
Strategy
Trigger: Pull Request opened.
Action: Build the static site to a temporary directory.
Host: Upload to a staging platform (Vercel, Netlify, or S3).
Comment: A bot comments on the PR with the unique URL.
GitHub Actions Implementation
yaml
# .github/workflows/docs-preview.yml
name: Docs Preview
on: pull_request
jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Install & Build
run: |
npm install
npm run build:docs # Output usually in ./dist or ./site
- name: Deploy to Preview Environment
# Example using a generic S3 uploader or Netlify CLI
run: |
# Logic to upload ./dist to a unique URL based on PR ID
# e.g., pr-1234.docs-preview.mycompany.com
- name: Comment on PR
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "📚 Docs Preview is ready! \n 🔗 https://pr-${{ github.event.pull_request.number }}.docs-preview.mycompany.com"
})
6. Service Level Objectives (SLOs)
Documentation is a product; therefore, it needs SLOs to measure reliability and usefulness.
SLO 1: Availability (Uptime)
The documentation site must be reachable.
Target: 99.9% Uptime.
Measurement: Synthetic monitoring (Pingdom, Datadog) pinging the root URL every 5 minutes.
SLO 2: Freshness (Latency to Production)
How long does it take for a documentation fix to reach the user?
Target: Documentation changes related to a software release must be live within 1 hour of the code merge.
Measurement: CI/CD timestamps (Tmerge) vs. CDN invalidation timestamp (Tdeploy).
SLO 3: Coverage (API Parity)
Are all public endpoints documented?
Target: 100% of OpenAPI/Swagger endpoints must have a corresponding Markdown guide or reference page.
Measurement: Automated script comparing the OpenAPI spec routes against the docs file structure.
SLO 4: Feedback Loop (User Satisfaction)
Target: "Was this page helpful?" score > 90%.
Implementation: Add a simple binary feedback component at the bottom of every page.
Measurement: Aggregate analytics (Google Analytics / Plausible) on positive vs. negative clicks.
Summary Checklist
To implement this workflow, complete the following:
Repo Setup: Create a /docs directory.
Linting: Add markdownlint, vale, and linkinator configs.
CI: Create the Linting workflow to run on PRs.
Ownership: Create the CODEOWNERS file mapping folders to GitHub teams.
CD: Connect the repo to Vercel/Netlify to enable automatic Preview Deployments.
SLOs: Configure a monitor for the production domain and a "Is this helpful?" button.