feat #1187: Add :result key to (current-task) map that can be used in :leave task hook

This commit is contained in:
Michiel Borkent 2022-02-27 12:10:33 +01:00
parent ba1c66585a
commit 61e47555f9
3 changed files with 18 additions and 3 deletions

View file

@ -4,9 +4,13 @@ For a list of breaking changes, check [here](#breaking-changes).
## Unreleased
### New
- [#1187](https://github.com/babashka/babashka/issues/1187) tasks: Add `:result` key to `(current-task)` map that can be used in `:leave` task hook
### Enhancements
- [#1190](https://github.com/babashka/babashka/issues/1190): task dependencies resolve as core.async channels
- [#1190](https://github.com/babashka/babashka/issues/1190) tasks: task dependencies resolve as core.async channels
## 0.7.6 (2022-02-24)

View file

@ -192,9 +192,11 @@
(if leave
(format "
(let [%s %s]
%s
(binding [babashka.tasks/*task*
(assoc babashka.tasks/*task* :result %s)]
%s)
%s)"
task-name prog (pr-str leave) task-name)
task-name prog task-name (pr-str leave) task-name)
prog)))
(defn wrap-depends [prog depends parallel?]

View file

@ -416,3 +416,12 @@ even more stuff here\"
d {:depends [a b c]
:task (prn [a b c])}}})
(is (= [nil nil nil] (bb "run" "--parallel" "d")))))
(deftest current-task-result-test
(test-utils/with-config
(pr-str '{:tasks {:leave (prn [(:name (current-task)) (:result (current-task))])
a 1
b 2
c {:depends [a b]
:task [a b]}}})
(is (= ["[a 1]" "[b 2]" "[c [1 2]]"] (str/split-lines (test-utils/bb nil "run" "c"))))))