feat(core): add support for skipping remote cache (#29574)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
0d5e53d60e
commit
d46761d764
@ -103,6 +103,7 @@ Print the task graph to the console:
|
||||
| `--parallel` | string | Max number of parallel processes [default is 3]. |
|
||||
| `--runner` | string | This is the name of the tasks runner configured in nx.json. |
|
||||
| `--skipNxCache` | boolean | Rerun the tasks even when the results are available in the cache. (Default: `false`) |
|
||||
| `--skipRemoteCache` | boolean | Disables the remote cache. (Default: `false`) |
|
||||
| `--skipSync` | boolean | Skips running the sync generators associated with the tasks. (Default: `false`) |
|
||||
| `--targets` | string | Tasks to run for affected projects. |
|
||||
| `--uncommitted` | boolean | Uncommitted changes. |
|
||||
|
||||
@ -131,6 +131,7 @@ nx release publish
|
||||
| `--registry` | string | The registry to publish to. |
|
||||
| `--runner` | string | This is the name of the tasks runner configured in nx.json. |
|
||||
| `--skipNxCache` | boolean | Rerun the tasks even when the results are available in the cache. (Default: `false`) |
|
||||
| `--skipRemoteCache` | boolean | Disables the remote cache. (Default: `false`) |
|
||||
| `--skipSync` | boolean | Skips running the sync generators associated with the tasks. (Default: `false`) |
|
||||
| `--tag` | string | The distribution tag to apply to the published package. |
|
||||
| `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces). |
|
||||
|
||||
@ -107,6 +107,7 @@ Print the task graph to the console:
|
||||
| `--projects` | string | Projects to run. (comma/space delimited project names and/or patterns). |
|
||||
| `--runner` | string | This is the name of the tasks runner configured in nx.json. |
|
||||
| `--skipNxCache` | boolean | Rerun the tasks even when the results are available in the cache. (Default: `false`) |
|
||||
| `--skipRemoteCache` | boolean | Disables the remote cache. (Default: `false`) |
|
||||
| `--skipSync` | boolean | Skips running the sync generators associated with the tasks. (Default: `false`) |
|
||||
| `--targets` | string | Tasks to run for affected projects. |
|
||||
| `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces). |
|
||||
|
||||
@ -81,6 +81,7 @@ Run's a target named build:test for the myapp project. Note the quotes around th
|
||||
| `--project` | string | Target project. |
|
||||
| `--runner` | string | This is the name of the tasks runner configured in nx.json. |
|
||||
| `--skipNxCache` | boolean | Rerun the tasks even when the results are available in the cache. (Default: `false`) |
|
||||
| `--skipRemoteCache` | boolean | Disables the remote cache. (Default: `false`) |
|
||||
| `--skipSync` | boolean | Skips running the sync generators associated with the tasks. (Default: `false`) |
|
||||
| `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces). |
|
||||
| `--version` | boolean | Show version number. |
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
- [remoteCache](../../devkit/documents/DefaultTasksRunnerOptions#remotecache): RemoteCache
|
||||
- [runtimeCacheInputs](../../devkit/documents/DefaultTasksRunnerOptions#runtimecacheinputs): string[]
|
||||
- [skipNxCache](../../devkit/documents/DefaultTasksRunnerOptions#skipnxcache): boolean
|
||||
- [skipRemoteCache](../../devkit/documents/DefaultTasksRunnerOptions#skipremotecache): boolean
|
||||
|
||||
## Properties
|
||||
|
||||
@ -74,3 +75,9 @@
|
||||
### skipNxCache
|
||||
|
||||
• `Optional` **skipNxCache**: `boolean`
|
||||
|
||||
---
|
||||
|
||||
### skipRemoteCache
|
||||
|
||||
• `Optional` **skipRemoteCache**: `boolean`
|
||||
|
||||
@ -103,6 +103,7 @@ Print the task graph to the console:
|
||||
| `--parallel` | string | Max number of parallel processes [default is 3]. |
|
||||
| `--runner` | string | This is the name of the tasks runner configured in nx.json. |
|
||||
| `--skipNxCache` | boolean | Rerun the tasks even when the results are available in the cache. (Default: `false`) |
|
||||
| `--skipRemoteCache` | boolean | Disables the remote cache. (Default: `false`) |
|
||||
| `--skipSync` | boolean | Skips running the sync generators associated with the tasks. (Default: `false`) |
|
||||
| `--targets` | string | Tasks to run for affected projects. |
|
||||
| `--uncommitted` | boolean | Uncommitted changes. |
|
||||
|
||||
@ -131,6 +131,7 @@ nx release publish
|
||||
| `--registry` | string | The registry to publish to. |
|
||||
| `--runner` | string | This is the name of the tasks runner configured in nx.json. |
|
||||
| `--skipNxCache` | boolean | Rerun the tasks even when the results are available in the cache. (Default: `false`) |
|
||||
| `--skipRemoteCache` | boolean | Disables the remote cache. (Default: `false`) |
|
||||
| `--skipSync` | boolean | Skips running the sync generators associated with the tasks. (Default: `false`) |
|
||||
| `--tag` | string | The distribution tag to apply to the published package. |
|
||||
| `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces). |
|
||||
|
||||
@ -107,6 +107,7 @@ Print the task graph to the console:
|
||||
| `--projects` | string | Projects to run. (comma/space delimited project names and/or patterns). |
|
||||
| `--runner` | string | This is the name of the tasks runner configured in nx.json. |
|
||||
| `--skipNxCache` | boolean | Rerun the tasks even when the results are available in the cache. (Default: `false`) |
|
||||
| `--skipRemoteCache` | boolean | Disables the remote cache. (Default: `false`) |
|
||||
| `--skipSync` | boolean | Skips running the sync generators associated with the tasks. (Default: `false`) |
|
||||
| `--targets` | string | Tasks to run for affected projects. |
|
||||
| `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces). |
|
||||
|
||||
@ -81,6 +81,7 @@ Run's a target named build:test for the myapp project. Note the quotes around th
|
||||
| `--project` | string | Target project. |
|
||||
| `--runner` | string | This is the name of the tasks runner configured in nx.json. |
|
||||
| `--skipNxCache` | boolean | Rerun the tasks even when the results are available in the cache. (Default: `false`) |
|
||||
| `--skipRemoteCache` | boolean | Disables the remote cache. (Default: `false`) |
|
||||
| `--skipSync` | boolean | Skips running the sync generators associated with the tasks. (Default: `false`) |
|
||||
| `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces). |
|
||||
| `--version` | boolean | Show version number. |
|
||||
|
||||
@ -32,6 +32,7 @@ export interface RunOptions {
|
||||
nxBail: boolean;
|
||||
nxIgnoreCycles: boolean;
|
||||
skipNxCache: boolean;
|
||||
skipRemoteCache: boolean;
|
||||
cloud: boolean;
|
||||
dte: boolean;
|
||||
batch: boolean;
|
||||
@ -89,6 +90,13 @@ export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
|
||||
'Rerun the tasks even when the results are available in the cache.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
alias: 'disableNxCache',
|
||||
})
|
||||
.options('skipRemoteCache', {
|
||||
type: 'boolean',
|
||||
describe: 'Disables the remote cache.',
|
||||
default: false,
|
||||
alias: 'disableRemoteCache',
|
||||
})
|
||||
.options('excludeTaskDependencies', {
|
||||
describe: 'Skips running dependent tasks first.',
|
||||
@ -104,6 +112,7 @@ export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
|
||||
type: 'boolean',
|
||||
hidden: true,
|
||||
})
|
||||
|
||||
.options('dte', {
|
||||
type: 'boolean',
|
||||
hidden: true,
|
||||
|
||||
@ -83,6 +83,7 @@ export function getCache(options: DefaultTasksRunnerOptions): DbCache | Cache {
|
||||
? new DbCache({
|
||||
// Remove this in Nx 21
|
||||
nxCloudRemoteCache: isNxCloudUsed(nxJson) ? options.remoteCache : null,
|
||||
skipRemoteCache: options.skipRemoteCache,
|
||||
})
|
||||
: new Cache(options);
|
||||
}
|
||||
@ -95,7 +96,12 @@ export class DbCache {
|
||||
|
||||
private isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
|
||||
|
||||
constructor(private readonly options: { nxCloudRemoteCache: RemoteCache }) {}
|
||||
constructor(
|
||||
private readonly options: {
|
||||
nxCloudRemoteCache: RemoteCache;
|
||||
skipRemoteCache?: boolean;
|
||||
}
|
||||
) {}
|
||||
|
||||
async init() {
|
||||
// This should be cheap because we've already loaded
|
||||
@ -185,6 +191,16 @@ export class DbCache {
|
||||
}
|
||||
|
||||
private async _getRemoteCache(): Promise<RemoteCacheV2 | null> {
|
||||
if (this.options.skipRemoteCache) {
|
||||
output.warn({
|
||||
title: 'Remote Cache Disabled',
|
||||
bodyLines: [
|
||||
'Nx will continue running, but nothing will be written or read from the remote cache.',
|
||||
],
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
const nxJson = readNxJson();
|
||||
if (isNxCloudUsed(nxJson)) {
|
||||
const options = getCloudOptions();
|
||||
@ -270,7 +286,16 @@ export class Cache {
|
||||
|
||||
private _currentMachineId: string = null;
|
||||
|
||||
constructor(private readonly options: DefaultTasksRunnerOptions) {}
|
||||
constructor(private readonly options: DefaultTasksRunnerOptions) {
|
||||
if (this.options.skipRemoteCache) {
|
||||
output.warn({
|
||||
title: 'Remote Cache Disabled',
|
||||
bodyLines: [
|
||||
'Nx will continue running, but nothing will be written or read from the remote cache.',
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
removeOldCacheRecords() {
|
||||
/**
|
||||
@ -315,7 +340,7 @@ export class Cache {
|
||||
if (res) {
|
||||
await this.assertLocalCacheValidity(task);
|
||||
return { ...res, remote: false };
|
||||
} else if (this.options.remoteCache) {
|
||||
} else if (this.options.remoteCache && !this.options.skipRemoteCache) {
|
||||
// didn't find it locally but we have a remote cache
|
||||
// attempt remote cache
|
||||
await this.options.remoteCache.retrieve(task.hash, this.cachePath);
|
||||
@ -370,7 +395,7 @@ export class Cache {
|
||||
await writeFile(join(td, 'source'), await this.currentMachineId());
|
||||
await writeFile(tdCommit, 'true');
|
||||
|
||||
if (this.options.remoteCache) {
|
||||
if (this.options.remoteCache && !this.options.skipRemoteCache) {
|
||||
await this.options.remoteCache.store(task.hash, this.cachePath);
|
||||
}
|
||||
|
||||
|
||||
@ -75,6 +75,7 @@ export interface DefaultTasksRunnerOptions {
|
||||
lifeCycle: LifeCycle;
|
||||
captureStderr?: boolean;
|
||||
skipNxCache?: boolean;
|
||||
skipRemoteCache?: boolean;
|
||||
batch?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ describe('splitArgs', () => {
|
||||
base: 'sha1',
|
||||
head: 'sha2',
|
||||
skipNxCache: false,
|
||||
skipRemoteCache: false,
|
||||
});
|
||||
});
|
||||
|
||||
@ -68,6 +69,7 @@ describe('splitArgs', () => {
|
||||
).toEqual({
|
||||
base: 'main',
|
||||
skipNxCache: false,
|
||||
skipRemoteCache: false,
|
||||
});
|
||||
});
|
||||
|
||||
@ -85,6 +87,7 @@ describe('splitArgs', () => {
|
||||
).toEqual({
|
||||
base: 'develop',
|
||||
skipNxCache: false,
|
||||
skipRemoteCache: false,
|
||||
});
|
||||
});
|
||||
|
||||
@ -102,6 +105,7 @@ describe('splitArgs', () => {
|
||||
).toEqual({
|
||||
base: 'main',
|
||||
skipNxCache: false,
|
||||
skipRemoteCache: false,
|
||||
});
|
||||
});
|
||||
|
||||
@ -193,6 +197,7 @@ describe('splitArgs', () => {
|
||||
).toEqual({
|
||||
projects: ['aaa', 'bbb'],
|
||||
skipNxCache: false,
|
||||
skipRemoteCache: false,
|
||||
});
|
||||
});
|
||||
|
||||
@ -217,6 +222,7 @@ describe('splitArgs', () => {
|
||||
base: 'envVarSha1',
|
||||
head: 'envVarSha2',
|
||||
skipNxCache: false,
|
||||
skipRemoteCache: false,
|
||||
});
|
||||
|
||||
expect(
|
||||
@ -234,6 +240,7 @@ describe('splitArgs', () => {
|
||||
base: 'envVarSha1',
|
||||
head: 'directlyOnCommandSha1',
|
||||
skipNxCache: false,
|
||||
skipRemoteCache: false,
|
||||
});
|
||||
|
||||
expect(
|
||||
@ -251,6 +258,7 @@ describe('splitArgs', () => {
|
||||
base: 'directlyOnCommandSha2',
|
||||
head: 'envVarSha2',
|
||||
skipNxCache: false,
|
||||
skipRemoteCache: false,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@ -35,6 +35,7 @@ export interface NxArgs {
|
||||
select?: string;
|
||||
graph?: string | boolean;
|
||||
skipNxCache?: boolean;
|
||||
skipRemoteCache?: boolean;
|
||||
outputStyle?: string;
|
||||
nxBail?: boolean;
|
||||
nxIgnoreCycles?: boolean;
|
||||
@ -182,7 +183,15 @@ export function splitArgsIntoNxArgsAndOverrides(
|
||||
}
|
||||
|
||||
if (!nxArgs.skipNxCache) {
|
||||
nxArgs.skipNxCache = process.env.NX_SKIP_NX_CACHE === 'true';
|
||||
nxArgs.skipNxCache =
|
||||
process.env.NX_SKIP_NX_CACHE === 'true' ||
|
||||
process.env.NX_DISABLE_NX_CACHE === 'true';
|
||||
}
|
||||
|
||||
if (!nxArgs.skipRemoteCache) {
|
||||
nxArgs.skipRemoteCache =
|
||||
process.env.NX_DISABLE_REMOTE_CACHE === 'true' ||
|
||||
process.env.NX_SKIP_REMOTE_CACHE === 'true';
|
||||
}
|
||||
|
||||
normalizeNxArgsRunner(nxArgs, nxJson, options);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user