Now, let’s get to the main event. We’ll break this down into four simple steps that will take you from manual chaos to automated bliss in minutes.
Step 1: Generate Your dbt Documentation Locally (2 minutes)
First, let’s ensure you can generate the documentation on your own machine. This confirms your dbt project is set up correctly and helps you understand what files we’ll be automating.
Navigate to your dbt project’s root directory in your terminal and run the core documentation command:
dbt docs generate
This command compiles your project and generates a set of static HTML and JSON files that make up your documentation site. Once it completes, you’ll find these files inside the target/ directory. The key files are:
- index.html: The main entry point for your documentation site.
- manifest.json: A machine-readable JSON file containing information about your dbt project resources.
- catalog.json: A JSON file with metadata about your database objects.
You can open the target/index.html file in a web browser to see the local version of your documentation. Our goal is to get this exact site onto a public URL.
Step 2: Configure Your GitHub Repository for GitHub Pages (3 minutes)
Next, we need to tell GitHub where to find the files for your documentation website. We will configure it to serve files from a specific branch called gh-pages. While this branch doesn’t exist yet, our automation will create and populate it for us later.
- In your GitHub repository, go to the Settings tab.
- In the left sidebar, click on Pages.
- Under the “Build and deployment” section, for the Source, select Deploy from a branch.
- Under “Branch,” select gh-pages and keep the folder as / (root). If gh-pages isn’t an option yet, don’t worry. You can type it in, or simply wait for our workflow to create it in the next step.
- Click Save.
Your repository is now ready to host a site. All we need to do is push our documentation files to that gh-pages branch.
Step 3: Create the GitHub Actions Workflow for Automation (8 minutes)
This is the heart of our automation. We will create a GitHub Actions workflow. This is a small YAML file that tells GitHub what commands to run whenever we push code to our main branch.
- In your code editor, create a new directory structure in your dbt project’s root: .github/workflows/.
- Inside that workflows directory, create a new file named publish-docs.yml.
- Copy and paste the following code into publish-docs.yml. Here’s the exact YAML configuration we recommend for a robust setup: