Skip to content

Commit b207601

Browse files
authored
v3: semi-automatic package update command (#1052)
* fix package manager detection * fix cli update check while in beta * add update command and warn on mismatches * update fixes and better integration with dev and deploy * fix for ci * update docs * changeset * be more specific about prompts before updates * fail on version mismatch during ci * update github actions docs * fix package manager copypasta * remove ncu * ignore companyicons * improve warnings and errors
1 parent 3913e57 commit b207601

20 files changed

+467
-275
lines changed

.changeset/beige-pens-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
v3 CLI update command and package manager detection fix

docs/_snippets/v3/step-cli-dev.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
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.
44

5+
It can also update your `@trigger.dev/*` packages to prevent version mismatches and failed deploys. You will always be prompted first.
6+
57
<CodeGroup>
68

79
```bash npm

docs/v3/cli-deploy.mdx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ yarn dlx trigger.dev@beta deploy
2121

2222
</CodeGroup>
2323

24+
<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>
25+
2426
It performs a few steps to deploy:
2527

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

3235
## Options
3336

docs/v3/cli-dev.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ yarn dlx trigger.dev@beta dev
2121

2222
</CodeGroup>
2323

24+
It will first perform an update check to prevent version mismatches, failed deploys, and other errors. You will always be prompted first.
25+
2426
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.
2527

2628
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.

docs/v3/github-actions.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ description: "You can easily deploy your tasks with GitHub actions."
55

66
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.
77

8+
<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>
9+
810
```yaml .github/workflows/release-trigger.yml
911
name: Deploy to Trigger.dev
1012

@@ -42,3 +44,19 @@ If you already have a GitHub action file, you can just add the final step "🚀
4244
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.
4345

4446
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.
47+
48+
## Version pinning
49+
50+
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.
51+
52+
To ensure a smooth CI experience you can pin the CLI version in the deploy step, like so:
53+
54+
```yaml .github/workflows/release-trigger.yml
55+
- name: 🚀 Deploy Trigger.dev
56+
env:
57+
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
58+
run: |
59+
npx trigger.dev@3.0.0-beta.16 deploy
60+
```
61+
62+
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.

docs/v3/upgrading-from-v2.mdx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,7 @@ async function yourBackendFunction() {
171171

172172
## Upgrading your project
173173

174-
<Steps>
175-
176-
<Step title="Upgrade the v2 Trigger.dev packages">
177-
178-
You can run this command to upgrade all the packages to the beta:
179-
180-
```bash
181-
npx @trigger.dev/cli@beta update --to beta
182-
```
183-
184-
</Step>
185-
186-
<Step title="Follow the v3 quick start">
187-
188-
Follow the [v3 quick start](/v3/quick-start) to get started with v3.
189-
190-
</Step>
191-
192-
</Steps>
174+
Just follow the [v3 quick start](/v3/quick-start) to get started with v3. Our new CLI will take care of the rest.
193175

194176
## Using v2 together with v3
195177

packages/cli-v3/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
"mock-fs": "^5.2.0",
107107
"nanoid": "^4.0.2",
108108
"node-fetch": "^3.3.0",
109-
"npm-check-updates": "^16.12.2",
110109
"object-hash": "^3.0.0",
111110
"p-debounce": "^4.0.0",
112111
"p-throttle": "^6.1.0",

packages/cli-v3/src/cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { configureWhoamiCommand } from "../commands/whoami.js";
88
import { COMMAND_NAME } from "../consts.js";
99
import { getVersion } from "../utilities/getVersion.js";
1010
import { configureListProfilesCommand } from "../commands/list-profiles.js";
11+
import { configureUpdateCommand } from "../commands/update.js";
1112

1213
export const program = new Command();
1314

@@ -23,3 +24,4 @@ configureDeployCommand(program);
2324
configureWhoamiCommand(program);
2425
configureLogoutCommand(program);
2526
configureListProfilesCommand(program);
27+
configureUpdateCommand(program);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { safeJsonParse } from "../utilities/safeJsonParse";
5757
import { JavascriptProject } from "../utilities/javascriptProject";
5858
import { cliRootPath } from "../utilities/resolveInternalFilePath";
5959
import { escapeImportPath, spinner } from "../utilities/windows";
60+
import { updateTriggerPackages } from "./update";
6061
import { docs, getInTouch } from "../utilities/links";
6162

6263
const DeployCommandOptions = CommonCommandOptions.extend({
@@ -74,6 +75,7 @@ const DeployCommandOptions = CommonCommandOptions.extend({
7475
outputMetafile: z.string().optional(),
7576
apiUrl: z.string().optional(),
7677
saveLogs: z.boolean().default(false),
78+
skipUpdateCheck: z.boolean().default(false),
7779
});
7880

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

168171
intro("Deploying project");
169172

173+
if (!options.skipUpdateCheck) {
174+
await updateTriggerPackages(dir, { ...options }, true, true);
175+
}
176+
170177
const authorization = await login({
171178
embedded: true,
172179
defaultApiUrl: options.apiUrl,

packages/cli-v3/src/commands/dev.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
import { findUp, pathExists } from "find-up";
5454
import { cliRootPath } from "../utilities/resolveInternalFilePath";
5555
import { escapeImportPath } from "../utilities/windows";
56+
import { updateTriggerPackages } from "./update";
5657

5758
let apiClient: CliApiClient | undefined;
5859

@@ -61,6 +62,7 @@ const DevCommandOptions = CommonCommandOptions.extend({
6162
debugOtel: z.boolean().default(false),
6263
config: z.string().optional(),
6364
projectRef: z.string().optional(),
65+
skipUpdateCheck: z.boolean().default(false),
6466
});
6567

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

134137
await printStandloneInitialBanner(true);
135-
printDevBanner();
138+
139+
if (!options.skipUpdateCheck) {
140+
console.log(); // spacing
141+
await updateTriggerPackages(dir, { ...options }, false, true);
142+
}
143+
144+
printDevBanner(!options.skipUpdateCheck);
136145

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

0 commit comments

Comments
 (0)