-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathrelease.joke
More file actions
144 lines (129 loc) · 5.03 KB
/
Copy pathrelease.joke
File metadata and controls
144 lines (129 loc) · 5.03 KB
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
135
136
137
138
139
140
141
142
143
144
(alias 's 'joker.string)
(alias 'os 'joker.os)
(def ^:private version-pattern "version\\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- ensure-clean-worktree
[context]
(let [status (exec "git" "status" "--porcelain")]
(when (seq status)
(exit-err (str "Git worktree is not clean " context ":") status))))
(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-amd64-sha (shasum "joker-linux-amd64.zip")
linux-arm64-sha (shasum "joker-linux-arm64.zip")
mac-amd64-sha (shasum "joker-mac-amd64.zip")
mac-arm64-sha (shasum "joker-mac-arm64.zip")]
(when-not current-version
(exit-err "Could not find version number"))
(println "SHA256 checksums:")
(println " linux-amd64:" linux-amd64-sha)
(println " linux-arm64:" linux-arm64-sha)
(println " mac-arm64: " mac-arm64-sha)
(println " mac-amd64: " mac-amd64-sha)
(spit formula-file (-> formula
(s/replace current-version version')
(s/replace #"sha256 \".*\" # linux-amd64" (str "sha256 \"" linux-amd64-sha "\" # linux-amd64"))
(s/replace #"sha256 \".*\" # linux-arm64" (str "sha256 \"" linux-arm64-sha "\" # linux-arm64"))
(s/replace #"sha256 \".*\" # mac-arm64" (str "sha256 \"" mac-arm64-sha "\" # mac-arm64"))
(s/replace #"sha256 \".*\" # mac-amd64" (str "sha256 \"" mac-amd64-sha "\" # mac-amd64"))))
(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 "\""))))
;; Stage explicitly so newly generated and deleted documentation files are
;; included. `git commit -a` would omit untracked generated files.
(exec "git" "add" "-A" "--" "docs" "core/procs.go")
(exec "git" "commit" "-m" version)
(ensure-clean-worktree "after committing generated docs and the version"))
(defn- publish-version
[version]
;; Do not publish until documentation generation, artifact builds, and the
;; Homebrew formula update have all succeeded.
(ensure-clean-worktree "before tagging")
(println (str "Tagging and pushing " version "..."))
(exec "git" "tag" version)
(exec "git" "push")
(exec "git" "push" "origin" version))
(defn- build-binary
[goarch goos]
(os/set-env "GOOS" goos)
(os/set-env "GOARCH" goarch)
(exec "go" "build")
(os/unset-env "GOARCH")
(os/unset-env "GOOS"))
(defn- zip-binary
[goarch goos]
(let [os (case goos
"darwin" "mac"
"windows" "win"
goos)
zip-filename (str "joker-" os "-" goarch ".zip")
filename (if (= "windows" goos) "joker.exe" "joker")]
(exec "zip" "-9" zip-filename filename)))
(defn- build-binaries
[version]
(println "Building binaries...")
;; Build amd64 binaries for all platforms
(let [goarch "amd64"]
(doseq [goos ["darwin" "linux" "windows" "freebsd" "netbsd" "openbsd"]]
(println "Building" goos goarch)
(build-binary goarch goos)
(zip-binary goarch goos)))
;; Build arm64 binaries
(let [goarch "arm64"]
(doseq [goos ["darwin" "linux"]]
(println "Building" goos goarch)
(build-binary goarch goos)
(zip-binary goarch goos)))
(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))
(ensure-clean-worktree "before starting the release")
(generate-docs)
(update-version version)
(build-binaries version)
(update-brew-formula version)
(publish-version version)))
(main (joker.os/args))