Skip to content
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

feat(core): filter affected projects by glob pattern on tags #8364

Closed
Closed
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
6 changes: 6 additions & 0 deletions docs/generated/cli/affected-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/cli/affected-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/cli/affected-dep-graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/cli/affected-e2e.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/cli/affected-libs.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/cli/affected-lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/cli/affected-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/cli/affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### target

Task to run for affected projects
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/cli/format-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/cli/format-write.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/cli/print-affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### target

Task to run for affected projects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### tags

Default: ``

Filter affected projects by tags using glob patterns

### uncommitted

Uncommitted changes
Expand Down
24 changes: 23 additions & 1 deletion packages/workspace/src/command-line/affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { NxArgs, RawNxArgs } from './utils';
import { splitArgsIntoNxArgsAndOverrides } from './utils';
import { performance } from 'perf_hooks';
import type { Environment } from '../core/shared-interfaces';
import * as minimatch from 'minimatch';

export async function affected(
command: 'apps' | 'libs' | 'dep-graph' | 'print-affected' | 'affected',
Expand All @@ -40,7 +41,8 @@ export async function affected(

const projectGraph = await createProjectGraphAsync();
const projects = projectsToRun(nxArgs, projectGraph);
const projectsNotExcluded = applyExclude(projects, nxArgs);
const projectsMatchingTags = matchTags(projects, nxArgs);
const projectsNotExcluded = applyExclude(projectsMatchingTags, nxArgs);
const env = readEnvironment();
const filteredProjects = applyOnlyFailed(projectsNotExcluded, nxArgs, env);

Expand Down Expand Up @@ -132,6 +134,26 @@ export async function affected(
}
}

function matchTags(projects: Record<string, ProjectGraphNode>, nxArgs: NxArgs) {
// We do not want to filter projects if there are no tags passed in to match on
if (!nxArgs.tags || nxArgs.tags.length === 0) {
return projects;
}

const tagGlobs = nxArgs.tags;

return Object.entries(projects)
.filter(([, project]) => {
const tags: string[] = project.data.tags;

/*
* Ensure that each tag passed in (in glob format) exists in the projects tag array
*/
return tagGlobs.every((glob) => tags.some((tag) => minimatch(tag, glob)));
})
.reduce((prev, [key, project]) => ({ ...prev, [key]: project }), {});
}

function projectsToRun(nxArgs: NxArgs, projectGraph: ProjectGraph) {
if (nxArgs.all) return projectGraph.nodes;

Expand Down
6 changes: 6 additions & 0 deletions packages/workspace/src/command-line/nx-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ function withAffectedOptions(yargs: yargs.Argv): yargs.Argv {
.option('verbose', {
describe: 'Print additional error stack trace on failure',
})
.option('tags', {
describe: 'Filter affected projects by tags using glob patterns',
default: [],
type: 'array',
coerce: parseCSV,
})
.conflicts({
files: ['uncommitted', 'untracked', 'base', 'head', 'all'],
untracked: ['uncommitted', 'files', 'base', 'head', 'all'],
Expand Down
Loading