Skip to content

v3: semi-automatic package update command #1052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 23, 2024
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
5 changes: 5 additions & 0 deletions .changeset/beige-pens-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

v3 CLI update command and package manager detection fix
2 changes: 2 additions & 0 deletions docs/_snippets/v3/step-cli-dev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

The CLI `dev` command runs a server for your tasks. It will watches for changes in your `/trigger` directory and communicates with the Trigger.dev platform to register your tasks, perform runs, and send data back and forth.

It can also update your `@trigger.dev/*` packages to prevent version mismatches and failed deploys. You will always be prompted first.

<CodeGroup>

```bash npm
Expand Down
13 changes: 8 additions & 5 deletions docs/v3/cli-deploy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ yarn dlx trigger.dev@beta deploy

</CodeGroup>

<Warning>Will fail in CI if any version mismatches are detected. Ensure everything runs locally first using the [dev](/v3/cli-dev) command and don't bypass the version checks!</Warning>

It performs a few steps to deploy:

1. Typechecks the code.
2. Compiles and bundles the code.
3. Checks that [environment variables](/v3/deploy-environment-variables) are set.
4. Deploys the code to the cloud.
5. Registers the tasks as a new version in the environment (prod by default).
1. Optionally updates packages when running locally.
2. Typechecks the code.
3. Compiles and bundles the code.
4. Checks that [environment variables](/v3/deploy-environment-variables) are set.
5. Deploys the code to the cloud.
6. Registers the tasks as a new version in the environment (prod by default).

## Options

Expand Down
2 changes: 2 additions & 0 deletions docs/v3/cli-dev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ yarn dlx trigger.dev@beta dev

</CodeGroup>

It will first perform an update check to prevent version mismatches, failed deploys, and other errors. You will always be prompted first.

You will see in the terminal that the server is running and listening for requests. When you run a task, you will see it in the terminal along with a link to view it in the dashboard.

It is worth noting that each task runs in a separate Node process. This means that if you have a long-running task, it will not block other tasks from running.
Expand Down
18 changes: 18 additions & 0 deletions docs/v3/github-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ description: "You can easily deploy your tasks with GitHub actions."

This simple GitHub action file will deploy you 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 pinning](/v3/github-actions#version-pinning) section for more details.</Warning>

```yaml .github/workflows/release-trigger.yml
name: Deploy to Trigger.dev

Expand Down Expand Up @@ -42,3 +44,19 @@ If you already have a GitHub action file, you can just add the final step "🚀
You need to add the `TRIGGER_ACCESS_TOKEN` secret to your repository. You can create a new access token by going to your profile page and then clicking on the "Personal Access Tokens" tab.

To set it in GitHub go to your repository, click on "Settings", "Secrets and variables" and then "Actions". Add a new secret with the name `TRIGGER_ACCESS_TOKEN` and use the value of your access token.

## Version pinning

The CLI and `@trigger.dev/*` package versions need to be in sync, otherwise there will be errors and unpredictable behavior. Hence, the `deploy` command will automatically fail during CI on any version mismatches.

To ensure a smooth CI experience you can pin the CLI version in the deploy step, like so:

```yaml .github/workflows/release-trigger.yml
- name: 🚀 Deploy Trigger.dev
env:
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
run: |
npx [email protected] deploy
```

You should use the version you run locally during dev and manual deploy. The current version is displayed in the banner, but you can also check it by appending `--version` to any command.
20 changes: 1 addition & 19 deletions docs/v3/upgrading-from-v2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,7 @@ async function yourBackendFunction() {

## Upgrading your project

<Steps>

<Step title="Upgrade the v2 Trigger.dev packages">

You can run this command to upgrade all the packages to the beta:

```bash
npx @trigger.dev/cli@beta update --to beta
```

</Step>

<Step title="Follow the v3 quick start">

Follow the [v3 quick start](/v3/quick-start) to get started with v3.

</Step>

</Steps>
Just follow the [v3 quick start](/v3/quick-start) to get started with v3. Our new CLI will take care of the rest.

## Using v2 together with v3

Expand Down
1 change: 0 additions & 1 deletion packages/cli-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"mock-fs": "^5.2.0",
"nanoid": "^4.0.2",
"node-fetch": "^3.3.0",
"npm-check-updates": "^16.12.2",
"object-hash": "^3.0.0",
"p-debounce": "^4.0.0",
"p-throttle": "^6.1.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/cli-v3/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { configureWhoamiCommand } from "../commands/whoami.js";
import { COMMAND_NAME } from "../consts.js";
import { getVersion } from "../utilities/getVersion.js";
import { configureListProfilesCommand } from "../commands/list-profiles.js";
import { configureUpdateCommand } from "../commands/update.js";

export const program = new Command();

Expand All @@ -23,3 +24,4 @@ configureDeployCommand(program);
configureWhoamiCommand(program);
configureLogoutCommand(program);
configureListProfilesCommand(program);
configureUpdateCommand(program);
7 changes: 7 additions & 0 deletions packages/cli-v3/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { safeJsonParse } from "../utilities/safeJsonParse";
import { JavascriptProject } from "../utilities/javascriptProject";
import { cliRootPath } from "../utilities/resolveInternalFilePath";
import { escapeImportPath, spinner } from "../utilities/windows";
import { updateTriggerPackages } from "./update";
import { docs, getInTouch } from "../utilities/links";

const DeployCommandOptions = CommonCommandOptions.extend({
Expand All @@ -74,6 +75,7 @@ const DeployCommandOptions = CommonCommandOptions.extend({
outputMetafile: z.string().optional(),
apiUrl: z.string().optional(),
saveLogs: z.boolean().default(false),
skipUpdateCheck: z.boolean().default(false),
});

type DeployCommandOptions = z.infer<typeof DeployCommandOptions>;
Expand All @@ -90,6 +92,7 @@ export function configureDeployCommand(program: Command) {
"prod"
)
.option("--skip-typecheck", "Whether to skip the pre-build typecheck")
.option("--skip-update-check", "Skip checking for @trigger.dev package updates")
.option(
"--ignore-env-var-check",
"Detected missing environment variables won't block deployment"
Expand Down Expand Up @@ -167,6 +170,10 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {

intro("Deploying project");

if (!options.skipUpdateCheck) {
await updateTriggerPackages(dir, { ...options }, true, true);
}

const authorization = await login({
embedded: true,
defaultApiUrl: options.apiUrl,
Expand Down
11 changes: 10 additions & 1 deletion packages/cli-v3/src/commands/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
import { findUp, pathExists } from "find-up";
import { cliRootPath } from "../utilities/resolveInternalFilePath";
import { escapeImportPath } from "../utilities/windows";
import { updateTriggerPackages } from "./update";

let apiClient: CliApiClient | undefined;

Expand All @@ -61,6 +62,7 @@ const DevCommandOptions = CommonCommandOptions.extend({
debugOtel: z.boolean().default(false),
config: z.string().optional(),
projectRef: z.string().optional(),
skipUpdateCheck: z.boolean().default(false),
});

type DevCommandOptions = z.infer<typeof DevCommandOptions>;
Expand All @@ -78,6 +80,7 @@ export function configureDevCommand(program: Command) {
)
.option("--debugger", "Enable the debugger")
.option("--debug-otel", "Enable OpenTelemetry debugging")
.option("--skip-update-check", "Skip checking for @trigger.dev package updates")
).action(async (path, options) => {
wrapCommandAction("dev", DevCommandOptions, options, async (opts) => {
await devCommand(path, opts);
Expand Down Expand Up @@ -132,7 +135,13 @@ async function startDev(
}

await printStandloneInitialBanner(true);
printDevBanner();

if (!options.skipUpdateCheck) {
console.log(); // spacing
await updateTriggerPackages(dir, { ...options }, false, true);
}

printDevBanner(!options.skipUpdateCheck);

logger.debug("Starting dev session", { dir, options, authorization });

Expand Down
Loading