-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.clj
executable file
·109 lines (92 loc) · 3.8 KB
/
deploy.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/sh
#_(
#_DEPS is same format as deps.edn. Multiline is okay.
DEPS='
{:deps {org.clojure/clojure {:mvn/version "1.10.1"}
badigeon/badigeon {:git/url "https://github.com/EwenG/badigeon.git"
:sha "e7f62a60d8e890fc84a47bcfdd59137e11ff1c95"
:tag "0.0.7"}}}
'
#_You can put other options here
OPTS='
-J-client
'
exec clojure $OPTS -Sdeps "$DEPS" "$0" "$@"
)
(require
'[clojure.string :as str]
'[clojure.java.shell :as sh]
'[clojure.java.io :as io]
'[badigeon.clean :as clean]
'[badigeon.jar :as jar]
'[badigeon.install :as install]
'[badigeon.sign :as sign]
'[badigeon.deploy :as deploy])
(def GROUP+ARTIFACT 'crinkle/crinkle)
(defn git-describe []
(let [{:keys [exit out err]} (sh/sh "git" "--no-replace-objects"
"describe" "--match=v*.*"
"--abbrev=40" "--long" "--dirty")]
(if (zero? exit)
(str/trimr out)
(throw (ex-info "No annotated tag found with pattern \"v*.*\""
{:exit-code exit
:stderr err})))))
(def re-git-describe
#"(v([0-9]+)\.([0-9]+))-([0-9]+)-g([0-9a-f]+)(?:-(dirty))?")
(defn parsed-version [long-git-describe-str]
(let [[_ tag major minor revision sha dirty?]
(re-matches re-git-describe long-git-describe-str)
major (Long/parseLong major)
minor (Long/parseLong minor)
revision (Long/parseLong revision)]
(cond-> {:base-tag tag
:major major
:minor minor
:revision revision
:sha sha
:dirty? (boolean dirty?)}
(and (not dirty?) (zero? revision))
(assoc :tag tag))))
(defn mvn-version [{:keys [major minor revision]}]
(str major \. minor \. revision))
(defn do-deploy [ops]
(let [ops (set ops)
ver (parsed-version (git-describe))
mver (mvn-version ver)
jarbasename (str (name GROUP+ARTIFACT) \- mver ".jar")
jarfile (str "target/" jarbasename)]
(clean/clean "target")
(io/copy (io/file "base-pom.xml") (io/file "pom.xml"))
(jar/jar GROUP+ARTIFACT {:mvn/version mver}
{;; The jar file produced.
:out-path jarfile
:mvn/repos {"clojars" {:name "Clojars Repository"
:url "https://clojars.org/repo"}}})
(when (contains? ops "install")
(install/install GROUP+ARTIFACT {:mvn/version mver}
;; The jar file to be installed
jarfile
;; The pom.xml file to be installed. This file is generated when creating the jar with the badigeon.jar/jar function.
"pom.xml"
{;; The local repository where the jar should be installed.
:local-repo (str (System/getProperty "user.home") "/.m2/repository")}))
;; Deploy the previously created jar file to a remote repository.
(when (contains? ops "deploy")
(let [;; Artifacts are maps with a required :file-path key and an optional :extension key
artifacts [{:file-path jarfile :extension "jar"}
{:file-path "pom.xml" :extension "pom"}]
;; Artifacts must be signed when deploying non-snapshot versions of artifacts.
artifacts (badigeon.sign/sign artifacts {:command "gpg"
:gpg-key "9F681F44CFF78B35"})]
(badigeon.deploy/deploy GROUP+ARTIFACT mver
artifacts
{;; :id is used to match the repository in the ~/.m2/settings.xml for credentials when no credentials are explicitly provided.
:id "clojars"
;; The URL of the repository to deploy to.
:url "https://clojars.org/repo"})))
))
(try
(do-deploy *command-line-args*)
(finally
(shutdown-agents)))