We currently have a bunch of bash files in our CI ...
# general
We currently have a bunch of bash files in our CI pipeline that get the list of targets to build (using
list, dependees, minimize, filter
). Is there a way to write a pants plugin that invokes these goals?
To clarify, you invoke several Pants commands and you'd prefer to have one custom command that does the same work?
yes, right now we do this:
Copy code
local changed
  changed=($(./pants ${changed_parent} list))
  if [[ -z $changed ]]; then
    return 0

  local dependees
  dependees=($(./pants dependees --dependees-transitive --dependees-closed "${changed[@]}"))
  local minimized
  minimized=($(./pants minimize "${dependees[@]}"))

  local changed_targets
  changed_targets=($(./pants filter ${filter} "${minimized[@]}"))

  echo "Got changed targets ${changed_targets[@]}" "${TARGETS[@]}"
  TARGETS=("${changed_targets[@]}" "${TARGETS[@]}")
But bash syntax is clunky and we would like to add some more logic that would be easier to write in python. We would rather do
./pants run-ci-pipeline --step test
that would run the needed steps to calculate the targets and run tests against them
Yep, that should absolutely be possible with a custom goal. What version of Pants are you on, and what languages are you targeting?
we are on 1.29.0 and build scala projects
OK, so you need the plugin API for the v1 engine, not the one for the new v2 engine (which doesn't have Scala support yet).
You'll want to create a custom v1 task, as described here: https://v1.pantsbuild.org/dev_tasks.html
You can see examples (including of the tasks that implement the
list, dependees, minimize, filter
functionality you're currently using separately) here: https://github.com/pantsbuild/pants/tree/1.29.x/src/python/pants/backend/project_info, https://github.com/pantsbuild/pants/tree/1.29.x/src/python/pants/backend/graph_info/tasks
(note the 1.29.x branch, the v1 code has been removed in the main development branch, as we're working towards a 2.x launch)