forked from clj-kondo/clj-kondo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump_graal_version.clj
executable file
·95 lines (83 loc) · 2.9 KB
/
bump_graal_version.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
#!/usr/bin/env bb
(ns bump-graal-version
(:require [clojure.string :as str]
[clojure.tools.cli :as cli]))
(defn display-help []
(println (->> [""
"This is a script that should be run when you'd"
"you'd like to bump the GraalVM/java version for bb."
""
"The following options are available:"
"(-g, --graal) - to specify the GraalVM version"
"(-j, --java) - to specify the java version"
""
"Use it by providing one or 2 command line arguments"
"i.e the version you'd want to upgrade it to and/or the java version"
""
"./bump_graal_version.clj -g 19.3.2 (the new version)"
"or"
"./bump_graal_version.clj -g 19.3.2 --java java11"
"(for GraalVM java11-19.3.2)"
""]
(str/join \newline))))
(def files-to-edit
["Dockerfile"
"doc/dev.md"
"doc/build.md"
".circleci/config.yml"
"appveyor.yml"
"project.clj.template"
"project.clj"])
;; We might have to keep changing these from
;; time to time whenever the version is bumped
;;
;; OR
;;
;; We could have them as environment variables
(def current-graal-version "20.2.0")
(def current-java-version "java11")
(def valid-graal-bumps ["19.3.2" "20.1.0" "20.2.0" "20.3.0"])
(def valid-java-bumps ["java8" "java11"])
(def cl-options
[["-g" "--graal VERSION" "graal version"]
["-j" "--java VERSION" "java version"]
["-h" "--help"]])
(def cl-args
(:options (cli/parse-opts *command-line-args* cl-options)))
(defn is-valid-bump?
[version valid-bumps]
(some #(= % version) valid-bumps))
(defn replace-current
[file current new]
(let [file-contents (slurp file)]
(str/replace file-contents current new)))
(defn bump-current
[current new]
(doseq [file files-to-edit]
(let [exec-res (replace-current file current new)]
(try (spit file exec-res)
(catch Exception e (str "There was an error: " (.getMessage e)))
(finally
(println "Done with : " file))))))
(defn show-error
[err-version]
(println "This is not a valid version: " err-version))
(defn exec-script
[args]
(when (empty? args)
(display-help))
(let [new-graal-version (:graal args)
new-java-version (:java args)]
(when (not (nil? new-graal-version))
(if (is-valid-bump? new-graal-version valid-graal-bumps)
(do
(println "Performing Graal bump...")
(bump-current current-graal-version new-graal-version))
(show-error new-graal-version)))
(when (not (nil? new-java-version))
(if (is-valid-bump? new-java-version valid-java-bumps)
(do
(println "Performing Java bump...")
(bump-current current-java-version new-java-version))
(show-error new-java-version)))))
(exec-script cl-args)