Skip to content

Commit

Permalink
Fix bug in the reverted code (#451)
Browse files Browse the repository at this point in the history
issue #431
* 0.2.20-SNAPSHOT #8
* Extract test code from the 'changes' component to the 'test' component. (#449)
* Refactor code from the 'changes' component to the new 'test' component.
* Add more test to catch if the code that calculates which tests to run breaks.
* Update libraries to the latest version.
  • Loading branch information
tengstrand authored Mar 17, 2024
1 parent 68b7739 commit b6e4dd6
Show file tree
Hide file tree
Showing 40 changed files with 496 additions and 293 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/antq/deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:paths ["src"]
:deps {com.github.liquidz/antq {:mvn/version "2.8.1173"}}
:deps {com.github.liquidz/antq {:mvn/version "2.8.1185"}}
:aliases {:test {:extra-paths ["test"]
:extra-deps {}}}}
21 changes: 5 additions & 16 deletions components/change/src/polylith/clj/core/change/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
(:require [clojure.set :as set]
[polylith.clj.core.change.entity :as entity]
[polylith.clj.core.change.indirect-changes :as indirect-changes]
[polylith.clj.core.change.bricks-to-test :as bricks-to-test]
[polylith.clj.core.change.projects-to-test :as projects-to-test]
[polylith.clj.core.common.interface :as common]
[polylith.clj.core.git.interface :as git]
[polylith.clj.core.util.interface :as util]))
Expand All @@ -21,10 +19,6 @@
(vec (sort (map :name (filter #(project-affected? % changed-components changed-bases changed-projects)
projects)))))

(defn nothing-to-test [project]
(assoc project :bricks-to-test []
:projects-to-test []))

(defn with-changes [{:keys [ws-dir ws-local-dir user-input settings projects paths] :as workspace}]
(if (common/invalid-workspace? workspace)
workspace
Expand All @@ -33,24 +27,19 @@
:changed-components []
:changed-bases []
:changed-projects []
:changed-or-affected-projects []}
:projects (mapv nothing-to-test projects))
:changed-or-affected-projects []})
(let [{:keys [since changed-files is-no-changes]
:or {since "stable"}} user-input
tag-patterns (:tag-patterns settings)
{:keys [tag sha]} (git/sha ws-dir since tag-patterns)
files (git/diff ws-dir ws-local-dir is-no-changes changed-files sha nil)]
(let [{:keys [is-dev is-all is-run-all-brick-tests is-run-project-tests selected-bricks selected-projects]} user-input
{:keys [changed-components
(let [{:keys [changed-components
changed-bases
changed-projects]} (entity/changed-entities files paths)
changed-bricks (set (concat changed-components changed-bases))
affected-projects (affected-projects projects changed-components changed-bases changed-projects)
projects-with-keys (mapv #(-> %
(indirect-changes/with-indirect-changes changed-bricks)
(bricks-to-test/with-bricks-to-test changed-projects changed-components changed-bases selected-bricks selected-projects is-dev is-run-all-brick-tests)
(projects-to-test/with-projects-to-test paths affected-projects selected-projects is-dev is-run-project-tests is-all))
projects)
projects-with-changes (mapv #(indirect-changes/with-indirect-changes % changed-bricks)
projects)
changes (util/ordered-map :since since
:since-sha sha
:since-tag tag
Expand All @@ -61,4 +50,4 @@
:changed-projects changed-projects
:changed-or-affected-projects affected-projects)]
(assoc workspace :changes changes
:projects projects-with-keys))))))
:projects projects-with-changes))))))
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@
(deftest changed-projects--when-two-of-three-projects-contain-changed-bricks--return-the-projects-with-then-changed-bricks
(is (= #{"core" "dev"}
(project/indirectly-changed-project-names projects changed-bricks))))

2 changes: 1 addition & 1 deletion components/deps/deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:paths ["src"]
:deps {org.clojure/tools.deps {:mvn/version "0.18.1398"}}
:deps {org.clojure/tools.deps {:mvn/version "0.19.1417"}}
:aliases {:test {:extra-paths ["test"]
:extra-deps {}}}}
4 changes: 2 additions & 2 deletions components/deps/src/polylith/clj/core/deps/interface.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
(defn base-deps [bases base suffixed-top-ns]
(base-deps/base-deps bases base suffixed-top-ns))

(defn project-deps [components bases component-names-src component-names-test base-names-src base-names-test suffixed-top-ns brick-names-to-test]
(project-brick-deps/project-deps components bases component-names-src component-names-test base-names-src base-names-test suffixed-top-ns brick-names-to-test))
(defn project-deps [workspaces components bases component-names-src component-names-test base-names-src base-names-test suffixed-top-ns brick-names-to-test]
(project-brick-deps/project-deps workspaces components bases component-names-src component-names-test base-names-src base-names-test suffixed-top-ns brick-names-to-test))

(defn print-brick-project-table [workspace project-name brick-name]
(brick-project-deps-table/print-table workspace project-name brick-name))
Expand Down
22 changes: 16 additions & 6 deletions components/deps/src/polylith/clj/core/deps/project_brick_deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@
both the src and the test context, and make all the calculations for us.
If a brick is only included in the test context for the project, then we treat all dependencies as test dependencies."
[brick brick-id->deps ifc->comp all-brick-ids brick-ids-in-project brick-ids-in-project-test test-only-brick-ids brick-ids-to-test]
[brick brick-id->deps ifc->comp all-brick-ids brick-ids-in-project brick-ids-in-project-test test-only-brick-ids brick-ids-to-check]
(let [src-brick-id (->brick-id brick)
test-brick-id (str src-brick-id " (t)")
src-deps (finalize-deps src-brick-id brick-id->deps ifc->comp all-brick-ids brick-ids-in-project nil)
test-deps (finalize-deps test-brick-id brick-id->deps ifc->comp all-brick-ids brick-ids-in-project-test brick-ids-to-test)]
test-deps (finalize-deps test-brick-id brick-id->deps ifc->comp all-brick-ids brick-ids-in-project-test brick-ids-to-check)]
(if (contains? test-only-brick-ids src-brick-id)
{:src {}
:test (merge-deps src-deps test-deps)}
Expand All @@ -239,8 +239,8 @@
(set (map #(name->brick-id % %) bricks-to-test)))))

(defn project-deps
[components bases component-names-src component-names-test base-names-src base-names-test suffixed-top-ns brick-names-to-test]
"Calculate the src and test dependencies for a project. The returned dependencies
[workspaces components bases component-names-src component-names-test base-names-src base-names-test suffixed-top-ns brick-names-to-test]
"Calculates the src and test dependencies for a project. The returned dependencies
are stored in a map with a :src and :test key and includes a key for each brick that is included
in the project, together with the direct, indirect, and circular dependencies (if any) +
missing dependencies on interfaces and bases (if any).
Expand Down Expand Up @@ -281,6 +281,16 @@
:aliases > :test > :extra-paths syntax is only needed for the development project if your IDE doesn't support
the :local/root syntax.
The recommendation is to use the :local/root syntax in all your projects if it's supported by your IDE."
; (def workspaces workspaces)
; (def components components)
; (def bases bases)
; (def poly-bases bases)
; (def component-names-src component-names-src)
; (def component-names-test component-names-test)
; (def base-names-src base-names-src)
; (def base-names-test base-names-test)
; (def suffixed-top-ns suffixed-top-ns)
; (def brick-names-to-test brick-names-to-test)
(let [brick-names (set (concat component-names-src component-names-test base-names-src base-names-test))
bricks (filter #(contains? brick-names (:name %))
(concat bases components))
Expand All @@ -290,7 +300,7 @@
(concat components
(filter #(contains? component-names (:name %))
components))))
brick-ids-to-test (brick-names-to-ids brick-names-to-test components)
brick-ids-to-check (brick-names-to-ids brick-names-to-test components)
all-brick-ids (set (concat (map #(-> % :interface :name) components)
(map :name bases)))
brick-ids-in-project-src (brick-ids-in-project component-names-src base-names-src bricks)
Expand All @@ -317,5 +327,5 @@
(doseq [brick-id (brick-id->brick-ids test-brick-id)]
(update-deps! test-brick-id brick-id brick-id->brick-ids brick-id->deps #{test-brick-id}))))
;; Step 2: For each brick, convert interface names to component names + calculate missing and circular dependencies.
(into {} (map (juxt :name #(brick-deps % @brick-id->deps ifc->comp all-brick-ids brick-ids-in-project-src brick-ids-in-project-test test-only-brick-ids brick-ids-to-test))
(into {} (map (juxt :name #(brick-deps % @brick-id->deps ifc->comp all-brick-ids brick-ids-in-project-src brick-ids-in-project-test test-only-brick-ids brick-ids-to-check))
bricks))))
4 changes: 2 additions & 2 deletions components/file/deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{:paths ["src"]
:deps {clj-commons/fs {:mvn/version "1.6.310"}
org.clojure/tools.deps {:mvn/version "0.18.1398"}
:deps {clj-commons/fs {:mvn/version "1.6.311"}
org.clojure/tools.deps {:mvn/version "0.19.1417"}
borkdude/edamame {:mvn/version "1.4.25"}}
:aliases {:test {:extra-paths []
:extra-deps {}}}}
2 changes: 1 addition & 1 deletion components/tap/deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:paths ["src"]
:deps {djblue/portal {:mvn/version "0.51.1"}}
:deps {djblue/portal {:mvn/version "0.52.2"}}
:aliases {:test {:extra-paths []
:extra-deps {}}}}
4 changes: 4 additions & 0 deletions components/test/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:paths ["src" "resources"]
:deps {}
:aliases {:test {:extra-paths ["test"]
:extra-deps {}}}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns ^:no-doc polylith.clj.core.change.bricks-to-test
(ns ^:no-doc polylith.clj.core.test.bricks-to-test
(:require [clojure.set :as set]
[polylith.clj.core.common.interface :as common]))

Expand Down
22 changes: 22 additions & 0 deletions components/test/src/polylith/clj/core/test/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(ns ^:no-doc polylith.clj.core.test.core
(:require [polylith.clj.core.test.bricks-to-test :as bricks-to-test]
[polylith.clj.core.test.projects-to-test :as projects-to-test]
[polylith.clj.core.common.interface :as common]
[polylith.clj.core.git.interface :as git]))

(defn nothing-to-test [project]
(assoc project :bricks-to-test []
:projects-to-test []))

(defn with-test-calculations [{:keys [ws-dir user-input projects paths changes] :as workspace}]
(if (common/invalid-workspace? workspace)
workspace
(if (-> ws-dir git/is-git-repo? not)
(assoc workspace :projects (mapv nothing-to-test projects))
(let [{:keys [changed-components changed-bases changed-projects changed-or-affected-projects]} changes
{:keys [is-dev is-all is-run-all-brick-tests is-run-project-tests selected-bricks selected-projects]} user-input
projects-with-keys (mapv #(-> %
(bricks-to-test/with-bricks-to-test changed-projects changed-components changed-bases selected-bricks selected-projects is-dev is-run-all-brick-tests)
(projects-to-test/with-projects-to-test paths changed-or-affected-projects selected-projects is-dev is-run-project-tests is-all))
projects)]
(assoc workspace :projects projects-with-keys)))))
7 changes: 7 additions & 0 deletions components/test/src/polylith/clj/core/test/interface.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(ns ^:no-doc polylith.clj.core.test.interface
(:require [polylith.clj.core.test.core :as core]))

(defn with-test-calculations
"Make sure to first call changes/with-changes before calling this function."
[workspace]
(core/with-test-calculations workspace))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns ^:no-doc polylith.clj.core.change.projects-to-test
(ns ^:no-doc polylith.clj.core.test.projects-to-test
(:require [clojure.set :as set]
[polylith.clj.core.path-finder.interface.criterias :as c]
[polylith.clj.core.path-finder.interface.select :as select]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns polylith.clj.core.change.bricks-to-test-test
(ns polylith.clj.core.test.bricks-to-test-test
(:require [clojure.test :refer :all]
[polylith.clj.core.change.bricks-to-test :as to-test]
[polylith.clj.core.change.test-data :as data])
[polylith.clj.core.test.bricks-to-test :as to-test]
[polylith.clj.core.test.test-data :as data])
(:refer-clojure :exclude [test]))

(defn test [{:keys [changed-projects
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns polylith.clj.core.change.projects-to-test-test
(ns polylith.clj.core.test.projects-to-test-test
(:require [clojure.test :refer :all]
[polylith.clj.core.change.projects-to-test :as t]))
[polylith.clj.core.test.projects-to-test :as t]))

(deftest run-tests?--dont-run-project-tests-by-default
(is (false?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns polylith.clj.core.change.test-data
(ns polylith.clj.core.test.test-data
(:require [clojure.test :refer :all]))

(def dev {:is-dev true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(def minor 2)
(def patch 20)
(def revision SNAPSHOT) ;; Set to SNAPSHOT or RELEASE.
(def snapshot 6) ;; Increase by one for every snapshot release, or set to 0 if a release.
(def snapshot 8) ;; Increase by one for every snapshot release, or set to 0 if a release.
;; Also update :snapshot-version: at the top of readme.adoc.
(def snapshot? (= SNAPSHOT revision))

Expand All @@ -37,7 +37,7 @@

(def tool (if system/extended? "polyx" "poly"))

(def date "2024-03-06")
(def date "2024-03-17")

;; Execute 'poly doc version' to see when different changes was introduced.
(def api-version {:breaking 1, :non-breaking 0})
Expand Down
2 changes: 1 addition & 1 deletion components/workspace/deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:paths ["src"]
:deps {org.clojure/tools.deps {:mvn/version "0.18.1398"}}
:deps {org.clojure/tools.deps {:mvn/version "0.19.1417"}}
:aliases {:test {:extra-paths ["test"]
:extra-deps {}}}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[polylith.clj.core.file.interface :as file]
[polylith.clj.core.workspace.enrich.core :as enrich]
[polylith.clj.core.change.interface :as change]
[polylith.clj.core.test.interface :as test]
[polylith.clj.core.workspace.fromdisk.core :as fromdisk]
[polylith.clj.core.ws-file.interface :as ws-file]))

Expand Down Expand Up @@ -54,7 +55,8 @@
@wsdir->workspace))]
(-> workspace
(enrich/enrich-workspace workspaces)
(change/with-changes)))))))
(change/with-changes)
(test/with-test-calculations)))))))

(comment
(require '[polylith.clj.core.user-input.interface :as user-input])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
brick->loc (brick->loc enriched-bricks)
brick->lib-imports (brick->lib-imports enriched-bricks)
alias-id (atom 0)
enriched-projects (vec (sort-by project-sorter (mapv #(project/enrich-project % ws-dir alias-id enriched-components enriched-bases profiles suffixed-top-ns brick->loc brick->lib-imports paths user-input settings name-type->keep-lib-versions outdated-libs library->latest-version) projects)))
enriched-projects (vec (sort-by project-sorter (mapv #(project/enrich-project % ws-dir alias-id workspaces enriched-components enriched-bases profiles suffixed-top-ns brick->loc brick->lib-imports paths user-input settings name-type->keep-lib-versions outdated-libs library->latest-version) projects)))
messages (validator/validate-ws suffixed-top-ns settings paths interface-names interfaces profiles enriched-components enriched-bases enriched-projects config-errors interface-ns workspaces user-input color-mode)]
(cond-> workspace
true (assoc :interfaces interfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
(defn enrich-project [{:keys [alias name type is-dev test maven-repos namespaces paths lib-deps project-lib-deps] :as project}
ws-dir
alias-id
workspaces
components
bases
profiles
Expand Down Expand Up @@ -64,7 +65,7 @@
(seq base-names-test) (assoc :test base-names-test))
all-brick-names (concat component-names-src base-names-src component-names-test base-names-test)
brick-names-to-test (common/brick-names-to-test test all-brick-names)
deps (proj-deps/project-deps components bases component-names-src component-names-test base-names-src base-names-test suffixed-top-ns brick-names-to-test)
deps (proj-deps/project-deps workspaces components bases component-names-src component-names-test base-names-src base-names-test suffixed-top-ns brick-names-to-test)
lib-imports (project-lib-imports all-brick-names brick->lib-imports)
lines-of-code-total (project-total-loc all-brick-names brick->loc)
lines-of-code (assoc (loc/lines-of-code ws-dir namespaces) :total lines-of-code-total)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
(select-keys (proj/enrich-project {:name project-name :is-dev dev?}
"."
(atom 0)
{}
components
bases
profiles
Expand Down Expand Up @@ -178,6 +179,7 @@
(dissoc (proj/enrich-project project
"."
(atom 0)
{}
components
bases
profiles
Expand Down Expand Up @@ -248,6 +250,7 @@
(dissoc (proj/enrich-project project
"."
(atom 0)
{}
components
bases
[{:name "default"
Expand Down
Loading

0 comments on commit b6e4dd6

Please sign in to comment.