Skip to content

Commit c44f72b

Browse files
carderneTrigger.dev RepoOps
authored andcommitted
docs: recommend API keys for CI deployments
Mono-RevId: cc4638c038dd9befc6f869b27a2f4f34932897f7
1 parent 0b36a8d commit c44f72b

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

‎docs/deployment/preview-branches.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ jobs:
123123
- name: Deploy preview branch
124124
run: npx trigger.dev@latest deploy --env preview
125125
env:
126-
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
126+
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_PREVIEW_ACCESS_TOKEN }}
127127
```
128128
129129
For this workflow to work, you need to set the following secrets in your GitHub repository:
130130
131-
- `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).
131+
- `TRIGGER_PREVIEW_ACCESS_TOKEN`: A Trigger.dev API key for the Preview environment with **Deploy only** access. [Create a deployment API key and add it to GitHub](/github-actions#create-a-deployment-api-key).
132132

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

‎docs/github-actions.mdx‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: "CI / GitHub Actions"
3-
description: "You can easily deploy your tasks with GitHub actions and other CI environments."
3+
description: "Deploy your tasks from GitHub Actions and other CI environments using an environment API key."
44
---
55

6-
The instructions below are specific to GitHub Actions, but the same concepts can be used with other CI systems.
6+
The instructions below are specific to GitHub Actions, but the same concepts apply to other CI systems. Use an environment API key rather than a Personal Access Token so deployments are not tied to an individual team member's account or permissions.
77

88
<Tip>
99
Check out our new [GitHub integration](/github-integration) for automatic deployments, without adding any GitHub Actions workflows.
@@ -74,7 +74,7 @@ jobs:
7474

7575
- name: 🚀 Deploy Trigger.dev
7676
env:
77-
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
77+
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_STAGING_ACCESS_TOKEN }}
7878
run: |
7979
npx trigger.dev@latest deploy --env staging --external-id ${{ github.sha }}
8080
```
@@ -135,7 +135,7 @@ jobs:
135135
- name: Deploy preview branch
136136
run: npx trigger.dev@latest deploy --env preview --external-id ${{ github.event.pull_request.head.sha }}
137137
env:
138-
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
138+
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_PREVIEW_ACCESS_TOKEN }}
139139
```
140140

141141
On `pull_request`, `github.sha` is the merge commit GitHub creates for the PR, not the commit your
@@ -146,26 +146,36 @@ deployment sends.
146146
**Include `closed`** in the `pull_request.types` list. Without it, preview branches won't be archived when PRs are merged or closed, and you may hit the limit on active preview branches. See [Preview branches](/deployment/preview-branches#preview-branches-with-github-actions-recommended) for more details.
147147
</Note>
148148

149-
## Creating a Personal Access Token
149+
## Create a deployment API key
150+
151+
Create a separate API key for each environment that your CI workflows deploy to. The key remains valid when team membership or permissions change.
150152

151153
<Steps>
152154

153-
<Step title="Create a new access token">
154-
Go to your profile page and click on the ["Personal Access
155-
Tokens"](https://cloud.trigger.dev/account/tokens) tab.
155+
<Step title="Open the API keys page">
156+
Select the project and target environment, then open [**API keys**](https://cloud.trigger.dev/_/apikeys).
156157
</Step>
157158

158-
<Step title="Go to your repository on GitHub.">
159-
Click on 'Settings' -> 'Secrets and variables' -> 'Actions' -> 'New repository secret'
159+
<Step title="Create an API key">
160+
Click **New API key**, give the key a name that identifies the workflow, and choose **Deploy
161+
only** access.
160162
</Step>
161163

162-
<Step title="Add the TRIGGER_ACCESS_TOKEN">
163-
Add the name `TRIGGER_ACCESS_TOKEN` and the value of your access token. ![Add TRIGGER_ACCESS_TOKEN
164-
in GitHub](/images/github-access-token.png)
164+
<Step title="Copy the API key">
165+
Create the key and copy its value. Trigger.dev shows the complete value only once.
166+
</Step>
167+
168+
<Step title="Add the TRIGGER_ACCESS_TOKEN secret to GitHub">
169+
Open the repository's **Settings**, then select **Secrets and variables** → **Actions** → **New
170+
repository secret**. Add the name `TRIGGER_ACCESS_TOKEN` and paste the API key as its value.
171+
172+
![Add TRIGGER_ACCESS_TOKEN in GitHub](/images/github-access-token.png)
165173
</Step>
166174

167175
</Steps>
168176

177+
The API key must belong to the environment targeted by the deploy command. If the repository deploys to multiple environments, store each environment's key in a separate GitHub secret and map the appropriate secret to `TRIGGER_ACCESS_TOKEN` in each workflow.
178+
169179
## CLI Version pinning
170180

171181
The CLI and `@trigger.dev/*` package versions need to be in sync with the `trigger.dev` CLI, otherwise there will be errors and unpredictable behavior. Hence, the `deploy` command will automatically fail during CI on any version mismatches.
@@ -178,7 +188,7 @@ Tip: add the `trigger.dev` CLI to your `devDependencies` and the deploy command
178188
"deploy:trigger": "trigger deploy --env staging"
179189
},
180190
"devDependencies": {
181-
"trigger.dev": "4.0.2"
191+
"trigger.dev": "4.7.0"
182192
}
183193
}
184194
```

0 commit comments

Comments
 (0)