Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/strong-pianos-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"trigger.dev": patch
"@trigger.dev/core": patch
---

Fail fast in CI when running deploy with missing `TRIGGER_ACCESS_TOKEN` and add useful error message with link to docs
10 changes: 7 additions & 3 deletions docs/github-actions.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
---
title: "GitHub Actions"
description: "You can easily deploy your tasks with GitHub actions."
title: "CI / GitHub Actions"
description: "You can easily deploy your tasks with GitHub actions and other CI environments."
---

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.
The instructions below are specific to GitHub Actions, but the same concepts can be used with other CI systems.

## GitHub Actions example

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.

<Warning>
The deploy step will fail if any version mismatches are detected. Please see the [version
Expand Down
4 changes: 3 additions & 1 deletion docs/snippets/cli-commands-deploy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ It performs a few steps to deploy:
3. Deploys the code to the Trigger.dev instance.
4. Registers the tasks as a new version in the environment (prod by default).

You can also setup [GitHub Actions](/github-actions) to deploy your tasks automatically.
## Deploying from CI

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.

## Arguments

Expand Down
21 changes: 20 additions & 1 deletion packages/cli-v3/src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import { logger } from "../utilities/logger.js";
import { spinner } from "../utilities/windows.js";
import { isLinuxServer } from "../utilities/linux.js";
import { VERSION } from "../version.js";
import { env } from "std-env";
import { env, isCI } from "std-env";
import { CLOUD_API_URL } from "../consts.js";
import {
isPersonalAccessToken,
NotPersonalAccessTokenError,
} from "../utilities/isPersonalAccessToken.js";
import { links } from "@trigger.dev/core/v3";

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

if (isCI) {
const apiUrl =
env.TRIGGER_API_URL ?? authConfig?.apiUrl ?? opts.defaultApiUrl ?? CLOUD_API_URL;

const isSelfHosted = apiUrl !== CLOUD_API_URL;

// This is fine, as the api URL will generally be the same as the dashboard URL for self-hosted instances
const dashboardUrl = isSelfHosted ? apiUrl : "https://cloud.trigger.dev";

throw new Error(
`Authentication required in CI environment. Please set the TRIGGER_ACCESS_TOKEN environment variable with a Personal Access Token.

- You can generate one here: ${dashboardUrl}/account/tokens

- For more information, see: ${links.docs.gitHubActions.personalAccessToken}`
);
}

if (opts.embedded) {
log.step("You must login to continue.");
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/v3/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export const links = {
"https://trigger.dev/docs/queue-concurrency#waiting-for-a-subtask-on-the-same-queue",
deadlock: "https://trigger.dev/docs/queue-concurrency#deadlock",
},
gitHubActions: {
personalAccessToken:
"https://trigger.dev/docs/github-actions#creating-a-personal-access-token",
},
},
site: {
home: "https://trigger.dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/redis-worker/src/cron.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("Worker with cron", () => {

await setTimeout(6_000);

expect(processedItems.length).toBe(1);
expect(processedItems.length).toBeGreaterThanOrEqual(1);

const firstItem = processedItems[0];

Expand Down