Skip to content

Commit

Permalink
WIP: Rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Sep 4, 2024
1 parent c785b59 commit f6d9218
Show file tree
Hide file tree
Showing 93 changed files with 2,254 additions and 2,387 deletions.
2 changes: 2 additions & 0 deletions .cljfmt.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:remove-multiple-non-indenting-spaces? true
:sort-ns-references? true}
72 changes: 37 additions & 35 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish kmono 👘
name: Build
on: [push]

jobs:
Expand All @@ -11,52 +11,54 @@ jobs:
with:
fetch-depth: 0

- name: Cache clojure dependencies
uses: actions/cache@v3
with:
path: |
~/.m2/repository
~/.gitlibs
~/.deps.clj
key: cljdeps-${{ hashFiles('deps.edn') }}
restore-keys: cljdeps-

- uses: actions/setup-java@v2
- name: Setup Git
run: |
git config --global user.email "[email protected]"
git config --global user.name "Kmono CI"
# - name: Cache clojure dependencies
# uses: actions/cache@v3
# with:
# path: |
# ~/.m2/repository
# ~/.gitlibs
# ~/.deps.clj
# key: cljdeps-${{ hashFiles('deps.edn') }}
# restore-keys: cljdeps-


- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
distribution: temurin
java-version: 21
cache: 'maven'
cache-dependency-path: '**/deps.edn'

- uses: extractions/setup-just@v1

- uses: DeLaGuardo/[email protected]
with:
cli: latest

- uses: s4u/[email protected]
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
- name: Preload dependencies
run: |
just test
just cli cp -P ':*/*' > /dev/null
- name: Build
run: |
just build ":snapshot?" ${{ github.ref_name != 'master' }}
just build
- name: Release
env:
CLOJARS_USERNAME: infrastructure-kepler16-com
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }}
- name: Test
run: |
just release \
":snapshot?" ${{ github.ref_name != 'master' }} \
":create-tags?" ${{ github.ref_name == 'master' }}
just cli run -M ':*/test'
# - name: Release
# env:
# CLOJARS_USERNAME: infrastructure-kepler16-com
# CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }}
# run: |
# just release \
# ":snapshot?" ${{ github.ref_name != 'master' }} \
# ":create-tags?" ${{ github.ref_name == 'master' }}

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ config-override.edn

!.github
bin

.test-repos
95 changes: 95 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
(ns build
(:require
[clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as deps-deploy]
[k16.kmono.build :as kmono.build]
[k16.kmono.core.config :as core.config]
[k16.kmono.core.fs :as core.fs]
[k16.kmono.core.graph :as core.graph]
[k16.kmono.core.packages :as core.packages]
[k16.kmono.git.commit :as git.commit]
[k16.kmono.git.tags :as git.tags]
[k16.kmono.version :as kmono.version]
[k16.kmono.version.semantic-commits :as semantic-commits]))

(defn build [{:keys [snapshot release]}]
(b/delete {:path "target"})

(let [project-root (core.fs/find-project-root)
workspace-config (core.config/resolve-workspace-config project-root)

sha (git.commit/get-current-commit-short project-root)

packages
(->> (core.packages/resolve-packages project-root workspace-config)
(core.graph/filter-by #(not (get-in % [:deps-edn :kmono/private])))
(kmono.version/resolve-package-versions project-root)
(kmono.version/resolve-package-changes project-root))

suffix (when snapshot (str sha "-SNAPSHOT"))

versioned-packages
(kmono.version/inc-package-versions
semantic-commits/version-type
suffix
packages)

changed-packages
(->> versioned-packages
(core.graph/filter-by #(seq (:commits %)))
(core.graph/filter-by kmono.build/not-published?))]

(kmono.build/exec
"Building" changed-packages
(fn [pkg]
(let [pkg-name (:fqn pkg)
{:keys [basis paths]}
(kmono.build/create-build-context
versioned-packages pkg)

class-dir (str "target/" (kmono.build/relativize pkg "classes"))
jar-file (str "target/" (kmono.build/relativize pkg "lib.jar"))]

(b/copy-dir {:src-dirs paths
:target-dir class-dir})

(b/write-pom {:class-dir class-dir
:lib pkg-name
:version (:version pkg)
:basis basis})

(b/jar {:class-dir class-dir
:jar-file jar-file})

(when-let [build (get-in pkg [:deps-edn :kmono/build])]
(let [basis (b/create-basis
{:dir (:relative-path pkg)
:aliases (:aliases build)})]
(b/compile-clj
{:basis basis
:compile-opts {:direct-linking true}
:ns-compile [(:main build)]
:class-dir class-dir})

(b/uber
{:class-dir class-dir
:uber-file (str "target/" (kmono.build/relativize pkg (:file build)))
:basis basis
:main (:main build)}))))))

(when release
(kmono.build/exec
"Releasing" changed-packages
(fn [pkg]
(deps-deploy/deploy
{:installer :remote
:artifact (b/resolve-path (str "target/" (kmono.build/relativize pkg "lib.jar")))
:pom-file (b/pom-path {:lib (:fqn pkg)
:class-dir (str "target/" (kmono.build/relativize pkg "classes"))})})))

(git.tags/create-tags
project-root
(map
(fn [pkg]
(str (:fqn pkg) "@" (:version pkg)))
changed-packages)))))
98 changes: 55 additions & 43 deletions build/build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,71 @@
[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/package))

(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")
(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 [opts]
(clean opts)
(b/write-pom {:class-dir class-dir
:lib lib
:version version
:basis (b/create-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 uber-for-native [_]
(defn build [_]
(clean nil)

(let [basis (b/create-basis)]
(b/write-pom
{:class-dir class-dir
:lib lib
:version version
:basis basis
:src-dirs (:paths basis)
: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 (:paths basis)
:target-dir class-dir})

(b/jar {:class-dir class-dir
:jar-file jar-file})))

(defn build-jar [{:keys [main name]}]
(let [basis (b/create-basis {:aliases #{:native}})]
(clean nil)
(b/copy-dir {:src-dirs ["src"]
:target-dir class-dir})
(b/compile-clj {:basis basis
:compile-opts {:direct-linking true}
:ns-compile '[k16.kmono.main]
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file "target/kmono-uber.jar"
:basis basis
:main 'k16.kmono.main})))
(clean nil)

(b/copy-dir
{:src-dirs (:paths basis)
:target-dir class-dir})

(b/compile-clj
{:basis basis
:compile-opts {:direct-linking true}
:ns-compile '[k16.kmono.cli.main]
:class-dir class-dir})

(b/uber
{:class-dir class-dir
:uber-file (str "target/" name)
:basis basis
:main main})))

(defn release [_]
(deps-deploy/deploy {:installer :remote
:artifact (b/resolve-path jar-file)
:pom-file (b/pom-path {:lib lib
:class-dir class-dir})}))
(deps-deploy/deploy
{:installer :remote
:artifact (b/resolve-path jar-file)
:pom-file (b/pom-path {:lib lib
:class-dir class-dir})}))
31 changes: 10 additions & 21 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
{:kmono/package {:group com.kepler16
:artifact kmono
:build-cmd "clojure -T:build build"
:release-cmd "clojure -T:build release"}
:paths ["src" "resources"]
:deps {babashka/process {:mvn/version "0.5.22"}
babashka/fs {:mvn/version "0.5.21"}
org.slf4j/slf4j-api {:mvn/version "1.7.36"}
org.slf4j/slf4j-simple {:mvn/version "1.7.36"}
org.clojure/tools.deps {:mvn/version "0.19.1432"}
metosin/malli {:mvn/version "0.16.1"}
org.flatland/ordered {:mvn/version "1.15.12"}
org.clojure/tools.cli {:mvn/version "1.1.230"}}
{:kmono/workspace {:group com.kepler16}

:aliases {:build {:deps {local/build {:local/root "./build"}}
:ns-default build}
:native {:extra-deps {com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}}}
:test {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}}
:kmono {:deps {com.kepler16/kmono {:local/root "."}}
:main-opts [-m k16.kmono.main]
:ns-default k16.kmono.api}}}
:aliases {:build {:deps {io.github.clojure/tools.build {:mvn/version "0.9.6"}
slipset/deps-deploy {:mvn/version "0.2.2"}

com.keperl16/kmono-core {:local/root "packages/kmono-core"}
com.keperl16/kmono-version {:local/root "packages/kmono-version"}
com.keperl16/kmono-build {:local/root "packages/kmono-build"}
com.keperl16/kmono-git {:local/root "packages/kmono-git"}}
:ns-default build
:extra-paths ["./build.clj"]}}}
Loading

0 comments on commit f6d9218

Please sign in to comment.