Skip to content

Commit 4fdf23b

Browse files
authored
fix(deploy): fail in CI with descriptive message and instructions if no access token set (#2258)
* don't try interactive login in ci, link to docs * add ci note to cli deploy docs * add ci note to github actions * add changeset * make cron test less strict
1 parent 0c71dc7 commit 4fdf23b

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

.changeset/strong-pianos-provide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Fail fast in CI when running deploy with missing `TRIGGER_ACCESS_TOKEN` and add useful error message with link to docs

docs/github-actions.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
---
2-
title: "GitHub Actions"
3-
description: "You can easily deploy your tasks with GitHub actions."
2+
title: "CI / GitHub Actions"
3+
description: "You can easily deploy your tasks with GitHub actions and other CI environments."
44
---
55

6-
This simple GitHub action file will deploy your Trigger.dev tasks when new code is pushed to the `main` branch and the `trigger` directory has changes in it.
6+
The instructions below are specific to GitHub Actions, but the same concepts can be used with other CI systems.
7+
8+
## GitHub Actions example
9+
10+
This simple GitHub action workflow will deploy your Trigger.dev tasks when new code is pushed to the `main` branch and the `trigger` directory has changes in it.
711

812
<Warning>
913
The deploy step will fail if any version mismatches are detected. Please see the [version

docs/snippets/cli-commands-deploy.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ It performs a few steps to deploy:
3636
3. Deploys the code to the Trigger.dev instance.
3737
4. Registers the tasks as a new version in the environment (prod by default).
3838

39-
You can also setup [GitHub Actions](/github-actions) to deploy your tasks automatically.
39+
## Deploying from CI
40+
41+
When deploying from CI/CD environments such as GitHub Actions, GitLab CI, or Jenkins, you need to authenticate non-interactively by setting the `TRIGGER_ACCESS_TOKEN` environment variable. Please see the [CI / GitHub Actions guide](/github-actions) for more information.
4042

4143
## Arguments
4244

packages/cli-v3/src/commands/login.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import { logger } from "../utilities/logger.js";
2222
import { spinner } from "../utilities/windows.js";
2323
import { isLinuxServer } from "../utilities/linux.js";
2424
import { VERSION } from "../version.js";
25-
import { env } from "std-env";
25+
import { env, isCI } from "std-env";
2626
import { CLOUD_API_URL } from "../consts.js";
2727
import {
2828
isPersonalAccessToken,
2929
NotPersonalAccessTokenError,
3030
} from "../utilities/isPersonalAccessToken.js";
31+
import { links } from "@trigger.dev/core/v3";
3132

3233
export const LoginCommandOptions = CommonCommandOptions.extend({
3334
apiUrl: z.string(),
@@ -210,6 +211,24 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
210211
}
211212
}
212213

214+
if (isCI) {
215+
const apiUrl =
216+
env.TRIGGER_API_URL ?? authConfig?.apiUrl ?? opts.defaultApiUrl ?? CLOUD_API_URL;
217+
218+
const isSelfHosted = apiUrl !== CLOUD_API_URL;
219+
220+
// This is fine, as the api URL will generally be the same as the dashboard URL for self-hosted instances
221+
const dashboardUrl = isSelfHosted ? apiUrl : "https://cloud.trigger.dev";
222+
223+
throw new Error(
224+
`Authentication required in CI environment. Please set the TRIGGER_ACCESS_TOKEN environment variable with a Personal Access Token.
225+
226+
- You can generate one here: ${dashboardUrl}/account/tokens
227+
228+
- For more information, see: ${links.docs.gitHubActions.personalAccessToken}`
229+
);
230+
}
231+
213232
if (opts.embedded) {
214233
log.step("You must login to continue.");
215234
}

packages/core/src/v3/links.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export const links = {
2020
"https://trigger.dev/docs/queue-concurrency#waiting-for-a-subtask-on-the-same-queue",
2121
deadlock: "https://trigger.dev/docs/queue-concurrency#deadlock",
2222
},
23+
gitHubActions: {
24+
personalAccessToken:
25+
"https://trigger.dev/docs/github-actions#creating-a-personal-access-token",
26+
},
2327
},
2428
site: {
2529
home: "https://trigger.dev",

packages/redis-worker/src/cron.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe("Worker with cron", () => {
4242

4343
await setTimeout(6_000);
4444

45-
expect(processedItems.length).toBe(1);
45+
expect(processedItems.length).toBeGreaterThanOrEqual(1);
4646

4747
const firstItem = processedItems[0];
4848

0 commit comments

Comments
 (0)