diff --git a/CHANGELOG.md b/CHANGELOG.md index ad5f01cf..416c07b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/babashka/impl/tasks.clj b/src/babashka/impl/tasks.clj index 253314d5..2b376f0d 100644 --- a/src/babashka/impl/tasks.clj +++ b/src/babashka/impl/tasks.clj @@ -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?] diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 3bbfd839..66fda96b 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -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"))))))