nx icon indicating copy to clipboard operation
nx copied to clipboard

feat(core): add support for tags with `(print-)affected(:*)` and `run-many`

Open fguitton opened this issue 2 years ago • 10 comments

Current Behavior

When running the (print-)affected(:*) command you get all affected projects for a target. With the run-many command filtering is only possible with --projects. Both accept a --all, it being warned for in affected.

Expected Behavior

We would expect to be able to select projects by tags.

This PR

This could be seen as a first step only acting to select projects in the same way --projects does it for run-many. Tags are not applied in compound but rather as OR statement in comma separated fashion.

That is in the example below the command would select projects that either contain the tag sdk or the tag app, not necessarily projects containing both tags.

nx affected --tags=sdk,app --target=test

Related Issue(s)

This relates to very long standing #1621, #2675 or #8292 and a Nx v14 compatible treatment while being different from #8364 which attempts to support globs but does not address run-many.

Closes #1621 Closes #2675

fguitton avatar May 01 '22 13:05 fguitton

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 6, 2023 6:30pm

vercel[bot] avatar May 01 '22 13:05 vercel[bot]

Hello @vsavkin ! I know you had interest in looking at this over the past few years. It is the second PR opened for this feature but it addressed things slightly differently. I am happy to bring any changes required, any feedback/direction is most welcome We have a lot of need for this in our company.

Thank you for your help and valuable time 🙏🏼 !

fguitton avatar May 01 '22 13:05 fguitton

Any update on this? I would love to use it 😁 Also, I thought it might be worth adding this to print-affected as well

gioragutt avatar May 16 '22 18:05 gioragutt

I thought it might be worth adding this to print-affected as well

Hello ! The print-affected command should already work out of the box with the changes proposed at it is considered a special branch of the affected command and the project filtering gets done upstream of that.

https://github.com/nrwl/nx/blob/7f5137da84e5d0f1b31f9011c57fc0e3bfaa9252/packages/nx/src/command-line/affected.ts#L37

https://github.com/nrwl/nx/blob/7f5137da84e5d0f1b31f9011c57fc0e3bfaa9252/packages/nx/src/command-line/affected.ts#L79-L113

I can imagine there is latent question with regard to the use/semantic of --exclude which only applies to project names. I do not necessarily have a set opinion on this. In effect a tag filtering can very much replace the use of --exclude.

fguitton avatar May 17 '22 08:05 fguitton

Would love to see this merged into Nx and my PR closed.

yharaskrik avatar May 24 '22 14:05 yharaskrik

This would be a big QoL feature for us, would love to see this in the next release! Any indications when that might be?

epechuzal avatar Jun 24 '22 22:06 epechuzal

Can't wait for this to be merged :smile:

sylvainar avatar Jun 30 '22 08:06 sylvainar

pls

josh-stevens avatar Jul 29 '22 16:07 josh-stevens

This would be a great QoL feature for our team 👍

starch avatar Jul 29 '22 16:07 starch

@gioragutt

jon9090 avatar Oct 15 '22 05:10 jon9090

@gioragutt

Can you add some context to why you tagged me? 😅

gioragutt avatar Oct 15 '22 07:10 gioragutt

My team and I are so excited about this feature please release it in next version :)

jon9090 avatar Oct 31 '22 15:10 jon9090

Would really like this!

Use-case: only publish to the public npm registry packages tagged with open-source.

ianldgs avatar Nov 25 '22 15:11 ianldgs

Also interested in this. I want to be able to get a list of affected projects filtered by tag. Use case is for use with the nx dotnet plugin. When I generate a dotnet app it actually generates 2 app. One is the main dotnet app. The other is a test app. I want to get a list of affected apps excluding the test apps.

mrfelton avatar Nov 26 '22 12:11 mrfelton

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d2ffdb6ca361841c6117eed0df2cd7d59b0d3bca. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

nx-cloud[bot] avatar Dec 08 '22 22:12 nx-cloud[bot]

When this feature will be published? I'm wating for it. Use case: create separate ci/cd pipelines for projects in different technologies, like js and dotnet (with nx dotnet plugin)

msz13 avatar Dec 12 '22 14:12 msz13

@fguitton thank you for keeping this up to date for when they finally merge this 🙏🏻 I'm amused every time I get a notification about a rebase 😂

gioragutt avatar Jan 30 '23 00:01 gioragutt

I'm amused every time I get a notification about a rebase

Haha ! You're most welcome. I guess I'm being a bit overzealous on this one 😅 . It's almost going to be the oldest non-merged (or closed) pull-request now ! 😄

fguitton avatar Jan 30 '23 14:01 fguitton

Is there anything specific that is blocking this from being merged?

mrfelton avatar Jan 30 '23 14:01 mrfelton

@gioragutt

for when they finally merge this

We are now officially the oldest open pull request at sea. Hehe. Perhaps this means we're next ! 😃

fguitton avatar Mar 03 '23 11:03 fguitton

@gioragutt

for when they finally merge this

We are now officially the older open pull request at sea. Hehe. Perhaps this means we're next ! 😃

That's actually funny 😄 and again, kudos to you for keeping it up all this time 🙏🏻

gioragutt avatar Mar 03 '23 11:03 gioragutt

@fguitton Actually, after discussing this with @vsavkin a bit more today there is a bit more involved change that we'd like to make to properly support this and open some more doors in the future. Have you joined our community slack? I'd love to connect there and offer some more insight.

Here's the link if you aren't there yet, just dm me 😄: https://go.nrwl.io/join-slack

AgentEnder avatar Mar 15 '23 17:03 AgentEnder

@AgentEnder, So I found a bit of time to explore the direction you indicated and I have updated the PR to use this new approach.

The findMatchingProjects function has been modified to a operated on the following pattern: [tag:]filter[,...]. I have also removed the Set(...) performance bailout but making sure the performance test on CI were satisfied.

The principle stays the same and the change still covers (print-)affected(:*) and run-many but everything now happens through --projects argument. I have also made sure to permit a similar logic for the --exclude commutator as well, making sure is it backward compatible.

Negative filtering is supported and the syntax is flexible; either !tag:ui or tag:!ui indifferently.

Mix of project name and tag filters are also supported with an non-chained, negation-takes-all behaviour. Meaning the order of filters has no impact and we prefer to exclude in all cases.

I took the liberty to remove the mentions that tags only served for linting as well as added a couple of unit tests to insure that things behaved properly.

Feedback is obviously welcome, looking forward to this being merged in !

Best wishes 🌴

fguitton avatar Apr 01 '23 18:04 fguitton

Awesome! Thanks for the updates @fguitton. I'll look over this either today or tomorrow.

AgentEnder avatar Apr 03 '23 14:04 AgentEnder

Thank you @AgentEnder ! Extending to the whole Nx team of course ! Thrilled to see this merged 🎉

fguitton avatar Apr 06 '23 18:04 fguitton

Congrats @fguitton, you've put a lot of work on this and it shows! Thank you for all your effort, I'm sure it'll bring immense value to a lot of people 🙏🏻🙏🏻🙏🏻

gioragutt avatar Apr 06 '23 19:04 gioragutt

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

github-actions[bot] avatar Apr 12 '23 00:04 github-actions[bot]