Skip to content

Commit 3556d9d

Browse files
Turn off github workflows by default and add documentation around it (#53)
1 parent 944f230 commit 3556d9d

File tree

5 files changed

+90
-54
lines changed

5 files changed

+90
-54
lines changed

.github/workflows/dbt_ci.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
name: dbt CI
22

3-
on:
4-
pull_request:
5-
types: [opened, synchronize, reopened]
6-
paths:
7-
- 'models/**'
8-
- 'macros/**'
9-
- 'dbt_project.yml'
10-
- 'profiles.yml'
11-
- 'packages.yml'
12-
- '.github/workflows/dbt_ci.yml'
3+
# NOTE: Pull request CI jobs are disabled by default. Uncomment to enable standard CI workflows
4+
# Check the README.md to make sure you understand the credit costs associated with running dbt.
5+
# on:
6+
# pull_request:
7+
# types: [opened, synchronize, reopened]
8+
# paths:
9+
# - 'models/**'
10+
# - 'macros/**'
11+
# - 'dbt_project.yml'
12+
# - 'profiles.yml'
13+
# - 'packages.yml'
14+
# - '.github/workflows/dbt_ci.yml'
1315

1416
concurrency:
1517
group: ${{ github.workflow }}-${{ github.ref }}
@@ -19,12 +21,12 @@ jobs:
1921
dbt-ci:
2022
runs-on: ubuntu-latest
2123
timeout-minutes: 30
22-
24+
2325
env:
2426
DUNE_API_KEY: ${{ secrets.DUNE_API_KEY }}
2527
DUNE_TEAM_NAME: ${{ vars.DUNE_TEAM_NAME || 'dune' }} # Set as GitHub Variable or defaults to 'dune'
2628
DEV_SCHEMA_SUFFIX: pr${{ github.event.pull_request.number }}
27-
29+
2830
steps:
2931
- name: Check out code
3032
uses: actions/checkout@v4
@@ -86,7 +88,7 @@ jobs:
8688

8789
- name: Test modified models (after full refresh)
8890
run: uv run dbt test --select state:modified --state ./state
89-
91+
9092
- name: Run modified incremental models (incremental run)
9193
run: uv run dbt run --select state:modified,config.materialized:incremental --state ./state
9294

.github/workflows/dbt_deploy.yml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
name: dbt deploy
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
paths:
8-
- 'models/**'
9-
- 'macros/**'
10-
- 'dbt_project.yml'
11-
- 'profiles.yml'
12-
- 'packages.yml'
13-
- '.github/workflows/dbt_deploy.yml'
14-
schedule:
15-
- cron: '0 0 1 * *' # Run monthly on the 1st to refresh manifest artifact (90-day retention)
4+
# NOTE: Push and schedule triggers are disabled by default. Uncomment to enable standard CI workflows
5+
# Check the README.md to make sure you understand the credit costs associated with running dbt.
6+
# push:
7+
# branches:
8+
# - main
9+
# paths:
10+
# - 'models/**'
11+
# - 'macros/**'
12+
# - 'dbt_project.yml'
13+
# - 'profiles.yml'
14+
# - 'packages.yml'
15+
# - '.github/workflows/dbt_deploy.yml'
16+
# schedule:
17+
# - cron: '0 0 1 * *' # Run monthly on the 1st to refresh manifest artifact (90-day retention)
1618
workflow_dispatch: # Allow manual triggers
1719

1820
concurrency:
@@ -23,12 +25,12 @@ jobs:
2325
dbt-deploy:
2426
runs-on: ubuntu-latest
2527
timeout-minutes: 30
26-
28+
2729
env:
2830
DUNE_API_KEY: ${{ secrets.DUNE_API_KEY }}
2931
DUNE_TEAM_NAME: ${{ vars.DUNE_TEAM_NAME || 'dune' }} # Set as GitHub Variable or defaults to 'dune'
3032
DBT_TARGET: prod # All dbt commands will use the prod target from profiles.yml
31-
33+
3234
steps:
3335
- name: Check out code
3436
uses: actions/checkout@v4

.github/workflows/dbt_prod.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
# schedule:
55
# - cron: '0 * * * *' # Run every hour at minute 0
66
# NOTE: Schedule is disabled by default. Uncomment when ready to enable hourly production runs.
7+
# Check the README.md to make sure you understand the credit costs associated with running dbt.
78
workflow_dispatch: # Allow manual triggers
89

910
concurrency:
@@ -14,12 +15,12 @@ jobs:
1415
dbt-prod:
1516
runs-on: ubuntu-latest
1617
timeout-minutes: 30
17-
18+
1819
env:
1920
DUNE_API_KEY: ${{ secrets.DUNE_API_KEY }}
2021
DUNE_TEAM_NAME: ${{ vars.DUNE_TEAM_NAME || 'dune' }} # Set as GitHub Variable or defaults to 'dune'
2122
DBT_TARGET: prod # All dbt commands will use the prod target from profiles.yml
22-
23+
2324
steps:
2425
- name: Check out code
2526
uses: actions/checkout@v4

README.md

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ A dbt project template for Dune using Trino and uv for Python package management
66
77
[![Latest Release](https://img.shields.io/github/v/release/duneanalytics/dune-dbt-template?label=latest%20release)](https://github.com/duneanalytics/dune-dbt-template/releases) | [CHANGELOG](CHANGELOG.md)
88

9+
## ⚠️ NOTE ⚠️
10+
11+
Running dbt models on Dune from automated pipelines can quickly consume a lot of credits on Dune.
12+
We have disabled the CI workflows in this repo by default to prevent accidents.
13+
Please check the **[Development Workflow](docs/development-workflow.md)** doc for more information.
14+
15+
When you're ready to enable automated dbt runs on PRs, pushes to main, or a schedule, uncomment the triggers in the github workflow files:
16+
17+
- [Pull Request CI](./.github/workflows/dbt_ci.yml)
18+
- [Deploy on merge](./.github/workflows/dbt_deploy.yml)
19+
- [Scheduled incremental runs](./.github/workflows/dbt_prod.yml)
20+
921
## 📚 Documentation
1022

1123
**New to this repo?** See the [docs/](docs/) directory for complete guides:
@@ -29,15 +41,15 @@ uv sync
2941

3042
**Required variables:**
3143

32-
| Variable | Description | Where to Get |
33-
|----------|-------------|--------------|
34-
| `DUNE_API_KEY` | Your Dune API key for authentication | [dune.com/settings/api](https://dune.com/settings/api) |
35-
| `DUNE_TEAM_NAME` | Your team name (determines schema where models are written) | Your Dune team name |
44+
| Variable | Description | Where to Get |
45+
| ---------------- | ----------------------------------------------------------- | ------------------------------------------------------ |
46+
| `DUNE_API_KEY` | Your Dune API key for authentication | [dune.com/settings/api](https://dune.com/settings/api) |
47+
| `DUNE_TEAM_NAME` | Your team name (determines schema where models are written) | Your Dune team name |
3648

3749
**Optional variables:**
3850

39-
| Variable | Description | Default |
40-
|----------|-------------|---------|
51+
| Variable | Description | Default |
52+
| ------------------- | ----------------------------------------------------------- | -------------------------- |
4153
| `DEV_SCHEMA_SUFFIX` | Personal dev schema suffix (creates `{team}__tmp_{suffix}`) | None (uses `{team}__tmp_`) |
4254

4355
See [Getting Started](docs/getting-started.md#2-set-environment-variables) for multiple options to set these variables (shell profile, session export, or inline).
@@ -54,12 +66,14 @@ uv run dbt test # Run tests
5466
### Target Configuration
5567

5668
This project uses dbt targets to control **schema naming**, not API endpoints:
69+
5770
- Both `dev` and `prod` targets connect to the **same production API** (`trino.api.dune.com`)
5871
- Target names control where models are written:
5972
- **`dev` target** (default): Writes to `{team}__tmp_` schemas (safe for development)
6073
- **`prod` target**: Writes to `{team}` schemas (production tables)
6174

6275
**Local development** uses `dev` target by default. To test with prod target locally:
76+
6377
```bash
6478
uv run dbt run --target prod # Use prod schema naming
6579
```
@@ -81,6 +95,7 @@ DEV_SCHEMA_SUFFIX=your_name uv run dbt run
8195
```
8296

8397
To disable suffix after using it:
98+
8499
```bash
85100
unset DEV_SCHEMA_SUFFIX
86101
```
@@ -127,13 +142,13 @@ select * from dune.dune__tmp_.dbt_template_view_model
127142

128143
## Model Templates
129144

130-
| Type | File | Use Case |
131-
|------|------|----------|
132-
| View | `dbt_template_view_model.sql` | Lightweight, always fresh |
133-
| Table | `dbt_template_table_model.sql` | Static snapshots |
134-
| Incremental (Merge) | `dbt_template_merge_incremental_model.sql` | Efficient updates via merge |
145+
| Type | File | Use Case |
146+
| --------------------------- | -------------------------------------------------- | ----------------------------------- |
147+
| View | `dbt_template_view_model.sql` | Lightweight, always fresh |
148+
| Table | `dbt_template_table_model.sql` | Static snapshots |
149+
| Incremental (Merge) | `dbt_template_merge_incremental_model.sql` | Efficient updates via merge |
135150
| Incremental (Delete+Insert) | `dbt_template_delete_insert_incremental_model.sql` | Efficient updates via delete+insert |
136-
| Incremental (Append) | `dbt_template_append_incremental_model.sql` | Append-only with deduplication |
151+
| Incremental (Append) | `dbt_template_append_incremental_model.sql` | Append-only with deduplication |
137152

138153
All templates are in `models/templates/`.
139154

@@ -146,6 +161,7 @@ Runs on every PR. Enforces branch is up-to-date with main, then runs and tests m
146161
**Target:** Uses `dev` target with `DEV_SCHEMA_SUFFIX=pr{number}` for isolated testing
147162

148163
**Steps:**
164+
149165
1. Enforces branch is up-to-date with main
150166
2. Runs modified models with full refresh
151167
3. Tests modified models
@@ -161,6 +177,7 @@ Runs hourly on main branch. Uses state comparison to only full refresh modified
161177
**Target:** Sets `DBT_TARGET: prod` to write to production schemas (`{team}`)
162178

163179
**Steps:**
180+
164181
1. Downloads previous manifest (if exists)
165182
2. **If state exists:** Runs modified models with full refresh and tests
166183
3. Runs all models (handles incremental logic)
@@ -173,23 +190,27 @@ Runs hourly on main branch. Uses state comparison to only full refresh modified
173190
### GitHub Setup
174191

175192
**Required:**
193+
176194
1. Add Secret: `DUNE_API_KEY` (Settings → Secrets and variables → Actions → Secrets)
177195
2. Add Variable: `DUNE_TEAM_NAME` (Settings → Secrets and variables → Actions → Variables)
178196
- Optional, defaults to `'dune'` if not set
179197

180198
**Recommended:**
199+
181200
1. **Public repos:** Require approval for outside contributor workflows (Settings → Actions → General → Fork pull request workflows)
182201
- Protects secrets from unauthorized access
183202
- See [SETUP_FOR_NEW_TEAMS.md](SETUP_FOR_NEW_TEAMS.md#fork-pull-request-workflow-permissions-required-for-public-repos) for details
184203

185204
**Email notifications:**
205+
186206
1. Enable workflow notifications: Profile → Settings → Notifications → Actions → "Notify me for failed workflows only"
187207
2. Verify email address is set
188208
3. Watch repository: Click "Watch" (any level works, even "Participating and @mentions")
189209

190210
## Troubleshooting
191211

192212
**Environment variables not set:**
213+
193214
```bash
194215
# Verify variables are set
195216
env | grep DUNE_API_KEY
@@ -201,16 +222,19 @@ export DUNE_TEAM_NAME=your_team_name
201222
```
202223

203224
**Connection errors:**
225+
204226
```bash
205227
uv run dbt debug # Test connection and check for errors
206228
```
207229

208230
**dbt_utils not found:**
231+
209232
```bash
210233
uv run dbt deps
211234
```
212235

213236
**Dependency issues:**
237+
214238
```bash
215239
uv sync --reinstall
216240
```
@@ -235,12 +259,12 @@ dbt_project.yml # Project configuration
235259

236260
The `get_custom_schema.sql` macro determines where models are written based on the dbt target:
237261

238-
| Target | DEV_SCHEMA_SUFFIX | Schema Name | Use Case |
239-
|--------|-------------------|-------------|----------|
240-
| `prod` | (any) | `{team}` | Production tables |
241-
| `dev` | Not set | `{team}__tmp_` | Local development |
242-
| `dev` | Set to `pr123` | `{team}__tmp_pr123` | CI/CD per PR |
243-
| `dev` | Set to `alice` | `{team}__tmp_alice` | Personal dev space |
262+
| Target | DEV_SCHEMA_SUFFIX | Schema Name | Use Case |
263+
| ------ | ----------------- | ------------------- | ------------------ |
264+
| `prod` | (any) | `{team}` | Production tables |
265+
| `dev` | Not set | `{team}__tmp_` | Local development |
266+
| `dev` | Set to `pr123` | `{team}__tmp_pr123` | CI/CD per PR |
267+
| `dev` | Set to `alice` | `{team}__tmp_alice` | Personal dev space |
244268

245269
This ensures safe isolation between development and production environments.
246270

docs/cicd.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Continuous integration and deployment via GitHub Actions.
44

55
## GitHub-Hosted Runners
66

7-
This template uses **GitHub-hosted runners** (`ubuntu-latest`) to execute CI/CD workflows.
7+
This template uses **GitHub-hosted runners** (`ubuntu-latest`) to execute CI/CD workflows.
88

99
GitHub provides and manages these runners - no infrastructure setup required on your end.
1010

1111
## Pull Request Workflow (CI)
1212

13-
**Trigger:** Every pull request
13+
**Trigger:** Every pull request
1414
**File:** `.github/workflows/dbt_run.yml`
1515

1616
### What It Does
@@ -37,13 +37,15 @@ This is set via `DEV_SCHEMA_SUFFIX=pr{number}` environment variable.
3737
### How to Pass CI
3838

3939
**Keep branch updated:**
40+
4041
```bash
4142
git fetch origin
4243
git merge origin/main
4344
git push
4445
```
4546

4647
**Test locally before pushing:**
48+
4749
```bash
4850
uv run dbt run --select modified_model --full-refresh
4951
uv run dbt test --select modified_model
@@ -53,8 +55,8 @@ uv run dbt test --select modified_model
5355

5456
## Production Workflow
5557

56-
**Trigger:** Manual (schedule disabled by default)
57-
**File:** `.github/workflows/dbt_prod.yml`
58+
**Trigger:** Manual (schedule disabled by default)
59+
**File:** `.github/workflows/dbt_prod.yml`
5860
**Branch:** `main` only
5961

6062
⚠️ **Note:** The hourly schedule is **disabled by default** in the template. Teams must uncomment the schedule in the workflow file when ready to enable automatic hourly runs.
@@ -79,6 +81,7 @@ The workflow saves `manifest.json` after each run and downloads it next time to
7981
### Target Configuration
8082

8183
Production runs use `DBT_TARGET=prod`:
84+
8285
- Writes to `{team}` schemas (production)
8386
- No suffix applied
8487

@@ -102,25 +105,27 @@ Optional - defaults to `'dune'` if not set.
102105

103106
To receive failure alerts:
104107

105-
1. **Enable notifications:**
108+
1. **Enable notifications:**
106109
Profile → Settings → Notifications → Actions → "Notify me for failed workflows only"
107110

108111
2. **Verify email address** in GitHub settings
109112

110-
3. **Watch repository:**
113+
3. **Watch repository:**
111114
Click "Watch" button (any level works, even "Participating and @mentions")
112115

113116
## Workflow Triggers
114117

115118
### Pull Request Workflow
116119

117120
Runs when:
121+
118122
- PR opened, synchronized, or reopened
119123
- Changes to: `models/`, `macros/`, `dbt_project.yml`, `profiles.yml`, `packages.yml`, workflow file
120124

121125
### Production Workflow
122126

123127
Runs when:
128+
124129
- Hourly (cron: `'0 * * * *'`) - **disabled by default, must be uncommented**
125130
- Manual trigger via GitHub Actions UI
126131

@@ -137,6 +142,7 @@ git push
137142
### Test Failures
138143

139144
Check test output in GitHub Actions logs:
145+
140146
```
141147
dbt test output → specific test name → error message
142148
```
@@ -151,6 +157,7 @@ Query the model in Dune to investigate.
151157
### Timeout
152158

153159
Workflows timeout after 30 minutes. If hitting this:
160+
154161
- Optimize query performance
155162
- Add date filters during development
156163
- Consider breaking large models into smaller pieces
@@ -160,6 +167,7 @@ Workflows timeout after 30 minutes. If hitting this:
160167
Go to Actions tab → "dbt prod orchestration" → "Run workflow"
161168

162169
Use this for:
170+
163171
- Testing deployment changes
164172
- Forcing a full refresh
165173
- Running outside normal schedule
@@ -169,4 +177,3 @@ Use this for:
169177
- [Development Workflow](development-workflow.md) - Local development process
170178
- [Testing](testing.md) - Test requirements
171179
- [Troubleshooting](troubleshooting.md) - Common issues
172-

0 commit comments

Comments
 (0)