Skip to content

Commit

Permalink
CI fingerprint debugging (#89)
Browse files Browse the repository at this point in the history
* Add debug option to fingerprint tasks.

* Print detailed debug info about changed projects.
  • Loading branch information
greglook authored Jul 5, 2022
1 parent 0c14268 commit f7d476b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 28 deletions.
83 changes: 59 additions & 24 deletions src/lein_monolith/task/fingerprint.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

;; ## Options

(def selection-opts
(assoc target/selection-opts :upstream 0 :downstream 0))
(def task-opts
(assoc target/selection-opts
:upstream 0
:downstream 0
:debug 0))


;; ## Hashing projects' inputs
Expand Down Expand Up @@ -257,29 +260,21 @@
"Determines if a project has changed since the last fingerprint saved under the
given marker."
[ctx marker project-name]
(let [{:keys [initial]} ctx
current (fingerprints ctx project-name)
past (get-in initial [marker project-name])]
(let [current (fingerprints ctx project-name)
past (get-in ctx [:initial marker project-name])]
(not= (::final past) (::final current))))


(defn- explain-kw
[ctx marker project-name]
(let [{:keys [initial]} ctx
current (fingerprints ctx project-name)
past (get-in initial [marker project-name])]
(cond
(nil? past) ::new-project

(= (::final past) (::final current)) ::up-to-date

:else
(or (some
(fn [ftype]
(when (not= (ftype past) (ftype current))
ftype))
[::version ::seed ::sources ::deps ::upstream])
::unknown))))
(def ^:private fingerprint-priority
"Priority ordered list of fingerprints to check; keys appearing earlier in
the list will take precedence when explaining why a project is considered
changed."
[::version
::seed
::sources
::deps
::java-version
::upstream])


(def ^:private reason-details
Expand All @@ -294,6 +289,26 @@
::unknown ["has a different fingerprint" "have different fingerprints" :red]})


(defn- explain-kw
[ctx marker project-name]
(let [current (fingerprints ctx project-name)
past (get-in ctx [:initial marker project-name])]
(cond
(nil? past)
::new-project

(= (::final past) (::final current))
::up-to-date

:else
(or (some
(fn [ftype]
(when (not= (ftype past) (ftype current))
ftype))
fingerprint-priority)
::unknown))))


(defn explain-str
[ctx marker project-name]
(let [[singular _ color] (reason-details (explain-kw ctx marker project-name))]
Expand Down Expand Up @@ -347,14 +362,34 @@
(colorize :bold marker)
"fingerprints:\n")
(let [reasons (group-by (partial explain-kw ctx marker) targets)]
(doseq [k [::unknown ::new-project ::sources ::resources ::deps ::version ::java-version ::upstream ::up-to-date]]
(doseq [k (concat [::unknown
::new-project]
fingerprint-priority
[::up-to-date])]
(when-let [projs (seq (k reasons))]
(let [[singular plural color] (reason-details k)
c (count projs)]
(lein/info "*" (colorize color (count projs))
(str (if (= 1 c) singular plural)
(when-not (#{::up-to-date ::upstream} k)
(str ": " (list-projects projs color)))))))))
(str ": " (list-projects projs color)))))
(when (and (:debug opts)
(not= k ::new-project)
(not= k ::up-to-date))
(doseq [project-name projs]
(let [past (get-in ctx [:initial marker project-name])
current (fingerprints ctx project-name)
attrs (disj (into (sorted-set) (concat (keys past) (keys current))) ::time)]
(println project-name)
(doseq [attr attrs]
(let [past-val (get past attr)
curr-val (get current attr)]
(if (= past-val curr-val)
(printf "%12s: %s\n" (name attr) curr-val)
(printf "%12s: %s => %s\n" (name attr) past-val curr-val)))))
(newline)
(flush)
,,,))))))
(lein/info)))))


Expand Down
8 changes: 4 additions & 4 deletions src/leiningen/monolith.clj
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@
information.
Usage:
lein monolith changed [project-selectors] [marker1 marker2 ...]"
lein monolith changed [:debug] [project-selectors] [marker1 marker2 ...]"
[project args]
(let [[opts more] (u/parse-kw-args fingerprint/selection-opts args)
(let [[opts more] (u/parse-kw-args fingerprint/task-opts args)
opts (u/globalize-opts project opts)]
(fingerprint/changed project opts more)))

Expand All @@ -245,7 +245,7 @@
Usage:
lein monolith mark [project-selectors] marker1 marker2 ..."
[project args]
(let [[opts more] (u/parse-kw-args fingerprint/selection-opts args)
(let [[opts more] (u/parse-kw-args fingerprint/task-opts args)
opts (u/globalize-opts project opts)]
(fingerprint/mark-fresh project opts more)))

Expand All @@ -259,7 +259,7 @@
Usage:
lein monolith clear [project-selectors] [marker1 marker2 ...]"
[project args]
(let [[opts more] (u/parse-kw-args fingerprint/selection-opts args)
(let [[opts more] (u/parse-kw-args fingerprint/task-opts args)
opts (u/globalize-opts project opts)]
(fingerprint/clear project opts more)))

Expand Down

0 comments on commit f7d476b

Please sign in to comment.