forked from tonsky/datascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.clj
executable file
·124 lines (105 loc) · 4.21 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
#^:shebang '[
exec java -cp "$HOME/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar" clojure.main "$0" "$@"
]
(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" (when-not (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)]
(update-file "CHANGELOG.md" #(str/replace % "# WIP" (str "# " new-v)))
(update-file "project.clj" #(str/replace % old-v new-v))
(update-file "README.md" #(str/replace % old-v new-v))
(update-file "release-js/package.json" #(str/replace %
(str "\"version\": \"" old-v "\"")
(str "\"version\": \"" new-v "\"")))
(update-file "release-js/wrapper.prefix" #(str/replace %
(str "Datascript v" old-v)
(str "Datascript v" new-v)))))
(defn run-tests []
(println "\n\n[ Running tests ]\n")
(sh "lein" "test-clj-all")
(sh "lein" "cljsbuild" "once" "advanced" "release")
(sh "node" "test_node.js" "--all"))
(defn make-commit []
(println "\n\n[ Making a commit ]\n")
(sh "git" "add"
"CHANGELOG.md"
"project.clj"
"README.md"
"release-js/package.json"
"release-js/wrapper.prefix")
(sh "git" "commit" "-m" (str "Version " new-v))
(sh "git" "tag" new-v)
(sh "git" "push" "origin" "master"))
(defn publish-npm []
(println "\n\n[ Publishing to npm ]\n")
(sh/with-sh-dir "release-js" (sh "npm" "publish")))
(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 []
(sh "cp" "release-js/datascript.js" (str "release-js/datascript-" new-v ".min.js"))
(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}
response (sh "curl" "-u" GITHUB_AUTH
"-X" "POST"
"--data" (map->json request)
"https://api.github.com/repos/tonsky/datascript/releases")
[_ id] (re-find #"\"id\": (\d+)" response)]
(sh "curl" "-u" GITHUB_AUTH
"-X" "POST"
"-H" "Content-Type: application/javascript"
"--data-binary" (str "@release-js/datascript-" new-v ".min.js")
(str "https://uploads.github.com/repos/tonsky/datascript/releases/" id "/assets?name=datascript-" new-v ".min.js"))))
(defn -main []
(sh "lein" "clean")
(update-version)
(run-tests)
(make-commit)
(publish-npm)
(github-release)
(binding [*env* {"DATASCRIPT_CLASSIFIER" "-aot1.9"}]
(sh "lein" "with-profile" "+aot" "deploy" "clojars"))
(sh "lein" "deploy" "clojars"))
(-main)