You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/deployment/preview-branches.mdx
+33-6Lines changed: 33 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
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."
@@ -9,7 +9,7 @@ import UpgradeToV4Note from "/snippets/upgrade-to-v4-note.mdx";
9
9
10
10
## How does it work?
11
11
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.
13
13
14
14
The process to use preview branches looks like this:
15
15
@@ -39,7 +39,34 @@ This limit exists because each branch has an independent concurrency limit. For
39
39
40
40
For full details see our [pricing page](https://trigger.dev/pricing).
41
41
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
+
asyncfunction triggerTask() {
65
+
awaitmyTask.trigger({ userId: "1234" }); // Trigger a run in your-branch-name
66
+
}
67
+
```
68
+
69
+
## Preview branches with GitHub Actions (recommended)
43
70
44
71
This GitHub Action will:
45
72
@@ -76,13 +103,13 @@ jobs:
76
103
77
104
For this workflow to work, you need to set the following secrets in your GitHub repository:
78
105
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).
80
107
81
108
Notice that the deploy command has `--env preview` at the end. We automatically detect the preview branch from the GitHub actions env var.
82
109
83
110
You can manually specify the branch using `--branch <branch-name>` in the deploy command, but this isn't required.
84
111
85
-
## Using the CLI to create, deploy and archive preview branches
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:
0 commit comments