-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.clj
executable file
·113 lines (91 loc) · 3.5 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
#!/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])
(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 "windows-amd64/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 "windows-amd64/project.clj" old->new)
(update-file "ubuntu-latest-amd64/project.clj" old->new)
(update-file "macos-latest-amd64/project.clj" old->new)
(update-file "macos-latest-aarch64/project.clj" old->new)
(update-file "ubuntu-latest-amd64-shared/project.clj" old->new)
(update-file "macos-latest-amd64-shared/project.clj" old->new)
(update-file "macos-latest-aarch64-shared/project.clj" old->new)
(update-file "x86_64-windows-gnu/project.clj" old->new)
(update-file "aarch64-linux-gnu/project.clj" old->new)
))
(defn make-commit []
(println "\n\n[ Making a commit ]\n")
(sh "git" "add"
"CHANGELOG.md"
"windows-amd64/project.clj"
"ubuntu-latest-amd64/project.clj"
"macos-latest-amd64/project.clj"
"macos-latest-aarch64/project.clj"
"x86_64-windows-gnu/project.clj"
"aarch64-linux-gnu/project.clj"
"ubuntu-latest-amd64-shared/project.clj"
"macos-latest-amd64-shared/project.clj"
"macos-latest-aarch64-shared/project.clj")
(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/dtlvnative/releases")))
(defn -main []
(update-version)
(make-commit)
(github-release)
(System/exit 0))
(-main)