Skip to content

Commit

Permalink
Merge pull request #28 from kepler16/feat/major-refactor
Browse files Browse the repository at this point in the history
breaking: rename `:glob`, `-g` parameter to `:packages`, `-p`
  • Loading branch information
armed authored May 22, 2024
2 parents 6876283 + 5c228e7 commit c789920
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 65 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Modes:
-h, --help Show this help
-x, --exec CMD :build Command to exec [build, release, <custom cmd>]
-r, --repo-root PATH . Repository root (default: '.')
-g, --glob GLOB packages/* A glob describing where to search for packages, (default: 'packages/*')
-p, --packages GLOB packages/* A glob string describing where to search for packages, (default: 'packages/*')
-s, --snapshot FLAG false A snapshot flag (default: false)
-t, --create-tags FLAG false Should create tags flag (default: false)
-i, --include-unchanged FLAG true Should include unchanged packages flag (default: true)
Expand All @@ -157,15 +157,15 @@ Modes:
-A, --aliases :alias1:alias2:namespace/alias3 List of aliases from root deps.edn
-P, --package-aliases :package/alias1:package/alias2 List of aliases from packages
-r, --repo-root PATH . Repository root (default: '.')
-g, --glob GLOB packages/* A glob describing where to search for packages, (default: 'packages/*')
-p, --packages GLOB packages/* A glob string describing where to search for packages, (default: 'packages/*')
-f, --cp-file FILENAME nil Classpath file name (default: do nothing)
=== cp - save/print a classpath ===
-h, --help Show this help
-A, --aliases :alias1:alias2:namespace/alias3 List of aliases from root deps.edn
-P, --package-aliases :package/alias1:package/alias2 List of aliases from packages
-r, --repo-root PATH . Repository root (default: '.')
-g, --glob GLOB packages/* A glob describing where to search for packages, (default: 'packages/*')
-p, --packages GLOB packages/* A glob string describing where to search for packages, (default: 'packages/*')
-f, --cp-file FILENAME nil Classpath file name (default: do nothing)
```

Expand Down Expand Up @@ -217,7 +217,7 @@ One can pass this CLI args to `-T:kmono` command
- `:include-unchanged?` -jk `boolean`, should kmono include unchanged packages into build process (default `false`)
- `:snapshot?` - `boolean`, whether release is a snapshot, useful when releasing from PR branch (default `true`)
- `:create-tags?` - `boolean`, should kmono create new baseline tags after release. Usually baseline tags are created on master releases, not snapshots (default `false`)
- `:glob` - `string`, where to search for packages, defaults to `"packages/*"`
- `:packages` - `string`, where to search for packages, defaults to `"packages/*"`
- `:build-cmd` - `string`, overrides `build-cmd` option from package kmono config
- `:release-cmd` - `string`, overrides `release-cmd` option from package kmono config
- `:repo-root` - `string`, root of the monorepo, defaults to `"."`
Expand Down
11 changes: 7 additions & 4 deletions src/k16/kmono/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[clojure.string :as string]
[k16.kmono.ansi :as ansi]
[k16.kmono.config :as config]
[k16.kmono.config-schema :as schema]
[k16.kmono.exec :as exec]
[k16.kmono.git :as git]
[k16.kmono.repl.deps :as repl.deps]
Expand Down Expand Up @@ -141,7 +142,7 @@
([opts] (run opts nil))
([opts arguments]
(with-assertion-error
(let [[success?] (-run opts arguments)]
(let [[success?] (-run (schema/->internal-config opts) arguments)]
(if success?
(System/exit 0)
(System/exit 1))))))
Expand All @@ -161,7 +162,9 @@
(let [cp-file' (when configure-lsp?
(or (relativize-to-repo-root repo-root cp-file)
(relativize-to-repo-root repo-root ".lsp/.kmonocp")))
opts' (assoc opts :cp-file (str cp-file'))]
opts' (-> opts
(schema/->internal-config)
(assoc :cp-file (str cp-file')))]
(repl.deps/run-repl opts')))))

(defn generate-classpath!
Expand All @@ -170,13 +173,13 @@
([opts _]
(binding [ansi/*logs-enabled* (:cp-file opts)]
(with-assertion-error
(repl.deps/generate-classpath! opts)))))
(repl.deps/generate-classpath! (schema/->internal-config opts))))))

(defn generate-deps!
([opts]
(generate-deps! opts nil))
([opts _]
(binding [ansi/*logs-enabled* (:deps-file opts)]
(with-assertion-error
(repl.deps/generate-deps! opts)))))
(repl.deps/generate-deps! (schema/->internal-config opts))))))

8 changes: 3 additions & 5 deletions src/k16/kmono/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
kmono-merged-props (merge-with merge kmono-props kmono-props-local)
workspace-config (:kmono/workspace kmono-merged-props)]
(when (seq workspace-config)
(ansi/assert-err!
(not (seq (:kmono/package kmono-merged-props)))
"Both `:kmono/package` and `:kmono/workspace can't be set")
(schema/assert-schema!
schema/?KmonoWorkspaceConfig "Workspace config error" workspace-config))
(m/encode schema/?KmonoWorkspaceConfig (or workspace-config {})
schema/?KmonoWorkspaceUserConfig "Workspace config error" workspace-config))
(m/encode schema/?KmonoWorkspaceConfig
(schema/->internal-config (or workspace-config {}))
(mt/default-value-transformer
{::mt/add-optional-keys true}))))

Expand Down
9 changes: 9 additions & 0 deletions src/k16/kmono/config_schema.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns k16.kmono.config-schema
(:require
[clojure.pprint :as pp]
[clojure.set :as set]
[k16.kmono.ansi :as ansi]
[malli.core :as m]
[malli.error :as me]
Expand Down Expand Up @@ -30,6 +31,9 @@
[:group {:optional true}
[:or :string :symbol]]]))

(def ?KmonoWorkspaceUserConfig
(mu/rename-keys ?KmonoWorkspaceConfig {:glob :packages}))

(def ?KmonoPackageConfig
[:map
[:group [:or :string :symbol]]
Expand Down Expand Up @@ -95,3 +99,8 @@
(throw (ex-info title {:type :errors/assertion})))
value))))

(defn ->internal-config
"We don't want packages key internally, because we already have it, so rename it to glob"
[config]
(set/rename-keys config {:packages :glob}))

17 changes: 10 additions & 7 deletions src/k16/kmono/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
["-r" "--repo-root PATH"
"Repository root (default: '.')"
:default "."]
["-g" "--glob GLOB"
"A glob describing where to search for packages, (default: 'packages/*')"
["-p" "--packages GLOB"
"A glob string describing where to search for packages, (default: 'packages/*')"
:id :glob
:default "packages/*"]
["-s" "--snapshot FLAG"
"A snapshot flag (default: false)"
Expand Down Expand Up @@ -77,13 +78,15 @@
["-r" "--repo-root PATH"
"Repository root (default: '.')"
:default "."]
["-g" "--glob GLOB"
"A glob describing where to search for packages, (default: 'packages/*')"
:default nil]
["-p" "--packages GLOB"
"A glob string describing where to search for packages, (default: 'packages/*')"
:id :glob
:default "packages/*"]
["-l" "--configure-lsp"
(str "Set repl specific `:project-specs` in `.lsp/config.edn`, "
"requires cp-file to be set (default: true)")
:id :configure-lsp?]
"requires cp-file to be set (default: false)")
:id :configure-lsp?
:default false]
(cp-option nil "Save classpath file for LSP use (default: do nothing)")])

(def cp-cli-spec
Expand Down
41 changes: 2 additions & 39 deletions src/k16/kmono/util.clj
Original file line number Diff line number Diff line change
@@ -1,51 +1,14 @@
(ns k16.kmono.util
(:require
[babashka.fs :as fs]
[clojure.edn :as edn]
[k16.kmono.git :as git]))

(defn- update-dependant
[{:keys [snapshot? package-map]} changes dependant-name]
(let [dpkg (get package-map dependant-name)
{:keys [version] :as dependant} (get changes dependant-name)
new-version (git/bump {:version version
:bump-type :build
:commit-sha (:commit-sha dpkg)
:snapshot? snapshot?})]
(assoc dependant
:version new-version
:changed? (not= version new-version))))

(defn ensure-dependent-builds
[config changes graph]
(loop [changes' changes
cursor (keys changes)]
(if-let [{:keys [published? package-name]} (get changes' (first cursor))]
(if-not @published?
(let [dependants (->> graph
(map (fn [[pkg-name deps]]
(when (contains? deps package-name)
pkg-name)))
(remove nil?))]
(recur (reduce (fn [chgs dpn-name]
(update-dependant config chgs dpn-name))
changes'
dependants)
(rest cursor)))
(recur changes' (rest cursor)))
changes')))
[clojure.edn :as edn]))

(defn read-deps-edn!
[file-path]
(try
(-> (fs/file file-path)
(slurp)
(edn/read-string)
;; support for legacy name :kmono/config
(update-keys (fn [k]
(if (= k :kmono/config)
:kmono/package
k))))
(edn/read-string))
(catch Throwable e
(throw (ex-info "Could not read deps.edn file"
{:file-path file-path
Expand Down
10 changes: 4 additions & 6 deletions test/k16/kmono/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
(testing "Make feat changes to p1 and release again"
(spit (fs/file repo-root "packages/p1/src/foo.clj")
"(ns foo)\n(println :hello)")
(Thread/sleep 100)
(test-utils/shell-commands! ["git add ."
"git commit -m 'feat: p1 foo added'"])
(Thread/sleep 100)
(is (= [true
[{"kmono-test/p2" {:success? true, :output "no changes"},
"kmono-test/root-module" {:success? true, :output "no changes"},
Expand All @@ -64,9 +64,9 @@
(spit (fs/file repo-root "packages/p2/src/bar.clj")
"(ns bar)\n(println :hello_bar)")
(spit (fs/file repo-root "src/lol.clj") "(ns lol)")
(Thread/sleep 100)
(test-utils/shell-commands! ["git add ."
"git commit -m 'fix: root and p2 bugs'"])
(Thread/sleep 100)
(is (= [true
[{"kmono-test/p2" {:success? true,
:output "release p2\n"},
Expand Down Expand Up @@ -103,17 +103,15 @@
(let [release-opts {:repo-root repo-root}]
(spit (fs/file repo-root "deps.edn")
(str {:kmono/workspace {:group "kmono-wp-test"
:glob "packages/*"
:packages "packages/*"
:aliases [:dev]
:package-aliases [:*/test]
:build-cmd "echo 'build root'"
:release-cmd "echo 'release root'"}
:deps {}
:paths ["src"]}))
(testing "Derive params from workspace"
(with-redefs [repl.deps/cp! (fn [{:keys [package-aliases
aliases]}
sdeps-overrides]
(with-redefs [repl.deps/cp! (fn [{:keys [package-aliases aliases]} _]
(is (= [:kmono/package-deps
:kmono.pkg/p2.test
:kmono.pkg/p1.test]
Expand Down

0 comments on commit c789920

Please sign in to comment.