Generate content from code

Some projects may benefit from having part of the documentation generated automatically from code. This removes the need to manually keep code and documentation in sync. An example project that does this is the Fresh App Factory.

  1. Create a script to generate the partial file.

    #!/bin/bash
    # update-docs.sh
    echo generated content > docs/modules/ROOT/partials/contents.adoc
  2. Include the partial into a documentation page.

    include::partial$contents.adoc[]
  3. Create a GitHub Actions workflow to keep the repo in sync.

    # .github/workflows/docs.yml
    name: Update docs
    on:
      push:
        branches:
          - 'main'
      workflow_dispatch:
    jobs:
      docs:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          - run: ./update-docs.sh
          - uses: stefanzweifel/git-auto-commit-action@v4
            with:
              commit_message: Update documentation
              commit_user_name: dtinth-bot
              commit_user_email: dtinth-bot@users.noreply.github.com
              commit_author: dtinth-bot <dtinth-bot@users.noreply.github.com>