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): add an option to run-many by tags #4557

Closed
wants to merge 1 commit into from

Conversation

Schibum
Copy link

@Schibum Schibum commented Jan 18, 2021

nx run-many --target=deploy --tags=foo runs the given target for all
projects that have a tag foo configured in nx.json.

Closes #2675.

Current Behavior

nx run-many --target=build --all

and

nx run-many --target=build --projects=p1,p2

are supported with nx run-many.

Expected Behavior

Add a --tags option (mutually exclusive with --all and --projects) that allows to target projects by tags as configured in nx.json. E.g.:

nx run-many --target=deploy --tags=tag1,tag2

Would run build for any project tagged with tag1 or tag2.

@Schibum Schibum force-pushed the run_many_tags branch 5 times, most recently from a6d133b to ba94562 Compare January 18, 2021 15:40
@Schibum Schibum marked this pull request as ready for review January 18, 2021 15:56
@AgentEnder
Copy link
Member

Related: #3812

@ludicast
Copy link

love (and need!) this ❤️

@Schibum
Copy link
Author

Schibum commented Feb 19, 2021

Any thoughts on this? Would be quite useful to simplify deployments in our case.

@ashwinGokhale
Copy link
Contributor

@FrozenPandaz any plans to review this PR? This would be a huge improvement to our developer experience.

Comment on lines 327 to 336
.check(({ all, projects, tags }) => {
if (
(all && projects) ||
(projects && tags) ||
(all && tags) ||
(!all && !projects && !tags)
)
throw new Error(
'You must provide either --all or --projects or --tags'
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to:

const suppliedArgs = !!all + !!projects + !!tags;
if (suppliedArgs === 1) {
  return true;
} else {
  // throw error
}

Optionally you may remove the redundant else here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ updated and rebased

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and fixed lint, green on CI again

`nx run-many --target=deploy --tags=foo` runs the given target for all
projects that have a tag `foo` configured in nx.json.

Closes nrwl#2675.
@Schibum
Copy link
Author

Schibum commented Apr 26, 2021

Any change for this getting merged at all near-term? If not I'll close this and figure out another way for us internally.

@FrozenPandaz
Copy link
Collaborator

Sorry @Schibum I don't think we will be merging this soon. @vsavkin and I have been discussing using --tags for run-many and affected for a while. We don't think this feature is out of the question. However, we're not sure it promotes the best practices. Before this is implemented, I think the discussion should continue to clarify use cases of this feature.

Having worked in many workspaces large and small, we have yet to see a clear case where this feature would be part of a dev's workflow. It might be a good idea to allow a dev to focus on an area in some cases. But I think in many cases, it may be short-sighted to focus on an area without being concerned about everything that is affected. nx affected is good for limiting concerns in the workspace.

For working on higher-level features, affected focuses on the area being looked at while also considering other areas that are affected by the work. Compared to affected, run-many --tags would probably expand the focus wider than necessary in this case.

For working on shared or core code, run-many --tags would ignore areas that use the code and a dev should be concerned about when working on an area. affected limits the concerns to precisely this.

Perhaps some workspaces are tagged with a different strategy than what we've seen and this feature makes sense there. We've discussed some possible use cases but still aren't clear on when this is ideal.

If you'd like to have this functionality in your workflow, you can explore using --projects along with bash command substitution to list the projects with a tag. Something like nx run-many --projects $(node list-projects-with-tags.js tag) should work well.

Again, before this is implemented, I think the discussion should continue to clarify use cases of this feature. Would it be alright to close this PR for now?

@Schibum
Copy link
Author

Schibum commented May 4, 2021

Hi, thank you for clarifying in such a detailed manner. In our case, we'd like to group deployment of multiple projects typically deployed together (using a 'deploy' configured within nx). E.g. we'd be deploying a frontend + backend using a tag such as deploy:project1. In CI, creating a release tag such as project1-v1.0.0 would then run that deploy target for all projects with such a tag.
But I'm fine with closing, we'll just implement that externally to nx as you suggested.

@Schibum Schibum closed this May 4, 2021
@dominikgasior
Copy link

dominikgasior commented Nov 25, 2021

Hi, @FrozenPandaz it would be super cool to have this feature though. I have come across the problem when one team doesn't want to use nx format whereas another team would love to. It would be great to have some kind of shortcut where I can very easily run nx format only for the projects with a tag related to my team.

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] run-many --tags=tag1,tag2
7 participants