-
Notifications
You must be signed in to change notification settings - Fork 6
/
bb.edn
125 lines (102 loc) · 5.08 KB
/
bb.edn
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
{:min-bb-version "0.7.8"
:tasks
{:requires ([clojure.edn :as edn]
[clojure.string :as str]
[babashka.fs :as fs]
[babashka.process :as p])
:init (do
(def major 0)
(def minor 6)
(def rev-count-offset 69) ;; previous repo offset
(def meta-inf-file "resources/META-INF/nextjournal/markdown/meta.edn")
(defn rev-count []
(-> (p/process ["git" "rev-list" "HEAD" "--count"] {:out :string})
p/check :out str/trim Integer/parseInt))
(defn version [] (format "%d.%d.%d" major minor (inc (+ (rev-count) rev-count-offset))))
(defn update-changelog []
(->> (str/replace (slurp "CHANGELOG.md")
(re-pattern "## [Uu]nreleased")
(str "## Unreleased\n\n...\n\n"
(format "## %s" (version))))
(spit "CHANGELOG.md")))
(defn read-version [] (-> (slurp meta-inf-file) edn/read-string :version)))
yarn-install
{:doc "Installs and updates npm dependencies"
:task (shell "yarn install")}
build-esm
{:doc "Builds the ESM JS module file for the markdown module"
:task (shell "./node_modules/.bin/esbuild src/js/markdown.js --bundle --minify --outfile=resources/js/markdown.mjs --format=esm")
:depends [yarn-install]}
test
{:doc "runs tests in the markdown module"
:depends [build-esm]
:task (clojure "-X:test")}
build:notebooks
{:doc "builds a Clerk static with notebooks specified in deps.edn given a specified git SHA"
:task (clojure (str "-X:dev:nextjournal/clerk :git/sha '\"" (or (first *command-line-args*) "SHASHASHA") "\"' :browse? false"))}
dev
{:doc "Boots and watches shadow browser test"
:depends [yarn-install]
:task (clojure "-M:dev:test:nextjournal/clerk:shadow watch browser-test")}
cljs:compile:tests
{:doc "compiles tests as node executable"
:depends [yarn-install]
:task (clojure "-M:dev:test:shadow compile test")}
test:cljs
{:doc "runs cljs tests via node"
:depends [cljs:compile:tests]
:task (shell "yarn node --trace-uncaught out/node-tests.js")}
link-changelog {:doc "Turns the issue references in the changelog into links"
:task (do (defn tag->issue-link [s]
(clojure.string/replace s (re-pattern "(?<!\\[)#([0-9]+)") "[#$1](https://github.com/nextjournal/markdown/issues/$1)"))
(let [f "CHANGELOG.md"]
(spit f (tag->issue-link (slurp f)))))}
update-meta {:doc "Updates meta.edn with current version (based on commit count currently)."
:task (spit (doto (fs/file meta-inf-file)
(-> fs/parent fs/create-dirs)) {:version (version)})}
tag {:doc "Tags release and pushes tag to Github."
:task (let [tag (str "v" (read-version))]
(shell "git tag" tag))}
delete-tag {:doc "Tells git to delete the tag at the current version"
:task (shell (str "git tag -d v" (read-version)))}
current-version {:doc "Prints the version as written to META-INF during publishing"
:task (print (read-version))}
publish {:doc "Prepares repo for publishing via CI"
:task (do
(run 'update-meta)
(println "Preparing repo for Release.\n Updated worktree has been committed (e.g. changes to CHANGELOG)" (read-version))
(run 'link-changelog)
(update-changelog)
(shell "git add -u")
(shell (str "git commit -m v" (read-version)))
(run 'tag)
(println "\n\nRun:\n\n" " git push --atomic"
"origin" "main" (str "v" (read-version))
"\n\nto push the release and let CI build it!"))}
undo:publish {:doc "Reset to state prior to `bb publish`"
:task (do
(run 'delete-tag)
(shell "git reset HEAD~1")
(shell "git co -- resources/META-INF/nextjournal/markdown/meta.edn"))}
-current-tag (->> (shell {:out :string} "git tag --points-at HEAD")
:out
str/trim
not-empty)
-current-branch (->> (shell {:out :string} "git branch --show-current")
:out
str/trim)
jar {:doc "Build jar"
:task (do
(println "Building jar")
(clojure (str "-T:build jar :version '\"" (read-version) "\"'")))}
ci:publish {:doc "Publish task which will be run on CI"
:depends [-current-tag -current-branch]
:task (do
(prn :current-tag -current-tag)
(prn :current-branch -current-branch)
(if (and -current-tag (= "main" -current-branch))
(do
(println "Deploying to clojars")
(clojure (str "-T:build deploy :version '\"" (read-version) "\"'")))
;; still build jar for artifact upload
(run 'jar)))}}}