Skip to content

Commit f03d7ae

Browse files
committed
Draft preview branches docs
1 parent 82e7484 commit f03d7ae

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

docs/deployment/preview-branches.mdx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: "Preview branches"
3+
description: "Create isolated environments for each branch of your code, allowing you to test changes in a dedicated preview environment before merging to production"
4+
---
5+
6+
import UpgradeToV4Note from "/snippets/upgrade-to-v4-note.mdx";
7+
8+
<UpgradeToV4Note />
9+
10+
## How does it work?
11+
12+
The "Preview" environment is a special environment where you can create "branches". Normally you would automatically create a preview branch that matches your git branch when a Pull Request is opened (and then archive it automatically when the PR is merged/closed).
13+
14+
The process to use preview branches looks like this:
15+
16+
1. Create a preview branch
17+
2. Deploy to the preview branch (1+ times)
18+
3. Trigger runs using the Preview API key and the branch name
19+
4. Archive the preview branch
20+
21+
There are two main ways to do this:
22+
23+
1. Automatically: using GitHub Actions (recommended)
24+
2. Manually: in the dashboard and/or using the CLI
25+
26+
## Using preview branches using GitHub Actions
27+
28+
```yml
29+
name: Deploy to Trigger.dev (preview branches)
30+
31+
on:
32+
pull_request:
33+
types: [opened, synchronize, reopened, closed, merged]
34+
35+
jobs:
36+
deploy-preview:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Use Node.js 20.x
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: "20.x"
45+
46+
- name: Install dependencies
47+
run: npm install
48+
49+
- name: Deploy preview branch
50+
run: npx trigger.dev@v4-beta deploy --env preview
51+
env:
52+
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
53+
```
54+
55+
For this workflow to work, you need to set up the following secrets in your GitHub repository:
56+
57+
- `TRIGGER_ACCESS_TOKEN`: Your Trigger.dev personal access token. View the instructions [here](/github-actions) to learn more.
58+
59+
Notice that the deploy command has `--env preview` at the end. We automatically detect the preview branch from the GitHub actions env var.
60+
61+
## Manually creating, deploying and archiving preview branches
62+
63+
### Creating and archiving preview branches from the dashboard
64+
65+
In the dashboard, you can
66+
67+
## Automating using GitHub Actions
68+
69+
## Limits
70+
71+
## Triggering runs on preview branches
72+
73+
When triggering runs for a preview branch you need to both set the `TRIGGER_SECRET_KEY` (to your Preview API key) and set `TRIGGER_PREVIEW_BRANCH` to the name of your branch.

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"deployment/overview",
101101
"deploy-environment-variables",
102102
"github-actions",
103+
"deployment/preview-branches",
103104
"deployment/atomic-deployment",
104105
{
105106
"group": "Deployment integrations",

0 commit comments

Comments
 (0)