diff --git a/.changeset/strong-pianos-provide.md b/.changeset/strong-pianos-provide.md new file mode 100644 index 0000000000..728179393b --- /dev/null +++ b/.changeset/strong-pianos-provide.md @@ -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 diff --git a/docs/github-actions.mdx b/docs/github-actions.mdx index 87ae4d75f2..9fba762fae 100644 --- a/docs/github-actions.mdx +++ b/docs/github-actions.mdx @@ -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. The deploy step will fail if any version mismatches are detected. Please see the [version diff --git a/docs/snippets/cli-commands-deploy.mdx b/docs/snippets/cli-commands-deploy.mdx index 95efc59bd3..d3ed672f2b 100644 --- a/docs/snippets/cli-commands-deploy.mdx +++ b/docs/snippets/cli-commands-deploy.mdx @@ -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 diff --git a/packages/cli-v3/src/commands/login.ts b/packages/cli-v3/src/commands/login.ts index 484ada22a1..687b6e8f6d 100644 --- a/packages/cli-v3/src/commands/login.ts +++ b/packages/cli-v3/src/commands/login.ts @@ -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(), @@ -210,6 +211,24 @@ export async function login(options?: LoginOptions): Promise { } } + 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."); } diff --git a/packages/core/src/v3/links.ts b/packages/core/src/v3/links.ts index f59f2014f0..f514bf62f8 100644 --- a/packages/core/src/v3/links.ts +++ b/packages/core/src/v3/links.ts @@ -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", diff --git a/packages/redis-worker/src/cron.test.ts b/packages/redis-worker/src/cron.test.ts index 9a607234a4..a75c8fdc9a 100644 --- a/packages/redis-worker/src/cron.test.ts +++ b/packages/redis-worker/src/cron.test.ts @@ -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];