forked from juji-io/datalevin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.clj
executable file
·134 lines (112 loc) · 3.83 KB
/
release.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env clojure
"USAGE: ./release.clj <new-version>"
(def new-v (first *command-line-args*))
(assert (re-matches #"\d+\.\d+\.\d+" (or new-v "")) "Use ./release.clj <new-version>")
(println "Releasing version" new-v)
(require '[clojure.string :as str])
(require '[clojure.java.shell :as sh])
(require '[clojure.java.io :as io])
(defn update-file [f fn]
(print "Updating" (str f "...")) (flush)
(spit f (fn (slurp f)))
(println "OK"))
(defn current-version []
(second (re-find #"def version \"([0-9\.]+)\"" (slurp "project.clj"))))
(def ^:dynamic *env* {})
(defn sh [& args]
(apply println "Running" (if (empty? *env*) "" (str :env " " *env*)) args)
(let [res (apply sh/sh (concat args [:env (merge (into {} (System/getenv)) *env*)]))]
(if (== 0 (:exit res))
(do
(println (:out res))
(:out res))
(binding [*out* *err*]
(println "Process" args "exited with code" (:exit res))
(println (:out res))
(println (:err res))
(throw (ex-info (str "Process" args "exited with code" (:exit res)) res))))))
(defn update-version []
(println "\n\n[ Updating version number ]\n")
(let [old-v (current-version)
old->new #(str/replace % old-v new-v)]
(update-file "CHANGELOG.md" #(str/replace % "# WIP" (str "# " new-v)))
(update-file "project.clj" old->new)
(update-file "test-jar/deps.edn" old->new)
(update-file "test-jar/test-uber.sh" old->new)
(update-file "test-jar/project.clj" old->new)
(update-file "doc/dtlv.md" old->new)
(update-file "src/datalevin/main.clj" old->new)
(update-file "native/project.clj" old->new)
(update-file "native/test-jar/deps.edn" old->new)
(update-file "native/README.md" old->new)
(update-file "README.md" old->new)))
(defn run-tests []
(println "\n\n[ Running tests ]\n")
(sh "./lein-test")
(println "\n\n[ Testing jar ]\n")
(sh "./jar")
(sh "test-jar/test.sh")
(println "\n\n[ Testing uberjar ]\n")
(sh "./uberjar")
(sh "test-jar/test-uber.sh")
(println "\n\n[ Testing native jar ]\n")
(sh "script/jar" :dir "native")
(sh "./test.sh" :dir "native/test-jar")
(println "\n\n[ Testing native jar ]\n")
(sh "script/compile" :dir "native")
(sh "./dtlv-test" :dir "native"))
(defn make-commit []
(println "\n\n[ Making a commit ]\n")
(sh "git" "add"
"CHANGELOG.md"
"project.clj"
"test-jar/deps.edn"
"test-jar/test-uber.sh"
"test-jar/project.clj"
"doc/dtlv.md"
"src/datalevin/main.clj"
"native/project.clj"
"native/test-jar/deps.edn"
"native/README.md"
"README.md")
(sh "git" "commit" "-m" (str "Version " new-v))
(sh "git" "tag" new-v)
(sh "git" "push" "origin" "master"))
(defn- str->json [s]
(-> s
(str/replace "\\" "\\\\")
(str/replace "\"" "\\\"")
(str/replace "\n" "\\n")))
(defn- map->json [m]
(str "{ "
(->>
(map (fn [[k v]] (str "\"" (str->json k) "\": \"" (str->json v) "\"")) m)
(str/join ",\n"))
" }"))
(def GITHUB_AUTH (System/getenv "GITHUB_AUTH"))
(defn github-release []
(let [changelog (->> (slurp "CHANGELOG.md")
str/split-lines
(drop-while #(not= (str "# " new-v) %))
next
(take-while #(not (re-matches #"# .+" %)))
(remove str/blank?)
(str/join "\n"))
request { "tag_name" new-v
"name" new-v
"target_commitish" "master"
"body" changelog}]
(sh "curl" "-u" GITHUB_AUTH
"-X" "POST"
"--data" (map->json request)
"https://api.github.com/repos/juji-io/datalevin/releases")))
(defn -main []
(run-tests)
(update-version)
(make-commit)
(github-release)
(sh "./deploy")
(sh "script/deploy" :dir "native")
(System/exit 0)
)
(-main)