Fork me on GitHub
#polylith
<
2024-01-26
>
donavan18:01:36

Is it a reasonable idea to extend the poly tool from within one’s project? I’m considering polylith as a partial replacement to my custom tooling.

seancorfield18:01:16

Can you be a bit more specific about what you're doing/thinking? At work, we run the poly tool via Clojure shell to get lists of changes etc, without trying to use it as a library.

donavan18:01:35

I have a tool that starts a development JVM, has commands and covers some ground that the poly tool does; I was considering the reasonableness of writing custom commands available within the poly tool on a specific project.

imre19:01:36

We started doing something similar as part of our (currently on hold) migration to polylith. Have a dev jvm that pulls in the poly tool and other tools we use and use them to carry out the build pipeline tasks. I don't think poly itself is officially extensible with commands but one can wrap the tool I believe

john-shaffer02:01:42

I use poly as a library calling projects-to-deploy since that is what polylith's build.clj does. Works well for me.

seancorfield02:01:33

We get that information via a CLI call from our build.clj:

(defn- changed-projects
  "Produce the list of projects that need building.

  `since` should be `:before-tag` or `:after-tag`"
  [since]
  (let [{:keys [exit out]}
        (run-task {:aliases [:poly]
                   :out     :capture
                   :exit    :capture
                   :main-args
                   ["ws"
                    "get:changes:changed-or-affected-projects"
                    (str "since:"
                         (case since
                           :before-tag "release"
                           :after-tag  "previous-release"))
                    "skip:dev"
                    "color-mode:none"]})]
    (if (zero? exit)
      (edn/read-string out)
      (throw (ex-info "Unable to determine changed projects"
                      {:exit exit :out out})))))

seancorfield02:01:54

(I'd be wary of calling any of the Polylith internals from my own code -- but the CLI interface is pretty well-defined and documented)

seancorfield02:01:47

run-task is a generic subprocess runner, based on aliases (similar to what's in the http://clojure-doc.org tools.build cookbook).

john-shaffer03:01:54

It's https://cljdoc.org/d/polylith/clj-poly/0.2.18/doc/ci/polylith-ci-setup#_deploy from the poly tool docs as an example, so I thought we were meant to use that API. But on a second reading, maybe build.clj changed since that was written.?

seancorfield05:01:32

Here's the 0.2.19-SNAPSHOT version of the API and it seems minimal and offers a reasonably firm guarantee of non-breakage, so I guess that function is safe to depend on (but I wouldn't depend on other namespaces -- and even tho' it says they don't mean to break the test runner, 0.2.19 has breaking changes compared to 0.2.18, but only a couple of test runners exist at this point and one has already been updated to work with both versions): https://cljdoc.org/d/polylith/clj-poly/0.2.19-SNAPSHOT/api/polylith.clj.core.api.interface#api-version

tengstrand06:01:24

We have an example in the documentation on how to use clj-poly from a build script in the documentation https://cljdoc.org/d/polylith/clj-poly/0.2.18/api/polylith.clj.core.api. In the same page we also say "If you need more access than is exposed by the API at the moment, just reach out to the Polylith team in https://clojurians.slack.com/messages/C013B7MQHJQ and we will try to help out."