Skip to content

Commit 544f064

Browse files
authored
Merge pull request #1 from rfdearborn/rfdearborn/initialize
Initialize!
2 parents 4b2f45d + d215540 commit 544f064

File tree

3 files changed

+578
-1
lines changed

3 files changed

+578
-1
lines changed

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
11
# dbt-docs-to-notion
2-
A github action for exporting dbt docs to a notion database
2+
A Github action for exporting dbt model docs to a Notion database, where they can be conveniently consumed (especially by casual users in your org).
3+
4+
## Output
5+
A Notion database, within a page of your choosing, with records like this:
6+
![dbt docs to notion output](https://i.imgur.com/Y1EWj9l.png)
7+
8+
## Usage
9+
### Prerequisites
10+
In advance of using this action, you should:
11+
1. [Create a new integration within your Notion workspace](https://www.notion.so/my-integrations)
12+
2. Have your Notion integration token and a working dbt `profiles.yml` accessible to your repo (I'd recommend using [Github's repository secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets); see example workflow below).
13+
### Inputs
14+
- `dbt-package`: dbt-bigquery, dbt-postgres, dbt-bigquery==1.0.0, etc. (**required**)
15+
- `dbt-profile-path`: where profile.yml lives (default: `./`)
16+
- `dbt-target`: profile target to use for dbt docs generation (**required**)
17+
- `model-records-to-write`: "all" or "model_name_1 model_name_2 ..." (default: "all")
18+
- `notion-database-name`: what to name the Notion database of dbt models (**required**)
19+
- `notion-parent-id`: Notion page where database of dbt models will be added (**required**)
20+
- `notion-token`: Notion token API for integration to use (pass using secrets) (**required**)
21+
22+
### Post-initialization Touchups
23+
Unfortunately, Notion's API doesn't allow for setting the order of properties or records in a database. Thus, after creating your database, you'll probably want to do some re-arranging (I'd recommend adding a table view to your database's parent page).
24+
25+
### Example workflow
26+
```
27+
name: dbt Docs to Notion
28+
29+
on:
30+
- pull_request
31+
32+
jobs:
33+
dbt-docs-to-notion:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v2
38+
- name: Create temp dbt profiles
39+
run: "printf %s \"$DBT_PROFILES\" > ./profiles.yml"
40+
env:
41+
DBT_PROFILES: ${{ secrets.DBT_PROFILES }}
42+
- name: dbt-docs-to-notion
43+
uses: ./.github/actions/dbt-docs-to-notion
44+
with:
45+
dbt-package: 'dbt-bigquery==1.0.0'
46+
dbt-profile-path: './'
47+
dbt-target: 'github_actions'
48+
model-records-to-write: "all"
49+
notion-database-name: 'dbt Models'
50+
notion-parent-id: 'your-page-id-here'
51+
notion-token: '${{ secrets.DBT_DOCS_TO_NOTION_TOKEN }}'
52+
```

action.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: 'dbt-docs-to-notion'
2+
description: 'Exports dbt model docs to a Notion database'
3+
branding:
4+
icon: 'book-open'
5+
color: 'orange'
6+
inputs:
7+
dbt-package:
8+
description: 'dbt-bigquery, dbt-postgres, dbt-bigquery==1.0.0, etc.'
9+
required: true
10+
dbt-profile-path:
11+
description: 'where profile.yml lives'
12+
required: false
13+
default: './'
14+
dbt-target:
15+
description: 'profile target to use for dbt docs generation'
16+
required: true
17+
model-records-to-write:
18+
description: \"all\" or \"model_name_1 model_name_2 ...\"
19+
required: false
20+
default: "all"
21+
notion-database-name:
22+
description: 'what to name the Notion database of dbt models'
23+
required: true
24+
notion-parent-id:
25+
description: 'Notion page where database of dbt models will be added'
26+
required: true
27+
notion-token:
28+
description: 'Notion token api for integration to use (pass using secrets)'
29+
required: true
30+
runs:
31+
using: 'composite'
32+
steps:
33+
- name: Install Python
34+
uses: "actions/setup-python@v2"
35+
with:
36+
python-version: "3.7"
37+
- name: Install dbt
38+
run: "pip3 install ${{ inputs.dbt-package }}"
39+
shell: bash
40+
- name: Load dbt deps
41+
run: "dbt deps --profiles-dir ${{ inputs.dbt-profile-path }} --target=${{ inputs.dbt-target }}"
42+
shell: "bash"
43+
- name: Generate dbt Docs
44+
run: "dbt docs generate --profiles-dir ${{ inputs.dbt-profile-path }} --target=${{ inputs.dbt-target }}"
45+
shell: bash
46+
- name: Export dbt Docs to Notion
47+
run: "python3 ./.github/actions/dbt-docs-to-notion/dbt_docs_to_notion.py ${{ inputs.model-records-to-write }}"
48+
shell: bash
49+
env:
50+
DATABASE_NAME: ${{ inputs.notion-database-name }}
51+
DATABASE_PARENT_ID: ${{ inputs.notion-parent-id }}
52+
NOTION_TOKEN: ${{ inputs.notion-token }}

0 commit comments

Comments
 (0)