generated from wdhowe/clj-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Updated build.clj with a project metadata map. - github workflow uses new jar build fn.
- Loading branch information
Showing
2 changed files
with
71 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,104 @@ | ||
(ns build | ||
"build script. | ||
Test | ||
"Clean: | ||
clj -T:build clean | ||
Test: | ||
clj -T:build test | ||
Test, Write POM, Build | ||
clj -T:build ci | ||
Test, Write POM, Build JAR: | ||
clj -T:build jar | ||
Deploy to Clojars | ||
CLOJARS_USERNAME=username CLOJARS_PASSWORD=clojars-token clj -T:build deploy" | ||
Deploy to Clojars: | ||
CLOJARS_USERNAME=username | ||
CLOJARS_PASSWORD=clojars-token | ||
clj -T:build deploy" | ||
(:refer-clojure :exclude [test]) | ||
(:require [clojure.tools.build.api :as b] | ||
[deps-deploy.deps-deploy :as dd])) | ||
|
||
;; Project Metadata | ||
(def lib 'com.github.wdhowe/clj-contrib) | ||
(def version "1.0.0") | ||
(def project | ||
"Project Metadata" | ||
{:description "A library of functions to enhance clojure.core." | ||
:lib 'com.github.wdhowe/clj-contrib | ||
:version "1.0.0" | ||
:license "Eclipse Public License" | ||
:license-url "http://www.eclipse.org/legal/epl-v20.html" | ||
:author "Bill Howe" | ||
:url "https://github.com/wdhowe/clj-contrib" | ||
:git-repo "wdhowe/clj-contrib" | ||
:class-dir "target/classes"}) | ||
|
||
(defn- pom-template | ||
[version] | ||
(let [git-repo (:git-repo project) | ||
url (:url project)] | ||
[[:description (:description project)] | ||
[:url url] | ||
[:licenses | ||
[:license | ||
[:name (:license project)] | ||
[:url (:license-url project)]]] | ||
[:developers | ||
[:developer | ||
[:name (:author project)]]] | ||
[:scm | ||
[:url url] | ||
[:connection (format "scm:git:%s.git" url)] | ||
[:developerConnection (format "scm:git:ssh:git@github.com:%s.git" git-repo)] | ||
[:tag (str "v" version)]]])) | ||
|
||
(defn- jar-opts | ||
[opts] | ||
(let [version (:version project) | ||
lib (:lib project)] | ||
(assoc opts | ||
:basis (b/create-basis {}) | ||
:class-dir (:class-dir project) | ||
:jar-file (format "target/%s-%s.jar" lib version) | ||
:lib lib | ||
:pom-data (pom-template version) | ||
:src-dirs ["src"] | ||
:target "target" | ||
:version version))) | ||
|
||
(defn- the-version [patch] (format "1.0.%s" patch)) | ||
;(def version (the-version (b/git-count-revs nil))) | ||
(def snapshot (the-version "999-SNAPSHOT")) | ||
(def class-dir "target/classes") | ||
(defn clean | ||
"Remove build directory." | ||
[_] | ||
(b/delete {:path "target"})) | ||
|
||
(defn test | ||
"Run all the tests." | ||
[opts] | ||
(let [basis (b/create-basis {:aliases [:test]}) | ||
cmds (b/java-command | ||
{:basis basis | ||
:main 'clojure.main | ||
:main-args ["-m" "cognitect.test-runner"]}) | ||
{:basis basis | ||
:main 'clojure.main | ||
:main-args ["-m" "cognitect.test-runner"]}) | ||
{:keys [exit]} (b/process cmds)] | ||
(when-not (zero? exit) (throw (ex-info "Tests failed" {})))) | ||
opts) | ||
|
||
(defn- pom-template | ||
[version] | ||
[[:description "A library of functions to enhance clojure.core."] | ||
[:url "https://github.com/wdhowe/clj-contrib"] | ||
[:licenses | ||
[:license | ||
[:name "Eclipse Public License"] | ||
[:url "http://www.eclipse.org/legal/epl-v20.html"]]] | ||
[:developers | ||
[:developer | ||
[:name "Bill Howe"]]] | ||
[:scm | ||
[:url "https://github.com/wdhowe/clj-contrib"] | ||
[:connection "scm:git:https://github.com/wdhowe/clj-contrib.git"] | ||
[:developerConnection "scm:git:ssh:git@github.com:wdhowe/clj-contrib.git"] | ||
[:tag (str "v" version)]]]) | ||
|
||
(defn- jar-opts | ||
[opts] | ||
(let [version (if (:snapshot opts) snapshot version)] | ||
(assoc opts | ||
:lib lib :version version | ||
:jar-file (format "target/%s-%s.jar" lib version) | ||
:basis (b/create-basis {}) | ||
:class-dir class-dir | ||
:target "target" | ||
:src-dirs ["src"] | ||
:pom-data (pom-template version)))) | ||
|
||
(defn ci | ||
(defn jar | ||
"Run the CI pipeline of: tests, write pom, and build the JAR." | ||
[opts] | ||
(test opts) | ||
(b/delete {:path "target"}) | ||
(clean nil) | ||
(let [opts (jar-opts opts)] | ||
(println "\nWriting pom.xml...") | ||
(b/write-pom opts) | ||
(println "\nCopying source...") | ||
(b/copy-dir {:src-dirs ["resources" "src"] :target-dir class-dir}) | ||
(println "\nBuilding" (:jar-file opts) "...") | ||
(b/copy-dir {:src-dirs ["resources" "src"] | ||
:target-dir (:class-dir project)}) | ||
(println "\nBuilding JAR" (:jar-file opts) "...") | ||
(b/jar opts)) | ||
opts) | ||
|
||
(defn deploy | ||
"Deploy the JAR to Clojars." | ||
[opts] | ||
(let [{:keys [jar-file] :as opts} (jar-opts opts)] | ||
(dd/deploy {:installer :remote :artifact (b/resolve-path jar-file) | ||
(let [{:keys [jar-file] :as opts} | ||
(jar-opts opts)] | ||
(dd/deploy {:installer :remote | ||
:artifact (b/resolve-path jar-file) | ||
:pom-file (b/pom-path (select-keys opts [:lib :class-dir]))})) | ||
opts) |