From a007e5d153f1c6c92f46ce35e5c8c877f707e3c0 Mon Sep 17 00:00:00 2001 From: Julien Vincent Date: Thu, 18 Jan 2024 15:47:07 +0000 Subject: [PATCH 1/3] patch: Ignore dependencies with no kmono config --- .../src/k16/kmono/adapters/clojure_deps.clj | 83 ++++++++++--------- .../src/k16/kmono/adapters/kmono_edn.clj | 46 +++++----- packages/kmono/src/k16/kmono/config.clj | 28 ++++--- 3 files changed, 81 insertions(+), 76 deletions(-) diff --git a/packages/kmono/src/k16/kmono/adapters/clojure_deps.clj b/packages/kmono/src/k16/kmono/adapters/clojure_deps.clj index a29f813..f847e63 100644 --- a/packages/kmono/src/k16/kmono/adapters/clojure_deps.clj +++ b/packages/kmono/src/k16/kmono/adapters/clojure_deps.clj @@ -47,48 +47,49 @@ (->adapter package-path 10000)) ([package-path timeout-ms] (let [deps-edn (read-deps-edn package-path) - {:keys [group artifact] :as config} - (-> (:kmono/config deps-edn) - (adapter/ensure-artifact package-path)) - coord (str group "/" artifact) - managed-deps (get-local-deps config deps-edn)] - (reify Adapter + kmono-config (:kmono/config deps-edn)] + (when kmono-config + (let [{:keys [group artifact] :as config} + (-> kmono-config + (adapter/ensure-artifact package-path)) + coord (str group "/" artifact) + managed-deps (get-local-deps config deps-edn)] + (reify Adapter - (prepare-deps-env [_ changes] - (binding [*print-namespace-maps* false] - (str "'" - {:deps - (into {} (map - (fn [dep] - [(symbol dep) - {:mvn/version - (get-in changes [dep :version])}])) - managed-deps)} - "'"))) + (prepare-deps-env [_ changes] + (binding [*print-namespace-maps* false] + (str "'" + {:deps + (into {} (map + (fn [dep] + [(symbol dep) + {:mvn/version + (get-in changes [dep :version])}])) + managed-deps)} + "'"))) - (get-managed-deps [_] managed-deps) + (get-managed-deps [_] managed-deps) - (get-kmono-config [_] config) - - (release-published? [_ version] - (-> (p/vthread - (let [;; ignore user's local repository cache - local-repo (str package-path "/.kmono/" artifact "/.m2")] - (try (deps.util.session/with-session - (let [;; ignoring user's machine local m2 repo - versions (->> (deps.ext/find-versions - (symbol coord) - nil - :mvn {:mvn/local-repo local-repo - :mvn/repos - (merge deps.util.maven/standard-repos - (:mvn/repos deps-edn))}) - (map :mvn/version) - (set))] - (contains? versions version))) - (finally - (try (fs/delete-tree local-repo) - (catch Throwable _)))))) - (p/timeout timeout-ms (str "Timeout resolving mvn version for package " coord)) - (deref))))))) + (get-kmono-config [_] config) + (release-published? [_ version] + (-> (p/vthread + (let [;; ignore user's local repository cache + local-repo (str package-path "/.kmono/" artifact "/.m2")] + (try (deps.util.session/with-session + (let [;; ignoring user's machine local m2 repo + versions (->> (deps.ext/find-versions + (symbol coord) + nil + :mvn {:mvn/local-repo local-repo + :mvn/repos + (merge deps.util.maven/standard-repos + (:mvn/repos deps-edn))}) + (map :mvn/version) + (set))] + (contains? versions version))) + (finally + (try (fs/delete-tree local-repo) + (catch Throwable _)))))) + (p/timeout timeout-ms (str "Timeout resolving mvn version for package " coord)) + (deref))))))))) diff --git a/packages/kmono/src/k16/kmono/adapters/kmono_edn.clj b/packages/kmono/src/k16/kmono/adapters/kmono_edn.clj index 3862e40..9b5d332 100644 --- a/packages/kmono/src/k16/kmono/adapters/kmono_edn.clj +++ b/packages/kmono/src/k16/kmono/adapters/kmono_edn.clj @@ -10,25 +10,27 @@ ([package-path] (->adapter package-path 10000)) ([package-path _] - (let [kmono-config (-> (fs/file package-path "kmono.edn") - (slurp) - (edn/read-string)) - config (adapter/ensure-artifact kmono-config package-path) - managed-deps (get config :local-deps [])] - (reify Adapter - - (prepare-deps-env [_ changes] - (string/join - ";" - (map - (fn [dep] - (str (symbol dep) - "@" - (get-in changes [dep :version]))) - managed-deps))) - - (get-managed-deps [_] managed-deps) - - (get-kmono-config [_] config) - - (release-published? [_ _] false))))) + (let [kmono-file (fs/file package-path "kmono.edn")] + (when (fs/exists? kmono-file) + (let [kmono-config (-> kmono-file + (slurp) + (edn/read-string)) + config (adapter/ensure-artifact kmono-config package-path) + managed-deps (get config :local-deps [])] + (reify Adapter + + (prepare-deps-env [_ changes] + (string/join + ";" + (map + (fn [dep] + (str (symbol dep) + "@" + (get-in changes [dep :version]))) + managed-deps))) + + (get-managed-deps [_] managed-deps) + + (get-kmono-config [_] config) + + (release-published? [_ _] false))))))) diff --git a/packages/kmono/src/k16/kmono/config.clj b/packages/kmono/src/k16/kmono/config.clj index da7f9bc..fb0ea3c 100644 --- a/packages/kmono/src/k16/kmono/config.clj +++ b/packages/kmono/src/k16/kmono/config.clj @@ -15,9 +15,8 @@ (defn get-adapter [pkg-dir] - (if (fs/exists? (fs/file pkg-dir "kmono.edn")) - (kmono.edn/->adapter (fs/file pkg-dir)) - (clj.deps/->adapter (fs/file pkg-dir)))) + (or (kmono.edn/->adapter (fs/file pkg-dir)) + (clj.deps/->adapter (fs/file pkg-dir)))) (defn- assert-schema! [?schema value] @@ -30,28 +29,32 @@ (assert-schema! schema/?Config config)) (defn- create-package-config [package-dir] - (let [adapter (get-adapter package-dir) - kb-pkg-config (->> (adapter/get-kmono-config adapter) - (assert-schema! schema/?KmonoPackageConfig)) - artifact (or (:artifact kb-pkg-config) - (symbol (fs/file-name package-dir))) - pkg-name (str (:group kb-pkg-config) "/" artifact) - pkg-commit-sha (git/subdir-commit-sha package-dir)] + (when-let [adapter (get-adapter package-dir)] + (let [kb-pkg-config (->> (adapter/get-kmono-config adapter) + (assert-schema! schema/?KmonoPackageConfig)) + artifact (or (:artifact kb-pkg-config) + (symbol (fs/file-name package-dir))) + pkg-name (str (:group kb-pkg-config) "/" artifact) + pkg-commit-sha (git/subdir-commit-sha package-dir) - (let [pkg-config (merge kb-pkg-config + pkg-config (merge kb-pkg-config {:artifact (or (:artifact kb-pkg-config) (symbol (fs/file-name package-dir))) :name pkg-name :commit-sha pkg-commit-sha :adapter adapter :dir (str package-dir)})] + (->> (assoc pkg-config :depends-on (adapter/get-managed-deps adapter)) (assert-schema! schema/?Package))))) (defn- create-config [repo-root glob] (let [package-dirs (fs/glob repo-root glob)] - {:packages (mapv create-package-config package-dirs)})) + {:packages (->> package-dirs + (map create-package-config) + (remove nil?) + vec)})) (defn create-graph {:malli/schema [:=> [:cat schema/?Packages] schema/?Graph]} @@ -149,4 +152,3 @@ :package-map (->pkg-map packages) :graph graph :build-order (parallel-topo-sort graph)}))))) - From 4d05342b3a1a4be274a4502f69b0233cef467798 Mon Sep 17 00:00:00 2001 From: Julien Vincent Date: Thu, 18 Jan 2024 16:53:25 +0000 Subject: [PATCH 2/3] major: Don't wrap extra deps env in "'" chars --- .../src/k16/kmono/adapters/clojure_deps.clj | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/kmono/src/k16/kmono/adapters/clojure_deps.clj b/packages/kmono/src/k16/kmono/adapters/clojure_deps.clj index f847e63..7dbc095 100644 --- a/packages/kmono/src/k16/kmono/adapters/clojure_deps.clj +++ b/packages/kmono/src/k16/kmono/adapters/clojure_deps.clj @@ -58,15 +58,13 @@ (prepare-deps-env [_ changes] (binding [*print-namespace-maps* false] - (str "'" - {:deps - (into {} (map - (fn [dep] - [(symbol dep) - {:mvn/version - (get-in changes [dep :version])}])) - managed-deps)} - "'"))) + (pr-str {:deps + (into {} (map + (fn [dep] + [(symbol dep) + {:mvn/version + (get-in changes [dep :version])}])) + managed-deps)}))) (get-managed-deps [_] managed-deps) From b449288eccb2832cd96a40b4908e05aab2512767 Mon Sep 17 00:00:00 2001 From: Julien Vincent Date: Thu, 18 Jan 2024 17:00:11 +0000 Subject: [PATCH 3/3] patch: Release to clojars instead of github --- .github/workflows/release.yml | 22 +++------------- build/build.clj | 48 +++++++++++++++++++++++++++++++++++ build/deps.edn | 3 +++ deps.edn | 13 +++------- packages/kmono/deps.edn | 12 ++++----- packages/kmono/justfile | 14 +++++----- 6 files changed, 68 insertions(+), 44 deletions(-) create mode 100644 build/build.clj create mode 100644 build/deps.edn diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ed4881c..98c9cc6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,16 +3,8 @@ on: [push] jobs: build-and-publish: - permissions: - contents: write - packages: write - runs-on: ubuntu-latest - env: - GITHUB_USERNAME: ${{ secrets.ORG_GITHUB_ACTOR }} - GITHUB_TOKEN: ${{ secrets.ORG_GITHUB_TOKEN }} - steps: - name: Checkout git repo uses: actions/checkout@v2 @@ -40,17 +32,6 @@ jobs: with: cli: latest - - uses: s4u/maven-settings-action@v2.4.1 - with: - githubServer: false - servers: | - [{"id": "github-kepler", - "username": "${{ secrets.ORG_GITHUB_ACTOR }}", - "password": "${{ secrets.ORG_GITHUB_TOKEN }}"}, - {"id": "github-kepler-kmono", - "username": "${{ github.actor }}", - "password": "${{ secrets.GITHUB_TOKEN }}"}] - # - name: Test # run: | # just test ":snapshot?" ${{ github.ref_name != 'master' }} @@ -60,6 +41,9 @@ jobs: just build ":snapshot?" ${{ github.ref_name != 'master' }} - name: Release + env: + CLOJARS_USERNAME: infrastructure-kepler16-com + CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }} run: | just release \ ":snapshot?" ${{ github.ref_name != 'master' }} \ diff --git a/build/build.clj b/build/build.clj new file mode 100644 index 0000000..e36b056 --- /dev/null +++ b/build/build.clj @@ -0,0 +1,48 @@ +(ns build + (:require + [clojure.edn :as edn] + [clojure.java.io :as io] + [clojure.tools.build.api :as b] + [deps-deploy.deps-deploy :as deps-deploy])) + +(def basis (delay (b/create-basis {}))) + +(def kmono-config + (-> (io/file "deps.edn") + slurp + edn/read-string + :kmono/config)) + +(def lib (symbol (or (System/getenv "KMONO_PKG_NAME") + (str (:group kmono-config) "/" (:artifact kmono-config))))) +(def version (or (System/getenv "KMONO_PKG_VERSION") "0.0.0")) +(def class-dir "target/classes") +(def jar-file "target/lib.jar") + +(defn clean [_] + (b/delete {:path "target"})) + +(defn build [_] + (b/write-pom {:class-dir class-dir + :lib lib + :version version + :basis @basis + :src-dirs ["src"] + :pom-data [[:description "Clojure monorepo tools"] + [:url "https://github.com/kepler16/kmono"] + [:licenses + [:license + [:name "MIT"] + [:url "https://opensource.org/license/mit"]]]]}) + + (b/copy-dir {:src-dirs ["src"] + :target-dir class-dir}) + + (b/jar {:class-dir class-dir + :jar-file jar-file})) + +(defn release [_] + (deps-deploy/deploy {:installer :remote + :artifact (b/resolve-path jar-file) + :pom-file (b/pom-path {:lib lib + :class-dir class-dir})})) diff --git a/build/deps.edn b/build/deps.edn new file mode 100644 index 0000000..b77496b --- /dev/null +++ b/build/deps.edn @@ -0,0 +1,3 @@ +{:paths ["./"] + :deps {io.github.clojure/tools.build {:mvn/version "0.9.6"} + slipset/deps-deploy {:mvn/version "0.2.2"}}} diff --git a/deps.edn b/deps.edn index 09e5692..13c7ca0 100644 --- a/deps.edn +++ b/deps.edn @@ -1,11 +1,4 @@ -{:mvn/repos {"github-kepler" {:url "https://maven.pkg.github.com/kepler16/*"}} - :aliases {:dev {:classpath-overrides {org.clojure/clojure nil} - :extra-deps {kepler16/kmono {:local/root "packages/kmono"} - com.github.flow-storm/clojure {:mvn/version "1.11.1-11"} - com.github.flow-storm/flow-storm-dbg {:mvn/version "3.8.3"}} - :jvm-opts ["-Dclojure.storm.instrumentEnable=true" - "-Dclojure.storm.traceEnable=true" - "-Dflowstorm.theme=dark" - "-Dclojure.storm.instrumentOnlyPrefixes=k16."]} - :kmono {:deps {kepler16/kmono {:local/root "packages/kmono"}} +{:deps {local/build {:local/root "build"}} + + :aliases {:kmono {:deps {com.kepler16/kmono {:local/root "packages/kmono"}} :ns-default k16.kmono.api}}} diff --git a/packages/kmono/deps.edn b/packages/kmono/deps.edn index a040034..b8a227f 100644 --- a/packages/kmono/deps.edn +++ b/packages/kmono/deps.edn @@ -1,6 +1,5 @@ -{:mvn/repos {"github-kepler" {:url "https://maven.pkg.github.com/kepler16/*"} - "github-kepler-kmono" {:url "https://maven.pkg.github.com/kepler16/kmono"}} - :kmono/config {:group kepler16 +{:kmono/config {:group com.kepler16 + :artifact kmono :build-cmd "just build" :release-cmd "just release"} :paths ["src" "resources"] @@ -14,7 +13,6 @@ metosin/malli {:mvn/version "0.11.0"} org.flatland/ordered {:mvn/version "1.15.11"}} - :aliases {:lib {:k16/metabuild {:kind :jar}} - :test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.86.1355"}}} - :meta {:deps {kepler16/metabuild {:mvn/version "0.10.0"}} - :ns-default k16.metabuild.api}}} + :aliases {:build {:deps {local/build {:local/root "../../build"}} + :ns-default build} + :test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.86.1355"}}}}} diff --git a/packages/kmono/justfile b/packages/kmono/justfile index d978e7f..414fe09 100644 --- a/packages/kmono/justfile +++ b/packages/kmono/justfile @@ -1,13 +1,11 @@ -library := "kepler16/kmono" -version := "$KMONO_PKG_VERSION" -maven_server := "github-kepler-kmono" - test: clojure -M:test -m "kaocha.runner" -build: - clojure -T:meta run :alias lib :lib {{ library }} :version \"{{ version }}\" +clean: + clojure -T:build clean -release: - clojure -T:meta deploy :repository \"{{ maven_server }}\" :lib {{ library }} :version \"{{ version }}\" +build: clean + clojure -T:build build +release: + clojure -T:build release