Skip to content

Commit

Permalink
Merge pull request #7 from parenthesin/refact/using-tools-build
Browse files Browse the repository at this point in the history
refact: using tools.build to pack jar/deploy
  • Loading branch information
rafaeldelboni authored Apr 23, 2023
2 parents 59191b2 + 1d3ec96 commit 62a092d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
restore-keys: ${{ runner.os }}-m2

- name: Build Jar
run: clojure -X:build :lib com.github.parenthesin/components :version \"${VERSION}\"
run: clojure -T:build jar :version \"${VERSION}\"

- name: Deploy on clojars
run: clojure -X:deploy :lib com.github.parenthesin/components :version \"${VERSION}\"
run: clojure -T:build deploy :version \"${VERSION}\"
env:
CLOJARS_USERNAME: ${{ vars.CLOJARS_USERNAME }}
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }}
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ clj -M:clojure-lsp diagnostics

```bash
# Build
clj -X:build :lib com.github.parenthesin/components :version '"0.1.0"'
clojure -T:build jar :version '"0.1.0"'
# Deploy
env CLOJARS_USERNAME=username CLOJARS_PASSWORD=clojars-token clj -X:deploy :lib com.github.parenthesin/components :version '"0.1.0"'
env CLOJARS_USERNAME=username CLOJARS_PASSWORD=clojars-token clojure -T:build deploy :version '"0.1.0"'
```

# Features

## System
- [schema](https://github.com/plumatic/schema) Types and Schemas
- [malli](https://github.com/metosin/malli) High-performance Data-Driven Data Specification Library for Clojure/Script.
- [component](https://github.com/stuartsierra/component) System Lifecycle and Dependencies
- [pedestal](https://github.com/pedestal/pedestal) Http Server
- [reitit](https://github.com/metosin/reitit) Http Routes System
Expand All @@ -127,7 +128,8 @@ clj -M:clojure-lsp diagnostics
- [next-jdbc](https://github.com/seancorfield/next-jdbc) JDBC-based layer to access databases
- [hikaricp](https://github.com/brettwooldridge/HikariCP) A solid, high-performance, JDBC connection pool at last
- [honeysql](https://github.com/seancorfield/honeysql) SQL as Clojure data structures
- [depstar](https://github.com/seancorfield/depstar) Generates Uberjars for releases
- [tools.build](https://github.com/clojure/tools.build) Clojure builds as Clojure programs
- [deps-deploy](https://github.com/slipset/deps-deploy) A Clojure library to deploy your stuff to clojars

## Tests & Checks
- [kaocha](https://github.com/lambdaisland/kaocha) Test runner
Expand Down
44 changes: 44 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(ns build
(:refer-clojure :exclude [test])
(:require [clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as dd]))

(def default-lib 'com.github.parenthesin/components)
(def default-version "0.0.1-SNAPSHOT")
(def class-dir "target/classes")

(defn- jar-opts
[{:keys [lib version jar-file] :as opts}]
(let [actual-lib (or lib default-lib)
actual-version (or version default-version)
actual-jar-file (or jar-file (format "target/%s-%s.jar"
actual-lib
actual-version))]
(assoc opts
:lib actual-lib
:version actual-version
:jar-file actual-jar-file
:scm {:tag (str "v" actual-version)}
:basis (b/create-basis {})
:class-dir class-dir
:target "target"
:src-dirs ["src"])))

(defn jar "Build Jar." [opts]
(b/delete {:path "target"})
(let [{:keys [jar-file lib version] :as opts} (jar-opts opts)]
(println "\nWriting pom.xml for" lib "on version" version)
(b/write-pom opts)
(println "\nCopying source from" class-dir)
(b/copy-dir {:src-dirs ["resources" "src"] :target-dir class-dir})
(println "\nBuilding JAR on" jar-file)
(b/jar opts))
opts)

(defn deploy "Deploy the Jar to Clojars." [opts]
(let [{:keys [jar-file version] :as opts} (jar-opts opts)
artifact (b/resolve-path jar-file)
pom-file (b/pom-path (select-keys opts [:lib :class-dir]))]
(println "\nDeploying JAR" artifact "for pom" pom-file "on version" version)
(dd/deploy {:installer :remote :artifact artifact :pom-file pom-file}))
opts)
16 changes: 4 additions & 12 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@
:nrepl {:extra-deps {cider/cider-nrepl {:mvn/version "0.30.0"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

:build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.9.2"
:git/sha "9c9f078"
:deps/root "slim"}}
:exec-fn org.corfield.build/jar
:exec-args {:jar-file "target/components.jar"}}

:deploy {:deps {slipset/deps-deploy {:mvn/version "0.2.1"}
io.github.seancorfield/build-clj {:git/tag "v0.9.2"
:git/sha "9c9f078"
:deps/root "slim"}}
:exec-fn org.corfield.build/deploy
:exec-args {:jar-file "target/components.jar"}}}}
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.9.4" :git/sha "76b78fe"}
slipset/deps-deploy {:mvn/version "0.2.1"}}
:ns-default build
:exec-args {:jar-file "target/components.jar"}}}}

0 comments on commit 62a092d

Please sign in to comment.