Is there a way to get a list of libraries or apps ...
# general
p
Is there a way to get a list of libraries or apps under
src/
and
libs/
that have changed since a git point in time (e.g. when using
pants --changed-since=origin/main
)? With
nx
we would do
yarn nx affected --target build --base=${{ needs.set-nx-base.outputs.NX_BASE }}
g
Have you read through https://www.pantsbuild.org/stable/docs/using-pants/advanced-target-selection? Without knowing what nx does, it seems like combining a few of those recipes would do what you want?
p
I'll have a look - thanks
If I make changes under
src/foo
and
src/bar
in a PR, but don't touch
src/baz
, I want to get
src/foo
,
src/bar
returned
To be clearer, I mean a source file under
src/foo
or a source file under
src/bar
g
If you just want the list that also works with
--changed-since
, just to be clear. For the filtering by address you probably want
--filter-address-regex
, and for type you want
--filter-target-type
. I'm not sure 100% how these interact with changed-since and transitive dependencies.
p
pants --changed-since=origin/main list
shows all files changed - I guess I could just pipe that to a script to get the impacted projects or libs
pants --changed-since=origin/main --changed-dependents=transitive  list
also returns
e
You could use --filter-target-type to only select packages/libraries/whatever along with those other options. something like
pants --changed-since=origin/main --changed-dependents=transitive --filter-target-type=docker_image
to find all docker images that have been changed
p
Thanks!
g
That information was also on the page I linked 🙂 Is there anything we can do to make that information more accessible?
p
I'll give that some thought- it just didn't fit in my head as the thing I was looking for
the list of impacted apps (so top level directories under
src
with changed files) came from
pants --changed-since=origin/main             --changed-dependents=transitive list | grep "^src" | grep -v ":"  | cut -f 2 -d '/' | sort | uniq | tr '\n' ',' | tr -d '[:space:]'
but I'm sure using the filter target type will get me there quicker
g
Yeah, combining filters and pipes is a useful pattern. Though if your goal is to have general engineers engage with this, I've found that writing a Python script instead of shell script is more approachable. Then we package that script as a pex and run. So our container publish script starts like this:
Copy code
info = pants(
        f"--changed-since={args.treeish}",
        "--changed-dependees=transitive",
        "--filter-target-type=oci_python_image,oci_image_build",
        "list",
        pants_args=args.pants,
    )
e
From the same page: https://www.pantsbuild.org/stable/docs/using-pants/advanced-target-selection#using-cli-aliases Cli aliases are pretty useful. You could put this into your pants.toml
Copy code
[cli.alias]
--changed-docker = "--changed-since=origin/main --changed-dependents=transitive --filter-target-type=docker_image"
and then use
pants --changed-docker package publish
to build and publish all docker images that have changed
👍 1
p
That's super useful thanks
e
no problem
c
(side note: the
package
step in the example above is redundant.. as
publish
will call
package
behind the scenes)
🤔 1