跳过任务

缓存 显著加快你的任务速度 - 但使用 npx turbo-ignore 可能会让你运行得更快。如果工作区不受代码更改的影响,你可以完全跳过执行任务。

¥Caching dramatically speeds up your tasks - but you may be able to go even faster by using npx turbo-ignore. If a workspace is unaffected by your code changes, you can completely skip executing a task altogether.

假设你希望在 web 应用(或其包依赖)没有任何更改时跳过 web 工作区的单元测试。如果你已经在使用 远程缓存,则可能会出现缓存命中。 - 但你仍然需要花时间配置 CI 容器、安装 npm 依赖以及其他可能需要一段时间的操作。

¥Let's say you want to skip the unit tests for your web workspace when there aren't any changes to your web application (or its package dependencies). If you are already using Remote Caching, you will probably get a cache hit - but you would still spend time provisioning the CI container, installing npm dependencies, and other things that can take a while.

理想情况下,你应该快速检查一下是否需要执行任何此类工作。

¥Ideally, you would do a quick check to see if any of that work needs to happen in the first place.


检出代码库后,但在进行任何其他工作之前,你可以花几秒钟检查一下 web 测试自父提交以来是否发生了变化。

¥After you've checked out the repo, but before any other work, you can take a few seconds to check that your web tests have changed since the parent commit.

Terminal
npx turbo-ignore web --task=test

此命令将:

¥This command will:

  1. 过滤 web 工作区。

    ¥Filter for the web workspace.

  2. 为你的 test 任务创建 dry 输出,并与父提交进行比较。

    ¥Create the dry output for your test task compared to your parent commit.

  3. 解析输出以确定哪些软件包已更改。

    ¥Parse the output to determine which packages have changed.

  4. 如果检测到更改,则使用 1 代码退出。否则,以 0 退出。

    ¥Exit with a 1 code if changes are detected. Otherwise, exits with a 0.

虽然你可能已经能够为此任务访问 >>> FULL TURBO 缓存,但你只是节省了运行 CI 所需的所有其他设置任务的时间。

¥While you may have been able to hit a >>> FULL TURBO cache for this task, you just saved time with all of the other setup tasks required to run your CI.

使用 turbo-ignore

¥Using turbo-ignore

要跳过不受影响的工作,首先请确保你的 Git 历史记录在计算机上可用。然后,运行 npx turbo-ignore

¥To skip unaffected work, first ensure that your Git history is available on the machine. Then, run npx turbo-ignore.

turbo-ignore 结合使用 --filter--dry=json 标志来查找从父提交到当前提交的更改,以识别受影响的包。默认情况下,turbo-ignore 会在当前工作目录中查找构建任务的差异,但 使用标志自定义此行为 可以。

¥turbo-ignore uses a combination of the --filter and --dry=json flags to find changes from the parent commit to the current commit to identify affected packages. By default, turbo-ignore finds the difference for the build task in the current working directory, but you can customize this behavior with flags.

以下是将要构建和运行的命令示例:

¥Here's an example of the command that will be built and run:

Terminal
npx turbo run build --filter=@example/web...3c8387ffd98b751305fe3f0284befdd00cbd4610 --dry=json

请注意,试运行不会执行构建任务。相反,它会在几秒钟内检查你的软件包,看看你的代码更改是否会影响你的构建(或其他任务)。

¥Note that a dry run does not execute the build task. Instead, it checks your packages to see if your code changes will affect your build (or other task) in only a few seconds.

如果 turbo-ignore 发现该任务可以跳过,它将退出进程并返回 0 代码。如果发现更改,该进程将退出并返回 1

¥If turbo-ignore finds that the task can be skipped, it will exit the process with a 0 code. If changes have been found, the process will exit with 1.

在 Vercel 上,将使用先前部署的 SHA 而不是父提交。

¥On Vercel, the previously deployed SHA will be used instead of the parent commit.

自定义行为

¥Customizing behavior

要指定工作区,你可以将其添加到命令中,例如:

¥To specify a workspace, you can add it to your command like:

Terminal
npx turbo-ignore web

其中 web 是运行默认 build 任务的工作区名称。

¥where web is your workspace's name running the default build task.

如果你想更改任务,请使用 --task 标志指定 turbo-ignore 将调用的命令的任务。

¥If you'd like to change the task, use the --task flag to specify the task for the command that turbo-ignore will invoke.

在 Vercel 上使用 turbo-ignore

¥Using turbo-ignore on Vercel

要在 Vercel 上使用 npx turbo-ignore,你可以使用 忽略的构建步骤 功能。Vercel 将自动推断正确的参数以成功运行 turbo-ignore

¥To use npx turbo-ignore on Vercel, you can use the Ignored Build Step feature. Vercel will automatically infer the correct arguments to successfully run turbo-ignore.

自定义行为

¥Customizing behavior

不在 Vercel 上时,请使用 --fallback 标志指定要比较的提交。

¥When not on Vercel, specify a commit for comparison using the --fallback flag.

在 Vercel 上,你可以指定 --fallback 标志,以便在默认比较不可用时为 Vercel 提供一个 git 引用进行比较。默认情况下,Vercel 会与最近部署的 SHA 进行比较,因此这对于避免首次提交到分支的部署等用例非常有用。

¥On Vercel, you can specify the --fallback flag to give Vercel a git ref to compare against when the default comparison is not available. By default, Vercel compares to the most recently deployed SHA so this is useful for use cases like avoiding a deploy for the first commit to a branch.