Skip to content

Commit 3dfb15b

Browse files
committed
internal dev: scripts updated to use new shell fn
Migrated from babashka process to bb tasks shell. This allowed me to support continueing on non-zero exits (via {:continue true}) and custom error reporting (via {:error-fn}) more gracefully. Other observations: - opts are specified first, I like this for especially long arg lists, the opts could otherwise be less obvious at-a-glance. - shell args are no longer wrapped in a vector and the the first arg will have shell args automatically parsed out. So we can (shell "ls -l") or (shell "ls" "-l"). When a vector is more convenient we call always (apply shell ["ls" "-l"]). - one could argue that the new shell fn can be easier to use but also more complicated because it supports doing 1 thing in different ways. Overall, I like the change, but as with everything there are pros and cons.
1 parent 98545da commit 3dfb15b

25 files changed

+209
-209
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ For a list of breaking changes see link:#v1-breaking[breaking changes].
1616

1717
=== Unreleased
1818

19+
* Internal rewrite-clj developer facing changes only
20+
1921
=== v1.0.644-alpha
2022

2123
* user guide and docstrings better explain `sexpr-able?` and what invalid code elements rewrite-clj parses https://github.com/clj-commons/rewrite-clj/issues/150[#150] https://github.com/clj-commons/rewrite-clj/issues/151[#151]

script/apply_import_vars.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Options:
1818
(when-let [opts (main/doc-arg-opt args-usage args)]
1919
(let [cmd (if (get opts "check") "check" "gen-code")]
2020
(status/line :head (str "Running apply import vars " cmd))
21-
(shell/command ["clojure" "-X:apply-import-vars:script" cmd])))
21+
(shell/command "clojure -X:apply-import-vars:script" cmd)))
2222
nil)
2323

2424
(main/when-invoked-as-script

script/ci_release.clj

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
(fs/delete-file-recursively dir true)))
1919

2020
(defn- last-release-tag []
21-
(-> (shell/command ["git" "describe" "--abbrev=0" "--match" "v[0-9]*"] {:out :string})
21+
(-> (shell/command {:out :string}
22+
"git describe --abbrev=0 --match v[0-9]*")
2223
:out
2324
string/trim))
2425

@@ -107,9 +108,9 @@
107108
(defn- create-jar! [version]
108109
(status/line :head (str "Creating jar for version " version))
109110
(status/line :detail "Reflecting deps in deps.edn to pom.xml")
110-
(shell/command ["clojure" "-Spom"])
111+
(shell/command "clojure -Spom")
111112
(status/line :detail "Updating pom.xml version and creating thin jar")
112-
(shell/command ["clojure" "-X:jar" ":version" (pr-str version)])
113+
(shell/command "clojure -X:jar :version" (pr-str version))
113114
nil)
114115

115116
(defn- assert-on-ci
@@ -123,32 +124,33 @@
123124
[]
124125
(status/line :head "Deploying jar to clojars")
125126
(assert-on-ci "deploy a jar")
126-
(shell/command ["clojure" "-X:deploy:remote"])
127+
(shell/command "clojure -X:deploy:remote")
127128
nil)
128129

129130
(defn- commit-changes! [version]
130131
(let [tag-version (str "v" version)]
131132
(status/line :head (str "Committing and pushing changes made for " tag-version))
132133
(assert-on-ci "commit changes")
133134
(status/line :detail "Adding changes")
134-
(shell/command ["git" "add" "doc/01-user-guide.adoc" "CHANGELOG.adoc" "pom.xml"])
135+
(shell/command "git add doc/01-user-guide.adoc CHANGELOG.adoc pom.xml")
135136
(status/line :detail "Committing")
136-
(shell/command ["git" "commit" "-m" (str "Release job: updates for version " tag-version)])
137+
(shell/command "git commit -m" (str "Release job: updates for version " tag-version))
137138
(status/line :detail "Version tagging")
138-
(shell/command ["git" "tag" "-a" tag-version "-m" (str "Release " tag-version)])
139+
(shell/command "git" "tag" "-a" tag-version "-m" (str "Release " tag-version))
139140
(status/line :detail "Pushing commit")
140-
(shell/command ["git" "push"])
141+
(shell/command "git push")
141142
(status/line :detail "Pushing version tag")
142-
(shell/command ["git" "push" "origin" tag-version])
143+
(shell/command "git push origin" tag-version)
143144
nil))
144145

145146
(defn- inform-cljdoc! [version]
146147
(status/line :head (str "Informing cljdoc of new version " version))
147148
(assert-on-ci "inform cljdoc")
148-
(let [exit-code (-> (shell/command-no-exit ["curl" "-X" "POST"
149-
"-d" "project=rewrite-clj/rewrite-clj"
150-
"-d" (str "version=" version)
151-
"https://cljdoc.org/api/request-build2"])
149+
(let [exit-code (-> (shell/command {:continue true}
150+
"curl" "-X" "POST"
151+
"-d" "project=rewrite-clj/rewrite-clj"
152+
"-d" (str "version=" version)
153+
"https://cljdoc.org/api/request-build2")
152154
:exit)]
153155
(when (not (zero? exit-code))
154156
(status/line :warn (str "Informing cljdoc did not seem to work, exited with " exit-code)))))
@@ -210,3 +212,4 @@ Options
210212

211213
(main/when-invoked-as-script
212214
(apply -main *command-line-args*))
215+

script/ci_unit_tests.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@
1212
(fs/delete-file-recursively dir true)))
1313

1414
(defn lint []
15-
(shell/command ["bb" "lint"]))
15+
(shell/command "bb lint"))
1616

1717
(defn check-import-vars []
18-
(shell/command ["bb" "apply-import-vars" "check"]))
18+
(shell/command "bb apply-import-vars check"))
1919

2020
(defn doc-tests[]
21-
(shell/command ["bb" "test-doc"]))
21+
(shell/command "bb test-doc"))
2222

2323
(defn clojure-tests []
2424
(doseq [version ["1.9" "1.10"]]
25-
(shell/command ["bb" "test-clj" "--clojure-version" version])) )
25+
(shell/command "bb test-clj --clojure-version" version)) )
2626

2727
(defn cljs-tests []
2828
(doseq [env ["node" "chrome-headless"]
2929
opt ["none" "advanced"]]
30-
(shell/command ["bb" "test-cljs" "--env" env "--optimizations" opt])))
30+
(shell/command "bb" "test-cljs" "--env" env "--optimizations" opt)))
3131

3232
(defn shadow-cljs-tests []
33-
(shell/command ["bb" "test-shadow-cljs"]))
33+
(shell/command "bb test-shadow-cljs"))
3434

3535
(defn cljs-bootstrap-tests []
3636
(if (some #{(env/get-os)} '(:mac :unix))
37-
(shell/command ["bb" "test-cljs" "--env" "planck" "--optimizations" "none"])
37+
(shell/command "bb test-cljs --env planck --optimizations none")
3838
(status/line :warn "skipping planck tests, they can only be run on linux and macOS")) )
3939

4040
(defn -main [& args]

script/cljdoc_preview.clj

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252

5353
(defn local-install []
5454
(status/line :head "building thin jar")
55-
(shell/command ["clojure" "-X:jar"])
55+
(shell/command "clojure -X:jar")
5656
(status/line :head "installing project to local maven repo")
57-
(shell/command ["clojure" "-X:deploy:local"]))
57+
(shell/command "clojure -X:deploy:local"))
5858

5959
(defn get-project []
6060
(str (get-from-pom :project :groupId) "/" (get-from-pom :project :artifactId) ))
@@ -67,8 +67,8 @@
6767
;;
6868

6969
(defn git-sha []
70-
(-> (shell/command ["git" "rev-parse" "HEAD"]
71-
{:out :string})
70+
(-> (shell/command {:out :string}
71+
"git rev-parse HEAD")
7272
:out
7373
string/trim))
7474

@@ -89,22 +89,22 @@
8989
(string/replace #"^(ssh///)*git@" "https://"))))
9090

9191
(defn git-origin-url-as-https []
92-
(-> (shell/command ["git" "config" "--get" "remote.origin.url"]
93-
{:out :string})
92+
(-> (shell/command {:out :string}
93+
"git config --get remote.origin.url")
9494
:out
9595
string/trim
9696
https-uri))
9797

9898
(defn uncommitted-code? []
99-
(-> (shell/command ["git" "status" "--porcelain"]
100-
{:out :string})
99+
(-> (shell/command {:out :string}
100+
"git status --porcelain")
101101
:out
102102
string/trim
103103
seq))
104104

105105
(defn unpushed-commits? []
106-
(let [{:keys [:exit :out]} (shell/command-no-exit ["git" "cherry" "-v"]
107-
{:out :string})]
106+
(let [{:keys [:exit :out]} (shell/command {:continue true :out :string}
107+
"git cherry -v")]
108108
(if (zero? exit)
109109
(-> out string/trim seq)
110110
(status/die 1 "Failed to check for unpushed commits to branch, is your branch pushed?"))))
@@ -114,21 +114,21 @@
114114
;;
115115

116116
(defn status-server [ container ]
117-
(let [container-id (-> ["docker" "ps" "-q" "-f" (str "name=" (:name container))]
118-
(shell/command {:out :string})
117+
(let [container-id (-> (shell/command {:out :string}
118+
"docker ps -q -f" (str "name=" (:name container)))
119119
:out
120120
string/trim)]
121121
(if (string/blank? container-id) "down" "up")))
122122

123123
(defn docker-pull-latest [ container ]
124-
(shell/command ["docker" "pull" (:image container)]))
124+
(shell/command "docker pull" (:image container)))
125125

126126
(defn stop-server [ container ]
127127
(when (= "down" (status-server container))
128128
(status/die 1
129129
"%s does not appear to be running"
130130
(:name container)))
131-
(shell/command ["docker" "stop" (:name container) "--time" "0"]))
131+
(shell/command "docker" "stop" (:name container) "--time" "0"))
132132

133133
(defn wait-for-server
134134
"Wait for container's http server to become available, assumes server has valid root page"
@@ -158,21 +158,21 @@
158158

159159
(defn cljdoc-ingest [container project version]
160160
(status/line :head "Ingesting project %s %s\ninto local cljdoc database" project version)
161-
(shell/command ["docker"
162-
"run" "--rm"
163-
"-v" (str cljdoc-db-dir ":/app/data")
164-
"-v" (str (home-dir) "/.m2:/root/.m2")
165-
"-v" (str (cwd) ":" (cwd) ":ro")
166-
"--entrypoint" "clojure"
167-
(:image container)
168-
"-A:cli"
169-
"ingest"
161+
(shell/command "docker"
162+
"run" "--rm"
163+
"-v" (str cljdoc-db-dir ":/app/data")
164+
"-v" (str (home-dir) "/.m2:/root/.m2")
165+
"-v" (str (cwd) ":" (cwd) ":ro")
166+
"--entrypoint" "clojure"
167+
(:image container)
168+
"-A:cli"
169+
"ingest"
170170
;; project and version are used to locate the maven artifact (presumably locally)
171-
"--project" project "--version" version
171+
"--project" project "--version" version
172172
;; use git origin to support folks working from forks/PRs
173-
"--git" (git-origin-url-as-https)
173+
"--git" (git-origin-url-as-https)
174174
;; specify revision to allow for previewing when working from branch
175-
"--rev" (git-sha)]))
175+
"--rev" (git-sha)))
176176

177177
(defn start-cljdoc-server [container]
178178
(when (= "up" (status-server container))
@@ -182,15 +182,15 @@
182182
(status/line :head "Checking for updates")
183183
(docker-pull-latest container)
184184
(status/line :head "Starting %s on port %d" (:name container) (:port container))
185-
(shell/command ["docker"
186-
"run" "--rm"
187-
"--name" (:name container)
188-
"-d"
189-
"-p" (str (:port container) ":8000")
190-
"-v" (str cljdoc-db-dir ":/app/data")
191-
"-v" (str (home-dir) "/.m2:/root/.m2")
192-
"-v" (str (cwd) ":" (cwd) ":ro")
193-
(:image container)]))
185+
(shell/command "docker"
186+
"run" "--rm"
187+
"--name" (:name container)
188+
"-d"
189+
"-p" (str (:port container) ":8000")
190+
"-v" (str cljdoc-db-dir ":/app/data")
191+
"-v" (str (home-dir) "/.m2:/root/.m2")
192+
"-v" (str (cwd) ":" (cwd) ":ro")
193+
(:image container)))
194194

195195
(defn view-in-browser [url]
196196
(status/line :head "opening %s in browser" url)

script/doc_api_diffs.clj

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
(defn install-locally []
1212
(status/line :head "installing rewrite-clj v1 locally from dev")
13-
(shell/command ["mvn" "install"]))
13+
(shell/command "mvn install"))
1414

1515
(defn wipe-rewrite-clj-diff-cache [ {:keys [coords version]}]
1616
(let [cache-dir (io/file "./.diff-apis/.cache")
@@ -38,14 +38,16 @@
3838

3939
(defn diff-apis [{:keys [:notes-dir :report-dir]} projecta projectb report-name extra-args]
4040
(status/line :head "Diffing %s and %s" (describe-proj projecta) (describe-proj projectb))
41-
(shell/command (concat ["clojure" "-M:diff-apis"]
42-
(map projecta [:coords :version :lang])
43-
(map projectb [:coords :version :lang])
44-
["--arglists-by" ":arity-only"
45-
"--notes" (str (io/file notes-dir (str report-name ".adoc")))
46-
"--report-format" ":asciidoc"
47-
"--report-filename" (str (io/file report-dir (str report-name ".adoc")))]
48-
extra-args)))
41+
(apply shell/command
42+
(concat
43+
["clojure" "-M:diff-apis"]
44+
(map projecta [:coords :version :lang])
45+
(map projectb [:coords :version :lang])
46+
["--arglists-by" ":arity-only"
47+
"--notes" (str (io/file notes-dir (str report-name ".adoc")))
48+
"--report-format" ":asciidoc"
49+
"--report-filename" (str (io/file report-dir (str report-name ".adoc")))]
50+
extra-args)))
4951

5052
(defn -main [& args]
5153
(when (main/doc-arg-opt args)

script/doc_update_readme.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
(try
131131
(let [chrome (chrome)]
132132
{:exe chrome
133-
:version (-> (shell/command [chrome "--version"] {:out :string})
133+
:version (-> (shell/command {:out :string} chrome "--version")
134134
:out
135135
string/trim)})
136136
(catch Exception _e)))
@@ -139,14 +139,14 @@
139139
(let [html-file (str target-dir "/temp.html")]
140140
(try
141141
(spit html-file (generate-contributor-html github-id contributions))
142-
(shell/command [(chrome)
143-
"--headless"
144-
(str "--screenshot=" target-dir "/" github-id ".png")
145-
(str "--window-size=" (:image-width image-opts) ",125")
146-
"--default-background-color=0"
147-
"--hide-scrollbars"
148-
html-file]
149-
{:out :string :err :string})
142+
(shell/command {:out :string :err :string}
143+
(chrome)
144+
"--headless"
145+
(str "--screenshot=" target-dir "/" github-id ".png")
146+
(str "--window-size=" (:image-width image-opts) ",125")
147+
"--default-background-color=0"
148+
"--hide-scrollbars"
149+
html-file)
150150
(finally
151151
(fs/delete-file-recursively (io/file html-file) true)))))
152152

script/helper/env.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
[]
2020
(let [min-version "1.10.1.697"
2121
version
22-
(->> (shell/command ["clojure" "-Sdescribe"] {:out :string})
22+
(->> (shell/command {:out :string} "clojure -Sdescribe")
2323
:out
2424
edn/read-string
2525
:version)]

script/helper/graal.clj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
(defn- assert-min-native-image-version [native-image-exe]
2121
(let [min-major 21
22-
version-out (->> (shell/command [native-image-exe "--version"] {:out :string})
22+
version-out (->> (shell/command {:out :string} native-image-exe "--version")
2323
:out)
2424
actual-major (->> version-out
2525
(re-find #"(?i)GraalVM (Version )?(\d+)\.")
@@ -34,7 +34,7 @@
3434
(status/line :head "Locate GraalVM native-image")
3535
(if-let [gu (find-gu-prog)]
3636
;; its ok (and simpler and safer) to request an install of native-image when it is already installed
37-
(do (shell/command [gu "install" "native-image"])
37+
(do (shell/command gu "install" "native-image")
3838
(let [native-image (or (find-native-image-prog)
3939
(status/die 1 "failed to install GraalVM native-image, check your GraalVM installation"))]
4040
(status/line :detail (str "found: " native-image))
@@ -54,22 +54,22 @@
5454

5555
(defn aot-compile-sources [classpath ns]
5656
(status/line :head "AOT compile sources")
57-
(shell/command ["java"
58-
"-Dclojure.compiler.direct-linking=true"
59-
"-cp" classpath
60-
"clojure.main"
61-
"-e" (str "(compile '" ns ")")]))
57+
(shell/command "java"
58+
"-Dclojure.compiler.direct-linking=true"
59+
"-cp" classpath
60+
"clojure.main"
61+
"-e" (str "(compile '" ns ")")))
6262

6363
(defn compute-classpath [base-alias]
6464
(status/line :head "Compute classpath")
6565
(let [alias-opt (str "-A:" base-alias)
66-
classpath (-> (shell/command ["clojure" alias-opt "-Spath"] {:out :string})
66+
classpath (-> (shell/command {:out :string} "clojure" alias-opt "-Spath")
6767
:out
6868
string/trim)]
6969
(println "\nClasspath:")
7070
(println (str "- " (string/join "\n- " (fs/split-path-list classpath))))
7171
(println "\nDeps tree:")
72-
(shell/command ["clojure" alias-opt "-Stree"])
72+
(shell/command "clojure" alias-opt "-Stree")
7373
classpath))
7474

7575
(defn run-native-image [{:keys [:graal-native-image :graal-reflection-fname
@@ -109,4 +109,4 @@
109109
:unix ["/usr/bin/time" "-v"]
110110
(status/line :warn (str "I don't know how to get run stats (user/real/sys CPU, RAM use, etc) for a command on " os))))]
111111

112-
(shell/command (concat time-cmd native-image-cmd))))
112+
(apply shell/command (concat time-cmd native-image-cmd))))

0 commit comments

Comments
 (0)