forked from candid82/joker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.joke
89 lines (78 loc) · 2.83 KB
/
release.joke
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
(alias 's 'joker.string)
(alias 'os 'joker.os)
(def ^:private version-pattern "version\\s+\"(.*)\"")
(def ^:private shasum-pattern "sha256\\s+\"(.*)\"")
(defn- exit-err
[& args]
(apply println-err args)
(joker.os/exit 1))
(defn- exec
[& args]
(let [res (apply os/sh args)]
(when-not (:success res)
(exit-err (str "'" (s/join " " args) "'") "failed:" (:out res) (:err res)))
(:out res)))
(defn- exec-from
[dir & args]
(let [res (apply os/sh-from dir args)]
(when-not (:success res)
(exit-err (str "'[" dir "] " (s/join " " args) "'") "failed:" (:out res) (:err res)))
(:out res)))
(defn- shasum
[filename]
(let [res (exec "shasum" "-a" "256" filename)]
(first (s/split res #"\s"))))
(defn- update-brew-formula
[version]
(println "Updating brew formula...")
(let [version' (subs version 1)
formula-file (get (os/env) "JOKER_FORMULA_PATH")
formula (slurp formula-file)
[_ current-version] (re-find (re-pattern version-pattern) formula)
linux-sha (shasum "joker-linux-amd64.zip")
mac-sha (shasum "joker-mac-amd64.zip")
shasum-rex (re-pattern shasum-pattern)]
(when-not current-version
(exit-err "Could not find version number"))
(spit formula-file (-> formula
(s/replace current-version version')
(s/replace shasum-rex (str "sha256 \"" mac-sha "\""))
(s/replace-first shasum-rex (str "sha256 \"" linux-sha "\""))))
(let [res (os/sh-from (s/replace formula-file "/joker.rb" "")
"git" "commit" "-a" "-m" (str "joker-" version))]
(when-not (:success res)
(exit-err "git commit failed:" (:out res) (:err res))))))
(defn- update-version
[version]
(println (str "Updating version to " version "..."))
(let [procs (slurp "core/procs.go")
procs-lines (s/split-lines procs)
version-line (first (filter #(re-find #"const VERSION = .*" %) procs-lines))]
(when-not procs
(exit-err "Could not find version line"))
(spit "core/procs.go" (s/replace procs version-line (str "const VERSION = \"" version "\""))))
(exec "git" "commit" "-a" "-m" version)
(exec "git" "tag" version)
(exec "git" "push")
(exec "git" "push" "--tags"))
(defn- build-binaries
[version]
(println "Building binaries...")
(exec "./build-all.sh")
(exec "rm" "-f" "joker.exe")
(exec "rm" "-f" "joker"))
(defn- generate-docs
[]
(exec-from "docs" "../joker" "generate-docs.joke"))
(defn- main
[args]
(let [[_ _ version] args]
(when-not version
(exit-err "No version provided"))
(when-not (re-matches #"v\d\.\d{1,2}\.\d{1,2}" version)
(exit-err "Invalid version provided:" version))
(generate-docs)
(update-version version)
(build-binaries version)
(update-brew-formula version)))
(main (joker.os/args))