DOCS
AS
CODE

Carl Chesser
@che55er | che55er.io

About Me







Guides

through drawings

Topics

πŸ” Introduction Β  πŸ“š Background Β  πŸš€ Examples

Fantastic resource πŸ‘‡

Docs as Code?

Documentation as Code (Docs as Code) refers to a philosophy that you should be writing documentation with the same tools as code.

Source: Write the Docs

Docs as Code uses...

Source: Write the Docs

🐞 Issue Trackers

🌳 Version Control (git)

πŸ”€ Plain Text Markup
(Markdown, reStructuredText, Asciidoc)

πŸ’¬ Code Reviews

βœ… Automated Tests

🐞 Issue Trackers

Align tracking the work of documentation with code. (have it live in the same queue)

🌳 Version Control (git)

Enable docs and code to live in same changeset
(like your tests)

Enable concurrent development branches

🌈 Enable all the features of version control for your documentation!

πŸ”€ Plain Text Markup

Enable all the features of your code editors in documentation
(compare, find/replace, track in version control)

🌈 Many editors with preview mode for Markdown as you edit!

πŸ’¬ Code Reviews

Enable discussions with code using the same toolchain (line-by-line comments, suggestions they can apply, CODEOWNERS)

βœ… Automated Tests

Enable static analysis tests on documentation (status checks on pull requests)

Creating the Culture of Documentation


Write the Docs (Twitter, 2014)

Documentation, Disrupted

How Two Technical Writers Changed Google Engineering Culture

Write the Docs (Google, 2015)

How we are solving internal technical documentation at Spotify

Write the Docs (Spotify, 2019)

Problematic Signals

🏝 Islands of documentation
(MediaWiki, Confluence, Office 365, READMEs, GitHub Pages)

πŸ“œ Excessive documentation decay
(possibly caused by islands)

πŸ” Searchability challenges

πŸ€·β€β™‚οΈ Different process for maintaining (vs. with code)

😐 Lack of trust on the content

🏝 Islands of documentation
(MediaWiki, Confluence, Office 365, READMEs, GitHub Pages)
πŸ“œ Documentation decay due to islands
πŸ” Searchability challenges

🏝 Islands of documentation
(MediaWiki, Confluence, Office 365, READMEs, GitHub Pages)
πŸ“œ Documentation decay due to islands
πŸ” Searchability challenges

🌎 A centralized build system for documentation that can enable content through a common convention

πŸ€·β€β™‚οΈ Different process for maintaining (vs. with code)

πŸ€·β€β™‚οΈ Different process for maintaining (vs. with code)

🧰 Enable documentation to exist closer to the code and toolchain

😐 Lack of trust on the content

😐 Lack of trust on the content

πŸͺ„ Make it easy for anyone to contribute
help them along the way, like DocDays!

But, not everyone has GitHub access…

or knows Markdown.
πŸ€·β€β™‚οΈ

🧩

Ensure approach aligns with strategy for expected toolchain access
(GitHub Enterprise)

πŸ”€

Illustrate through examples that if you know text,
you can write Markdown
Majority of contributions = textual content, β‰  formatting

πŸš€

Examples

πŸ”€ Markdown: Authoring

βš™οΈ Hugo: Generating

πŸ‘” Docsy: Theming

⚑️ GitHub Actions: Building

πŸ“‘ GitHub Pages: Serving

πŸ”€

Markdown

Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents. Created by John Gruber in 2004, Markdown is now one of the world’s most popular markup languages.

Source: The Markdown Guide

Editing

Great resource πŸ‘‡

The world’s fastest framework for building websites

https://gohugo.io/

Hugo Features

πŸ¦„ Shortcodes
Powerful way to extend beyond Markdown with reusable code blocks

πŸͺ΄ Multiple Formats
Hugo allows you to output your content in multiple formats...like this presentation

πŸ¦₯ Flexible
Build different types of content (menus, diagrams) to make a rich website out of Markdown

⚑️ Speed
At < 1 ms per page, the average site builds in less than a second

A Hugo theme for creating great technical documentation sites

πŸ‘”

Docsy Examples

πŸ¦„

Shortcodes

Generate API documentation from your OpenAPI (Swagger) specifications.

{{< swaggerui src="/openapi/petstore.yaml" >}}

πŸ§œβ€β™€οΈ

Diagrams: Mermaid


```mermaid
graph LR
  Start --> Need{"Do I need diagrams"}
  Need -- No --> Off["Set params.mermaid.enable = false"]
  Need -- Yes --> HaveFun["Great!  Enjoy!"]
```

GitHub Actions

Build your docs!

Include in .github/workflows/gh-pages.yaml file.

name: github pages

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-20.04
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: recursive  # Fetch the Docsy theme
          fetch-depth: 0         # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          # Can pin to a specific version if needed, ex:
          # hugo-version: '0.79.1'
          hugo-version: 'latest'
          extended: true

      - name: Setup Node
        uses: actions/setup-node@v2
        with:
          node-version: '14'

      - name: Cache dependencies
        uses: actions/cache@v1
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - run: npm ci
      - run: hugo
        env:
          HUGO_ENV: production

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        if: ${{ github.ref == 'refs/heads/main' }}
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_branch: gh-pages

GitHub Actions

Test your docs (spellcheck)!

Include in .github/workflows/validation.yaml file.

name: validation

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  spell-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        name: Check out the code
      - uses: actions/setup-node@v1
        name: Run spell check
        with:
          node-version: "12"
      - run: npm install -g cspell
      - run: cspell lint --config .github/cspell.json "content/**/*.md"

GitHub Actions

βœ… Enforce your tests in pull requests

πŸ“‘

GitHub Pages

βš’οΈ GitHub Actions build content on PRs and main

πŸ§† Generate and store static content for serving

πŸ§ͺ

Try it out!

https://cchesser.github.io/docs-as-code/

✍️ Try the Edit this Page link to make a change via a PR

βš™οΈ See build process on pull request and preview

Recap

πŸ““ Definition and approach

πŸ“š Background of how others have approached it

❀️ Benefits and how it lends to common problems in documentation

πŸš€ Examples with: Markdown, Hugo, Docsy, GitHub, GitHub Actions, GitHub Pages

Thank You

Thank
You!

Carl Chesser
@che55er | che55er.io