Skip to content

Commit

Permalink
Merge branch 'master' into feat/repl-starter
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/release.yml
#	deps.edn
#	packages/kmono/deps.edn
#	packages/kmono/justfile
#	packages/kmono/src/k16/kmono/adapters/clojure_deps.clj
#	packages/kmono/src/k16/kmono/config.clj
  • Loading branch information
armed committed Feb 12, 2024
2 parents 398c128 + c1f6dcf commit 0a751b9
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 112 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,6 +52,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' }} \
Expand Down
48 changes: 48 additions & 0 deletions build/build.clj
Original file line number Diff line number Diff line change
@@ -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})}))
3 changes: 3 additions & 0 deletions build/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{:paths ["./"]
:deps {io.github.clojure/tools.build {:mvn/version "0.9.6"}
slipset/deps-deploy {:mvn/version "0.2.2"}}}
15 changes: 4 additions & 11 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
{:mvn/repos {"github-kepler" {:url "https://maven.pkg.github.com/kepler16/*"}}
:aliases {:storm {:classpath-overrides {org.clojure/clojure nil}
:extra-deps {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."]}
:dev {:extra-deps {kepler16/kmono {:local/root "packages/kmono"}}}
:kmono {:deps {kepler16/kmono {:local/root "packages/kmono"}}
:main-opts ["-m" "k16.kmono.main"]}}}
{:deps {local/build {:local/root "build"}}

:aliases {:kmono {:deps {com.kepler16/kmono {:local/root "packages/kmono"}}
:ns-default k16.kmono.api}}}
9 changes: 5 additions & 4 deletions packages/kmono/deps.edn
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -15,7 +14,9 @@
org.flatland/ordered {:mvn/version "1.15.11"}
org.clojure/tools.cli {:mvn/version "1.0.219"}}

:aliases {:lib {:k16/metabuild {:kind :jar}}
:aliases {:build {:deps {local/build {:local/root "../../build"}}
:ns-default build}
:lib {:k16/metabuild {:kind :jar}}
:uber {:k16/metabuild {:kind :uber
:main k16.kmono.main}}
:native {:extra-deps {com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}}}
Expand Down
14 changes: 6 additions & 8 deletions packages/kmono/justfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
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

build: clean
clojure -T:build build

build-uber-native:
clojure -T:meta run :alias uber :include-aliases '[:native]' :uber-file \"target/kmono-uber.jar\"
release:
clojure -T:meta deploy :repository \"{{ maven_server }}\" :lib {{ library }} :version \"{{ version }}\"
clojure -T:build release
native-image:
$GRAALVM_HOME/bin/native-image \
Expand All @@ -26,4 +25,3 @@ native-image:
--initialize-at-build-time=org.eclipse.aether.transport.http.HttpTransporterFactory
build-native: build-uber-native native-image
83 changes: 41 additions & 42 deletions packages/kmono/src/k16/kmono/adapters/clojure_deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,48 @@
([package-path]
(->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
(let [deps-edn (read-deps-edn package-path)
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]
(pr-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)))))))))
46 changes: 24 additions & 22 deletions packages/kmono/src/k16/kmono/adapters/kmono_edn.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))))
36 changes: 19 additions & 17 deletions packages/kmono/src/k16/kmono/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -30,31 +29,35 @@
(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)]
(assert pkg-commit-sha
(str "Failed to get commit-sha. Given package directory ["
package-dir
"] has no git history"))
(let [pkg-config (merge kb-pkg-config
(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)
_ (assert pkg-commit-sha
(str "Failed to get commit-sha. Given package directory ["
package-dir
"] has no git history"))
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]}
Expand Down Expand Up @@ -153,4 +156,3 @@
:package-map (->pkg-map packages)
:graph graph
:build-order (parallel-topo-sort graph)})))))

0 comments on commit 0a751b9

Please sign in to comment.