Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI fingerprint debugging #89

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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