Skip to content

Commit

Permalink
Add spec validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinqian00 committed Jan 17, 2024
1 parent a8d1e0a commit 646c9e6
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions src/main/com/yetanalytics/clojars_build.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
(ns com.yetanalytics.clojars-build
(:require [clojure.tools.build.api :as b]
(:require [clojure.spec.alpha :as s]
[clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as dd]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Defaults
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(def default-group-id "com.yetanalytics")

(def default-src-dirs ["src/main"])
Expand All @@ -12,6 +17,10 @@

(def default-license-url "https://www.apache.org/licenses/LICENSE-2.0.txt")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helpers + Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn- basis []
(b/create-basis {}))

Expand All @@ -32,6 +41,52 @@
(defn- github-dev-conn [github-repo]
(format "scm:git:ssh://[email protected]/%s.git" github-repo))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Specs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Keep specs super-simple since this will mainly be used with GitHub Actions
;; and other dev stuff.

(defn- non-empty-string? [s]
(boolean (and (string? s)
(not-empty s))))

(s/def ::group-id non-empty-string?)
(s/def ::artifact-id non-empty-string?)
(s/def ::version non-empty-string?)
(s/def ::src-dirs (s/coll-of non-empty-string? :min-count 1))
(s/def ::resource-dirs (s/coll-of non-empty-string?))
(s/def ::license-name non-empty-string?)
(s/def ::license-url non-empty-string?)
(s/def ::github-repo non-empty-string?)
(s/def ::github-sha non-empty-string?)

(s/def ::jar-input
(s/keys :req-un [::artifact-id
::version
::github-repo
::github-sha]
:opt-un [::group-id
::src-dirs
::resource-dirs
::license-name
::license-url]))

(s/def ::deploy-input
(s/keys :req-un [::artifact-id
::version]
:opt-un [::group-id]))

(defn- assert-opts [spec opts]
(when-some [err (s/explain-data spec opts)]
(throw (ex-info (str "Inputs do not conform to spec: " spec)
err))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Public Functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn jar
"Create the JAR file that will be deployed onto Clojars.
Expand Down Expand Up @@ -59,7 +114,9 @@
src-dirs default-src-dirs
resource-dirs default-resource-dirs
license-name default-license-name
license-url default-license-url}}]
license-url default-license-url}
:as opts}]
(assert-opts ::jar-input opts)
(let [all-dirs (vec (concat src-dirs resource-dirs))
lib-name (library-name group-id artifact-id)
lib-sym (symbol lib-name)
Expand Down Expand Up @@ -104,14 +161,17 @@
[{:keys [group-id
artifact-id
version]
:or {group-id default-group-id}}]
:or {group-id default-group-id}
:as opts}]
(assert-opts ::deploy-input opts)
(let [lib-name (library-name group-id artifact-id)
lib-sym (symbol lib-name)
jar-name (jar-file-name artifact-id version)]
(dd/deploy {:installer :remote
:artifact (b/resolve-path jar-name)
:pom-file (b/pom-path {:lib lib-sym
:class-dir class-dir})})))
:class-dir class-dir})})
nil))

(comment
;; These comments both demonstrate the usage of `jar` and `deploy`,
Expand Down

0 comments on commit 646c9e6

Please sign in to comment.