Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: using tools.build to pack jar/deploy #7

Merged
merged 3 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"}}}}