Skip to content

Commit 76bca03

Browse files
committed
More wip on the preview branch docs
1 parent efa65bb commit 76bca03

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

docs/deployment/preview-branches.mdx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Preview branches"
3-
description: "Create isolated environments for each branch of your code, allowing you to test changes before merging to production. You can create preview branches manually or automatically with your git branches."
3+
description: "Create isolated environments for each branch of your code, allowing you to test changes before merging to production. You can create preview branches manually or automatically from your git branches."
44
---
55

66
import UpgradeToV4Note from "/snippets/upgrade-to-v4-note.mdx";
@@ -9,7 +9,7 @@ import UpgradeToV4Note from "/snippets/upgrade-to-v4-note.mdx";
99

1010
## How does it work?
1111

12-
The "Preview" environment is a special environment that you can create "branches" from. We recommend you automatically create a preview branch for each git branch when a Pull Request is opened and then archive it automatically when the PR is merged/closed.
12+
The Preview environment is special you create branches from it. We recommend you automatically create a preview branch for each git branch when a Pull Request is opened and then archive it automatically when the PR is merged/closed.
1313

1414
The process to use preview branches looks like this:
1515

@@ -39,7 +39,34 @@ This limit exists because each branch has an independent concurrency limit. For
3939

4040
For full details see our [pricing page](https://trigger.dev/pricing).
4141

42-
## Using preview branches using GitHub Actions (recommended)
42+
## Triggering runs and using the SDK
43+
44+
Before we talk about how to deploy to preview branches, one important thing to understand is that you must set the `TRIGGER_PREVIEW_BRANCH` environment variable as well as the `TRIGGER_SECRET_KEY` environment variable.
45+
46+
When deploying to somewhere that supports `process.env` (like Node.js runtimes) you can just set the environment variables:
47+
48+
```bash
49+
TRIGGER_SECRET_KEY="tr_preview_1234567890"
50+
TRIGGER_PREVIEW_BRANCH="your-branch-name"
51+
```
52+
53+
If you're deploying somewhere that doesn't support `process.env` (like some edge runtimes) you can manually configure the SDK:
54+
55+
```ts
56+
import { configure } from "@trigger.dev/sdk";
57+
import { myTask } from "./trigger/myTasks";
58+
59+
configure({
60+
secretKey: "tr_preview_1234567890", // WARNING: Never actually hardcode your secret key like this
61+
previewBranch: "your-branch-name",
62+
});
63+
64+
async function triggerTask() {
65+
await myTask.trigger({ userId: "1234" }); // Trigger a run in your-branch-name
66+
}
67+
```
68+
69+
## Preview branches with GitHub Actions (recommended)
4370

4471
This GitHub Action will:
4572

@@ -76,13 +103,13 @@ jobs:
76103
77104
For this workflow to work, you need to set the following secrets in your GitHub repository:
78105
79-
- `TRIGGER_ACCESS_TOKEN`: Your Trigger.dev personal access token. View the instructions [here](/github-actions) to learn how.
106+
- `TRIGGER_ACCESS_TOKEN`: A Trigger.dev personal access token (they start with `tr_pat_`). [Learn how to create one and set it in GitHub](/github-actions#creating-a-personal-access-token).
80107

81108
Notice that the deploy command has `--env preview` at the end. We automatically detect the preview branch from the GitHub actions env var.
82109

83110
You can manually specify the branch using `--branch <branch-name>` in the deploy command, but this isn't required.
84111

85-
## Using the CLI to create, deploy and archive preview branches
112+
## Preview branches with the CLI (manual)
86113

87114
### Deploying a preview branch
88115

@@ -95,7 +122,7 @@ npx trigger.dev@v4-beta deploy --env preview
95122
This will create and deploy a preview branch, automatically detecting the git branch. If for some reason the auto-detection doesn't work it will let you know and tell you do this:
96123

97124
```bash
98-
npx trigger.dev@v4-beta deploy --env preview --branch <branch-name>
125+
npx trigger.dev@v4-beta deploy --env preview --branch your-branch-name
99126
```
100127

101128
### Archiving a preview branch

0 commit comments

Comments
 (0)