diff --git a/.github/workflows/commit_validation.yml b/.github/workflows/commit_validation.yml new file mode 100644 index 0000000..84010e4 --- /dev/null +++ b/.github/workflows/commit_validation.yml @@ -0,0 +1,51 @@ +name: Commit validation +on: + push: + branches: '**' + # Don't want to validate on tag push, only commits --> https://stackoverflow.com/questions/64708371/how-to-run-github-workflow-on-every-commit-of-a-push +jobs: + clojure: + strategy: + matrix: + os: [ubuntu-latest] # , windows-latest There is a path issue + # macOS-latest is removed to save github costs + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install java + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '22' + - name: Install clojure tools + uses: DeLaGuardo/setup-clojure@13.0 + with: + cli: 1.12.0.1479 # Clojure CLI based on tools.deps + bb: 1.12.195 # Babashka + clj-kondo: 2024.11.14 # Clj-kondo + zprint: 1.2.9 # zprint + - name: Install fdfind + run: sudo apt-get install -y fd-find + - name: Setup zprint + run: echo "{:search-config? true}" >> ~/.zprintrc + - name: Cache clojure dependencies + uses: actions/cache@v4 + with: + path: /home/runner/.m2/repository + key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }} + restore-keys: cljdeps- + - name: Tests code alias + linter + forbidden words + run: bb wf-4 -iawlp + - name: Test code + run: bb test test-bb test-unit + - name: Write git diff - show what has been changed by zprint + run: git diff + - name: Pushed code should already be formatted + uses: CatChen/check-git-status-action@v1 + with: + fail-if-not-clean: true + request-changes-if-not-clean: false + push-if-not-clean: false diff --git a/.github/workflows/deploy_clojar.yml b/.github/workflows/deploy_clojar.yml new file mode 100644 index 0000000..9bda420 --- /dev/null +++ b/.github/workflows/deploy_clojar.yml @@ -0,0 +1,19 @@ +name: Tag - Deployment to clojars +# See https://github.com/jlesquembre/clojars-publish-action +on: + push: + tags: + - "*" + +jobs: + clojars: + runs-on: ubuntu-latest + + steps: + # This step checks out a copy of your repository. + - uses: actions/checkout@v4 + + - uses: jlesquembre/clojars-publish-action@0.3 + env: + CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }} + CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }} diff --git a/.github/workflows/validation_delaguardo.yml b/.github/workflows/validation_delaguardo.yml deleted file mode 100644 index 114c49a..0000000 --- a/.github/workflows/validation_delaguardo.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Commit validation - Delaguardo flavor -on: - push: - branches: - - main - - la -jobs: - clojure: - strategy: - matrix: - os: [ubuntu-latest] # , windows-latest There is a path issue - # macOS-latest is removed to save github costs - runs-on: ${{ matrix.os }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Prepare java - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: '22' - - - name: Install clojure tools - uses: DeLaGuardo/setup-clojure@13.0 - with: - cli: 1.12.0.1479 # Clojure CLI based on tools.deps - bb: 1.12.195 # Babashka - clj-kondo: 2024.11.14 # Clj-kondo - cljfmt: 0.13.0 # cljfmt - zprint: 1.2.9 # zprint - - name: Cache clojure dependencies - uses: actions/cache@v4 - with: - path: /home/runner/.m2/repository - key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }} - restore-keys: cljdeps- - - name: Test - run: bb wf-4 -ibawl -d :common-test diff --git a/.github/workflows/validation_docker.old b/.github/workflows/validation_docker.old deleted file mode 100644 index 644566d..0000000 --- a/.github/workflows/validation_docker.old +++ /dev/null @@ -1,11 +0,0 @@ -name: Commit validation - docker flavor -run-name: Test ${{ github.event.head_commit.message }} -on: [push] -jobs: - run-bb: - runs-on: ubuntu-latest - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - name: Base image - uses: docker://hephaistox/gha-image:1.0.1 diff --git a/README.md b/README.md index 8d64c17..470b50b 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,38 @@ # automaton-build -Automaton build library streamlines the creation, development, testing, and publishing of the projects. -automaton picture +Automaton build library streamlines the creation, development, testing, and publishing of the automaton projects. + +automaton duck picture > If every tool, when ordered, or even of its own accord, could do the work that befits it, just as the creations of Daedalus moved of themselves, or the tripods of Hephaestus went of their own accord to their sacred work, if the shuttle would weave and the plectrum touch the lyre without a hand to guide them, master-craftsmen would have no need of assistants and masters no need of slaves ~ Aristotle, Politics 1253b ## Motivation -While working with multiple projects in the organization, many things are repetitive, like running repl, formatting and linting the code, versioning, CICD etc. This library aims to simplify and automate this work. + +To meet monorepo objectives, it should be possible to quickly create a project and maintain its modifications through time. + +At the same moment, it is really complicated and most often dangerous to decide for once how all projects should look like. + +So, all factorized code is stored in the `automaton-build` project. + +## Design decision + +See [design decision page](docs/design_decision.md) ## Quick start -To integrate automaton-build into your project + +To integrate `automaton-build` into your project: + 1. Create `bb.edn` file at the root of your project with the following content: ``` clojure {:deps {org.clojars.hephaistox/automaton-build #:mvn{:version "1.0.2"}} -:tasks {-base-deps {:doc "Dependencies for a task using bb" - :extra-deps {org.clojure/tools.cli {:mvn/version "1.1.230"}}} +:tasks {-base-deps {:doc "Dependencies for a task using bb"} :requires [[automaton-build.tasks.common :as tasks-common]]}} ``` + Which will: -* Add this library (automaton-build) dependency to enable its features. -* Add the `-base-deps` task. Which will be used to declare whatever is common to all tasks. It starts with `-` so it is not shown in the task list. +* Add the `automaton-build` library dependency to enable its features. +* Add the `-base-deps` task to declare whatever is common to all tasks. It starts with `-` so it is not shown in the task list. * Add the `requires` that enables `tasks-common` namespace for all tasks so you don't have to repeat it. 2. Add your custom tasks or use pre-defined ones from the `automaton-build.tasks` directory. @@ -29,27 +41,16 @@ Example task for starting REPL: ```clojure repl {:depends [-base-deps] :requires [[automaton-build.tasks.2 :as tasks-2]] - :extra-deps {djblue/portal {:mvn/version "0.52.2"}} + :extra-deps {} :doc "Launch repl" :enter (tasks-common/enter tasks-2/cli-opts (current-task)) :task (tasks-2/start-repl [:common-test :env-development-repl :build])} ``` ## Tasks configuration -Some tasks may require additional configuration. Set up a `project.edn` file in your project root to customize task behavior. -For an example refer to the forbidden-words report task [automaton-build.tasks.tasks.3](src/bb/automaton_build/tasks/3.clj) and [project.edn file](project.edn) - -## Compatibility of dependencies -To use external dependency (`:extra-deps` alias), dependency needs to compile to the GraalVM or be included in Babashka. -[For a list of compatible libraries see the Babashka documentation](https://github.com/babashka/babashka/blob/master/doc/projects.md) - -In case the library is not supported, but has CLI capabilities, you can include it as an alias in the project `deps.edn` and just call cmd with "clojure -M/X:alias". -[Example of it can be found in documentation task that uses codox library](src/bb/automaton_build/tasks/doc.clj) -## See documentation -This library is heavily based on the usage of [babashka tasks](https://book.babashka.org/#_tasks_api). +Some tasks may require additional configuration. Set up a `project.edn` file in your project root to customize task behavior. For an example refer to the forbidden-words report task [automaton-build.tasks.tasks.3](src/bb/automaton_build/tasks/3.clj) and [project.edn file](project.edn) -If you're interested in more detail about the approach we took while developing this library look at [design decisions document](docs/design_decision.md) [For detailed API documentation click here](https://hephaistox.github.io/automaton-build/latest). diff --git a/bb.edn b/bb.edn index 03b36a4..fa28452 100644 --- a/bb.edn +++ b/bb.edn @@ -1,22 +1,39 @@ {:deps {cheshire/cheshire {:mvn/version "5.13.0"} - djblue/portal {:mvn/version "0.58.2"} io.github.clojure/tools.build {:mvn/version "0.10.5"} metosin/malli {:mvn/version "0.16.1"} org.clojure/tools.cli {:mvn/version "1.1.230"}} - :paths ["src/clj" "src/bb" "test_la/clj"] + :paths ["src/clj" "src/bb"] :tasks - {-base-deps {:doc "Dependencies for a task using bb" - :extra-deps {org.clojure/tools.cli {:mvn/version "1.1.230"}}} + {-base-deps {:doc "Dependencies for a task using bb"} :requires [[automaton-build.tasks.common :as tasks-common]] - lconnect - {:doc - "Repl in case automaton-build is failing. Using -f or --force cli arguments to force start if some part are failing" - :task (try (-> (babahska-process/shell "clojure" - "-M:common-test:env-development-repl:build" - *command-line-args*) - System/exit) - (catch Exception e - (println "Repl failed also - error during repl startup" (ex-message e))))} + deploy {:doc "Publish this project" + :requires [[automaton-build.tasks.deploy-app :refer [run]]] + :task (run)} + docs {:depends [-base-deps] + :doc "Publish documentation." + :enter (tasks-common/enter-with-arguments tasks-docs/cli-opts-common-def + (current-task) + tasks-docs/arguments) + :requires [[automaton-build.tasks.docs :as tasks-docs]] + :task (tasks-docs/run-app "**{.png,.gif,.jpg,.svg}" "gh-pages-dont-change")} + lconnect {:doc "Repl in case automaton-build is failing." + :task (-> (try (-> (shell "clojure" "-M:env-development-repl") + :exit) + (catch Exception e + (println "Repl failed also - error during repl startup\n *" + (pr-str e)) + -1)) + System/exit)} + test {:doc "Dev test bb code in jvm" + :requires [[automaton-build.tasks.test :as test]] + :task (-> (test/run "clj-test-runner" + #{{:description "bb tests in jvm" + :alias :test-bb} + {:description "unit tests - assembly tests at unit level" + :alias :test-unit} + {:description "test local development environmnet itself" + :alias :test-dev}}) + System/exit)} wf-4 {:depends [-base-deps] :doc "Full test and formatting." :enter (tasks-common/enter wf-4/cli-opts (current-task)) diff --git a/deps.edn b/deps.edn index 9672c88..16f72a9 100644 --- a/deps.edn +++ b/deps.edn @@ -1,6 +1,9 @@ {:aliases - {:antq {:deps {com.github.liquidz/antq {:mvn/version "2.11.1250"}} - :main-opts ["-m" "antq.core"]} + {:clj-test-runner {:exec-fn cognitect.test-runner.api/test + :extra-deps {com.cognitect/test-runner + {:git/url "https://github.com/cognitect-labs/test-runner" + :sha "3f288f1f16d167723ad87cc35b1dfee3c1681e10"}} + :jvm-opts ["-Dheph-conf=env/test_config.edn,env/common_config.edn"]} :codox {:exec-args {:description "`automaton-build` is a library to ease project cicd: build, test, deployemnt..." @@ -11,45 +14,21 @@ :source-uri "https://github.com/hephaistox/automaton-build/blob/{version}/{filepath}#L{line}"} :exec-fn codox.main/generate-docs :extra-deps {codox/codox {:mvn/version "0.10.8"}}} - :common-test - {:exec-fn cognitect.test-runner.api/test - :extra-deps {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner" - :sha "3f288f1f16d167723ad87cc35b1dfee3c1681e10"} - org.clojure/tools.namespace {:mvn/version "1.5.0"} - org.clojure/tools.reader {:mvn/version "1.5.0"}} - :extra-paths ["test/unit/bb" "test/unit/resources" "test/la/bb"] - :jvm-opts ["-Dheph-conf=env/test/config.edn,env/common_config.edn" "-Dhephaistox-in-test=true"] - :main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/unit" "-d" "test/la"]} - :deploy {:exec-args {:installer :remote} - :exec-fn deps-deploy.deps-deploy/deploy - :extra-deps {slipset/deps-deploy {:exclusions [org.slf4j/slf4j-nop] - :mvn/version "0.2.2"}}} - :env-development-repl - {:extra-deps {djblue/portal {:mvn/version "0.58.2"} - org.clojure/core.async {:mvn/version "1.6.681"}} - :extra-paths ["env/development/resources" "env/development/src/clj" "env/development/src/cljc"] - :jvm-opts ["-Dheph-conf=env/development/config.edn,env/common_config.edn"] - :main-opts ["-m" "automaton-build.repl.entry-point"]} - :env-development-test - {:exec-fn cognitect.test-runner.api/test - :extra-deps {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner" - :sha "3f288f1f16d167723ad87cc35b1dfee3c1681e10"} - org.clojure/tools.namespace {:mvn/version "1.5.0"} - org.clojure/tools.reader {:mvn/version "1.5.0"}} - :extra-paths ["test/dev/bb" "test/dev/clj" "test/dev/resources"] - :jvm-opts ["-Dhephaistox-in-test=true"] - :main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/dev"]}} + :repl {:extra-paths ["env/development/src/bb"] + :jvm-opts ["-Dheph-conf=env/development/config.edn,env/common_config.edn"] + :main-opts ["-m" "automaton-build.repl.entry-point"]} + :test-bb {:extra-paths ["test/bb"] + :main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/bb"]} + :test-dev {:extra-paths ["test/dev/bb" "test/dev/resources"] + :main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/dev"]} + :test-unit {:extra-paths ["test/unit/bb" "test/unit/resources"] + :main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/unit"]}} :deps {babashka/fs {:mvn/version "0.5.22"} babashka/process {:mvn/version "0.5.22"} cheshire/cheshire {:mvn/version "5.13.0"} clj-htmltopdf/clj-htmltopdf {:mvn/version "0.2.1"} codox/codox {:mvn/version "0.10.8"} - dev.weavejester/medley {:mvn/version "1.8.1"} - djblue/portal {:mvn/version "0.58.2"} - hiccup/hiccup {:mvn/version "2.0.0-RC3"} io.github.clojure/tools.build {:mvn/version "0.10.5"} - markdown-clj/markdown-clj {:mvn/version "1.12.2"} metosin/malli {:mvn/version "0.16.1"} zprint/zprint {:mvn/version "1.2.9"}} - :ns-default automaton-build.core :paths ["src/bb"]} diff --git a/env/development/config.edn b/env/development/config.edn index 9a3ecc3..11e74db 100644 --- a/env/development/config.edn +++ b/env/development/config.edn @@ -1,3 +1,2 @@ -{:dev {:clj-nrepl-port 8010 - :portal-port 8351} +{:dev {:clj-nrepl-port 8010} :env :development} diff --git a/env/development/src/bb/automaton_build/repl/entry_point.clj b/env/development/src/bb/automaton_build/repl/entry_point.clj new file mode 100644 index 0000000..427953b --- /dev/null +++ b/env/development/src/bb/automaton_build/repl/entry_point.clj @@ -0,0 +1,12 @@ +(ns automaton-build.repl.entry-point + "Entry point for repl" + (:require + [nrepl.server :refer [start-server]])) + +(defn -main + "Entry point" + [& _args] + (let [port 1234] + (println "Automaton build development mode") + (println "Start repl on port" port) + (start-server :port port))) diff --git a/env/test/file_found.edn b/env/test/file_found.edn deleted file mode 100644 index c61f5e4..0000000 --- a/env/test/file_found.edn +++ /dev/null @@ -1,2 +0,0 @@ -For -automaton-build.os.file-test diff --git a/env/test/src/.keep b/env/test/src/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/env/test/config.edn b/env/test_config.edn similarity index 100% rename from env/test/config.edn rename to env/test_config.edn diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..dbee818 --- /dev/null +++ b/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + jar + org.clojars.hephaistox + automaton-build + LATEST + automan-build + Hephaistox common tasks for project manipulation + https://github.com/hephaistox/automaton-build + + + + CC BY-NC 4.0 + https://creativecommons.org/licenses/by-nc/4.0/deed.en + + + + + + Hephaistox + + + + + https://github.com/hephaistox/automaton-build + scm:git:ssh://git@github.com:hephaistox/automaton-build.git + HEAD + + + diff --git a/project.edn b/project.edn index f8a1eff..b1f3167 100644 --- a/project.edn +++ b/project.edn @@ -2,11 +2,4 @@ :code {:forbidden-words ["TODO" "DONE" "NOTE" "FIXME" "tap>" "automaton-core" "automaton-web"]} :deps {:excluded-libs [{:doc "0.16.3 has deprecated warnings, fix is already in main merged but not released yet" - :name "metosin/malli"}]} - :publication {:base-branch "main" - :clojars true - :excluded-aliases - [:antq :codox :env-development-repl :env-development-test :common-test :deploy] - :la-branch "la" - :pom-xml-license {:name "CC BY-NC 4.0" - :url "https://creativecommons.org/licenses/by-nc/4.0/deed.en"}}} + :name "metosin/malli"}]}} diff --git a/resources/.keep b/resources/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/specific_task_registry.edn b/specific_task_registry.edn deleted file mode 100644 index 0967ef4..0000000 --- a/specific_task_registry.edn +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/src/bb/automaton_build/code/formatter.clj b/src/bb/automaton_build/code/formatter.clj index dad567f..79c2fdd 100644 --- a/src/bb/automaton_build/code/formatter.clj +++ b/src/bb/automaton_build/code/formatter.clj @@ -29,4 +29,4 @@ (defn format-clj-cmd "Command formatting all clj files in the directory and subdirectories where it is executed." [] - ["fd" "-e" "clj" "-e" "cljc" "-e" "cljs" "-e" "edn" "-x" "zprint" "-w"]) + ["fdfind" "-e" "clj" "-e" "cljc" "-e" "cljs" "-e" "edn" "-x" "zprint" "-w"]) diff --git a/src/bb/automaton_build/code/vcs.clj b/src/bb/automaton_build/code/vcs.clj index 825e8c0..5e80677 100644 --- a/src/bb/automaton_build/code/vcs.clj +++ b/src/bb/automaton_build/code/vcs.clj @@ -214,3 +214,48 @@ "Check if the returned value of clean state " [res] (and (= 0 (:exit res)) (str/blank? (:out res)))) + +(defn current-tag-cmd + "Command to return the the tag of the current commit" + [] + ["git" "describe" "--exact-match" "--tags"]) + +(defn current-tag-analyze + [res] + (if (= 0 (:exit res)) + {:found true + :tag (-> res + :out + str/split-lines + first)} + {:found false})) + +(defn current-repo-url-cmd "Command to return the current remote url" [] ["git" "remote" "-v"]) + +(defn current-repo-url-analyze + "Returns the url string to push to the origin repo, `nil` if was failing." + [{:keys [exit out]}] + (when (= 0 exit) + (->> out + str/split-lines + (map (fn [line] + (->> line + (re-find #"origin\s*([^\s]*).*(push)") + second))) + (filter some?) + first))) + +(defn gh-run-wip?-cmd "Returns `true` if the workflow is in progress" [] ["gh" "run" "list"]) + +(defn gh-run-wip?-analyze + [{:keys [exit out]}] + (when (= 0 exit) + (let [res (->> out + str/split-lines + first)] + (cond-> {:run-id (->> (str/split res #"\t") + (drop 6) + first)} + (re-find #"completed\tsuccess" res) (assoc :status :run-ok) + (re-find #"completed\tfailure" res) (assoc :status :run-failed) + (not (re-find #"completed\t" res)) (assoc :status :wip))))) diff --git a/src/bb/automaton_build/doc/mermaid.clj b/src/bb/automaton_build/doc/mermaid.clj deleted file mode 100644 index 847a8b0..0000000 --- a/src/bb/automaton_build/doc/mermaid.clj +++ /dev/null @@ -1,84 +0,0 @@ -(ns automaton-build.doc.mermaid - "Create mermaid images. - - Proxy to [mermaid cli](https://www.npmjs.com/package/@mermaid-js/mermaid-cli)" - (:require - [automaton-build.os.file :as build-file] - [automaton-build.os.filename :as build-filename])) - -(def ^:private mermaid-pattern "**.mermaid") - -(defn mermaid-pull-cli-cmd - "Command to install the mermaid cli." - [] - ["docker" "pull" "minlag/mermaid-cli"]) - -(defn mermaid-build-image-cmd - "Command to transform `mermaid-filepath` into an image -a png- into the `target-dir`. - - `user-id` and `group-id` are necessary to execute the command. " - [mermaid-filepath user-id group-id target-dir] - (let [mermaid-filename (build-filename/filename mermaid-filepath) - image-filename (build-filename/change-extension mermaid-filename ".png")] - {:output-file (build-filename/create-file-path target-dir image-filename) - :cmd ["docker" - "run" - "--rm" - "-u" - (str user-id ":" group-id) - "-v" - (str (-> mermaid-filepath - build-filename/extract-path - build-filename/absolutize) - ":/data") - "-v" - (str (build-filename/absolutize target-dir) ":/out-data") - "minlag/mermaid-cli" - "-i" - mermaid-filename - "-o" - (build-filename/create-file-path "/out-data" image-filename)]})) - -(defn need-to-update? - "Returns true if `file-in` needed to be modified, compared to `file-out`." - [file-in file-out] - (and (build-filename/match-extension? file-in ".mermaid") - (seq (build-file/modified-since file-out [file-in])))) - -(defn build-mermaid-image-cmd - "Returns a map with - - * `cmd` a command to turn `mermaid-filename` into an image with extension `image-extension`. - * and `target-path` the name of the image generated." - [mermaid-filename image-extension user-id group-id] - (let [filename (build-filename/filename mermaid-filename)] - {:command ["docker" - "run" - "--rm" - "-u" - (str user-id ":" group-id) - "-v" - (str (-> (build-filename/extract-path mermaid-filename) - build-filename/absolutize) - ":/data") - "minlag/mermaid-cli" - "-i" - filename - "-o" - (build-filename/change-extension filename image-extension)] - :target-path (build-filename/change-extension mermaid-filename image-extension)})) - -(defn ls-mermaid - "List all mermaid files searched recursively in `app-dir`." - [app-dir] - (->> (build-file/matching-files app-dir mermaid-pattern) - (mapv str))) - -(defn files-to-recompile - "List files that need to be recompiled, i.e. the one existing and which image is older than the last update of the source." - [mermaid-files image-extension] - (->> mermaid-files - (mapv str) - (filterv (fn [file] - (let [file-out (build-filename/change-extension file image-extension)] - (and (build-file/is-existing-file? file) (need-to-update? file file-out))))))) diff --git a/src/bb/automaton_build/echo/headers.clj b/src/bb/automaton_build/echo/headers.clj index 52eac6c..d09466d 100644 --- a/src/bb/automaton_build/echo/headers.clj +++ b/src/bb/automaton_build/echo/headers.clj @@ -84,8 +84,8 @@ [& texts] (swap! build-echo-common/echo-param assoc :section 2) (print build-text/font-red) - (header-printing "!" texts)) -(print build-text/font-default) + (header-printing "!" texts) + (print build-text/font-default)) (defn h2-valid! [& texts] diff --git a/src/bb/automaton_build/tasks/2.clj b/src/bb/automaton_build/tasks/2.clj index 58f34cb..30da894 100644 --- a/src/bb/automaton_build/tasks/2.clj +++ b/src/bb/automaton_build/tasks/2.clj @@ -1,17 +1,13 @@ (ns automaton-build.tasks.2 "Workflow 2 is starting a local development environment" (:require - [automaton-build.code.cljs :as build-cljs] - [automaton-build.doc.mermaid :as build-mermaid] - [automaton-build.echo.actions :refer - [action errorln exceptionln normalln uri-str]] - [automaton-build.fe.css :as build-fe-css] - [automaton-build.os.cli-opts :as build-cli-opts] - [automaton-build.os.file :as build-file] - [automaton-build.os.filename :as build-filename] - [automaton-build.tasks.impl.actions.cmds :refer [blocking-cmd long-living-cmd success]] - [automaton-build.tasks.impl.actions.user-info :as build-user-info] - [clojure.string :as str])) + [automaton-build.code.cljs :as build-cljs] + [automaton-build.echo.actions :refer [action errorln exceptionln normalln uri-str]] + [automaton-build.fe.css :as build-fe-css] + [automaton-build.os.cli-opts :as build-cli-opts] + [automaton-build.os.file :as build-file] + [automaton-build.tasks.impl.actions.cmds :refer [blocking-cmd long-living-cmd]] + [clojure.string :as str])) (def ^:private cli-opts (-> [["-r" "--repl" "Don't start the clj REPL" :default true :parse-fn not] @@ -94,59 +90,3 @@ (catch Exception e (errorln "Unexpected error" e)))) (def generated-image-extension ".png") - -(defn- build-new-mermaid-file-list - "Returns filenames of mermaid files to update, exclude `failed-files`." - [mermaid-all failed-files normalln] - (let [app-dir "" - mermaid-files (->> (build-mermaid/ls-mermaid app-dir) - (remove failed-files) - vec) - changed-files (if mermaid-all - mermaid-files - (-> mermaid-files - (build-mermaid/files-to-recompile generated-image-extension) - vec))] - (when verbose (normalln "Detected mermaid files: ") (normalln mermaid-files)) - (when-not (empty? failed-files) - (normalln "Failing files are excluded (unless updated again:)") - (normalln (str/join " " failed-files))) - changed-files)) - -(defn mermaid - "Watch mermaid files." - [] - (try - (when (or (get-in cli-opts [:options :mermaid]) (get-in cli-opts [:options :mermaid-all])) - (let [app-dir (build-filename/absolutize "") - prefixs ["md"] - mermaid-all (get-in cli-opts [:options :mermaid-all]) - {:keys [id group-id]} (build-user-info/user-infos prefixs false) - actionln (partial action prefixs) - normalln (partial normalln prefixs) - errorln (partial errorln prefixs) - blocking-cmd (partial blocking-cmd prefixs)] - (if (some nil? [id group-id]) - (errorln "Skip mermaid update.") - (do (actionln "Watching mermaid files in sub-directory of" (uri-str app-dir)) - (loop [failed-files #{} - files-to-do (build-new-mermaid-file-list mermaid-all failed-files normalln)] - (if (empty? files-to-do) - (do (Thread/sleep 1000) - (recur failed-files - (build-new-mermaid-file-list false failed-files normalln))) - (let [{:keys [command target-path]} (-> (first files-to-do) - (build-mermaid/build-mermaid-image-cmd - generated-image-extension - id - group-id)) - res (blocking-cmd command - app-dir - (format "Has not been able to proceed with `%s`" - target-path) - verbose)] - (when (success res) (normalln (uri-str target-path) "has been generated")) - (recur failed-files (rest files-to-do))))))))) - (catch Exception e - (println "Unexpected error during execution of css watch") - (println (pr-str e))))) diff --git a/src/bb/automaton_build/tasks/4.clj b/src/bb/automaton_build/tasks/4.clj index cd52db3..3e4d657 100644 --- a/src/bb/automaton_build/tasks/4.clj +++ b/src/bb/automaton_build/tasks/4.clj @@ -4,7 +4,6 @@ (:require [automaton-build.code.cljs :as build-cljs] [automaton-build.code.formatter :as build-formatter] - [automaton-build.code.vcs :as build-vcs] [automaton-build.echo.headers :refer [build-writter errorln h1 @@ -118,21 +117,6 @@ ;; ******************************************************************************** ;; API ;; ******************************************************************************** -(defn clean-state - "Check if the state is clean" - [project-dir] - (h1 "Check clean state.") - (let [s (build-writter) - res (binding [*out* s] - (-> (build-vcs/clean-state) - (blocking-cmd project-dir "" verbose)))] - (if (build-vcs/clean-state-analyze res) - (h1-valid "git state is clean.") - (h1-error "git state is not clean.")) - (print-writter s) - (when verbose (normalln (:out res))) - (build-vcs/clean-state-analyze res))) - (defn clj-test "Run clj test." [project-dir test-aliases] @@ -191,8 +175,7 @@ {:aliases-check (build-tasks-report-aliases/scan-alias project-map verbose)}) (when linter? {:linting (build-linter/lint (:deps project-map) verbose)}) (when tests-b? {:clj-tests-check (clj-test app-dir test-aliases)}) - (when tests-f? {:cljs-tests-check (cljs-test app-dir)}) - {:clean-state (clean-state app-dir)}) + (when tests-f? {:cljs-tests-check (cljs-test app-dir)})) status (->> status-map vals (every? true?))] @@ -225,9 +208,8 @@ build-project-map/add-project-config build-project-map/add-deps-edn))] (if (or (false? (get-in cli-opts [:options :generate-files])) - (and (every? (fn [[_k v]] (not= (:status v) :fail)) - (generate-monorepo-files/generate-files monorepo-project-map)) - (true? (clean-state (:app-dir monorepo-project-map))))) + (every? (fn [[_k v]] (not= (:status v) :fail)) + (generate-monorepo-files/generate-files monorepo-project-map))) (run* monorepo-project-map test-aliases) (do (h1-error! "State is not clean") 1))))) diff --git a/src/bb/automaton_build/tasks/deploy_app.clj b/src/bb/automaton_build/tasks/deploy_app.clj new file mode 100644 index 0000000..ac174a9 --- /dev/null +++ b/src/bb/automaton_build/tasks/deploy_app.clj @@ -0,0 +1,89 @@ +(ns automaton-build.tasks.deploy-app + "Deployment app per app" + (:require + [automaton-build.code.vcs :as build-vcs] + [automaton-build.echo.headers :refer [errorln h1 h2 h2-error h2-valid normalln]] + [automaton-build.os.cli-opts :as build-cli-opts] + [automaton-build.os.exit-codes :as build-exit-codes] + [automaton-build.project.map :as build-project-map] + [automaton-build.tasks.impl.headers.cmds :refer [blocking-cmd]])) + +; ******************************************************************************** +; *** Task setup +; ******************************************************************************** + +(def ^:private cli-opts + (-> [["-t" "--tag TAG" "Tag name, e.g. 1.3.2"] + ["-m" "--message MESSAGE" "Message for local apps push"]] + (concat build-cli-opts/help-options build-cli-opts/verbose-options) + build-cli-opts/parse-cli)) + +(def verbose? (get-in cli-opts [:options :verbose])) + +(def help (get-in cli-opts [:options :help])) + +(def tag (get-in cli-opts [:options :tag])) + +(def message (get-in cli-opts [:options :message])) + +; ******************************************************************************** +; *** Task +; ******************************************************************************** + +(defn run + [] + (let [app-dir "" + project-map (-> (build-project-map/create-project-map app-dir) + build-project-map/add-project-config) + {:keys [app-name]} project-map] + (h1 (str "Deploy app `" app-name "`")) + (when-not tag (errorln "The tag is mandatory")) + (when-not message (errorln "The message is mandatory")) + (when (:errors cli-opts) (errorln "Arguments are invalid") (build-cli-opts/error-msg cli-opts)) + (when (or (some? (:errors cli-opts)) (some nil? [tag message])) + (-> (build-cli-opts/print-usage cli-opts "deploy-app") + normalln) + (System/exit build-exit-codes/invalid-argument)) + (h2 "Check run status") + (let [{:keys [status run-id]} + (-> (build-vcs/gh-run-wip?-cmd) + (blocking-cmd app-dir "Error when getting github run status" verbose?) + build-vcs/gh-run-wip?-analyze)] + (when (= :wip status) + (h2-error "Run" run-id "has not finished") + (normalln (str "Visit `https://github.com/hephaistox/" + app-name + "/actions/runs/" + run-id + "` if needed")) + (normalln (str "or execute `gh run watch " run-id "`")) + (System/exit build-exit-codes/invalid-state)) + (when (= :run-failed status) + (h2-error "Run has failed") + (normalln + (str "Visit `https://github.com/hephaistox/" app-name "/actions/runs/" run-id "`")) + (normalln (str "or execute `gh run view --log " run-id "`")) + (System/exit build-exit-codes/invalid-state)) + (h2-valid "Run" run-id "passed") + (h2 "Tag" tag (str " with message `" message "`")) + (when-not (= 0 + (-> ["git" "tag" "-a" tag "-m" (str "\"" message "\"")] + (blocking-cmd app-dir "Tagging commit has failed" verbose?) + :exit)) + (h2-error "Tag has failed, deployment abort") + (System/exit build-exit-codes/cannot-execute)) + (when-not (= 0 + (-> ["git" "push" "origin" tag] + (blocking-cmd app-dir "Tag push has failed" verbose?) + :exit)) + (h2-error "Tag push has failed, deployment abort") + (System/exit build-exit-codes/cannot-execute)) + (h2-valid "Commit is tagged with " tag) + (h2 "Publish documentation") + (when-not (= 0 + (-> ["bb" "docs" tag "-r"] + (blocking-cmd app-dir "Documentation has failed" verbose?) + :exit)) + (h2-error "Documentation publishing has failed") + (System/exit build-exit-codes/cannot-execute)) + (h2-valid "Documentation published")))) diff --git a/src/bb/automaton_build/tasks/docs.clj b/src/bb/automaton_build/tasks/docs.clj index 64f5ad9..1e364c5 100644 --- a/src/bb/automaton_build/tasks/docs.clj +++ b/src/bb/automaton_build/tasks/docs.clj @@ -33,7 +33,7 @@ ;; ******************************************************************************** ;; Helpers ;; ******************************************************************************** -(def ^:private cli-opts-common-def +(def cli-opts-common-def (-> [["-r" "--remote" "Publish remotely the documentation"] ["-k" "--keep" "Keep the temporary directories"]] (concat build-cli-opts/help-options build-cli-opts/verbose-options))) @@ -237,21 +237,62 @@ (build-apps/add-monorepo-subprojects monorepo-name) (build-apps/apply-to-subprojects build-project-map/add-project-config - build-project-map/add-deps-edn))] + build-project-map/add-deps-edn)) + version (or version (build-version/current-version app-dir))] (when verbose (normalln "Version" version)) (if-let [{:keys [app-dir repo-url project-config-filedesc]} (first (filter (fn [subproject] (and some? project (= project (:app-name subproject)))) (:subprojects monorepo-project-map)))] - (let [version (or version (build-version/current-version app-dir))] - (publish-doc-task app-dir - repo-url - project-config-filedesc - version - resource-filters - doc-branch - (get-in cli-opts-monorepo [:options :remote]))) + (publish-doc-task app-dir + repo-url + project-config-filedesc + version + resource-filters + doc-branch + (get-in cli-opts-monorepo [:options :remote])) (build-headers-files/invalid-project-name-message monorepo-project-map)))) +(defn run-app + "Generates the documentation of the current application with the current tag. + + * The `resource-filters` are used to find what images to copy to the website. + + Gather data from: + + * The `project-config` is used to retrieve the `app-name` and the `repo-url` and `base-branch`. + * The `doc-paths` is coming from the `deps.edn` codox alias. + * Push the modifications to `doc-branch`." + [resource-filters doc-branch] + (let [app-dir "" + repo-url-res + (-> (build-vcs/current-repo-url-cmd) + (blocking-cmd app-dir "error when retrieveing the url of the remote origin" verbose)) + repo-url (build-vcs/current-repo-url-analyze repo-url-res) + {version :tag + found? :found} + (-> (build-vcs/current-tag-cmd) + (blocking-cmd + app-dir + "Error while getting the version of the documentation, your commit should have a tag" + verbose) + build-vcs/current-tag-analyze)] + (when verbose (normalln "Version: " version) (normalln (str "Distant repo url `" repo-url "`"))) + (if-not found? + (errorln "Abort doc creation, don't know how to create a doc without its version") + (do (when verbose (normalln "Version" version)) + (let [{:keys [app-dir project-config-filedesc]} (-> (build-project-map/create-project-map + app-dir) + build-project-map/add-project-config + build-project-map/add-deps-edn)] + (when (= 0 (:exit repo-url-res)) + (publish-doc-task app-dir + repo-url + project-config-filedesc + version + resource-filters + doc-branch + (get-in cli-opts-monorepo [:options :remote])))))))) + (def arguments {:doc-str "VERSION" :message "Where VERSION is the name of the version you want to push." diff --git a/src/bb/automaton_build/tasks/doctor.clj b/src/bb/automaton_build/tasks/doctor.clj index 3119e3f..066919d 100644 --- a/src/bb/automaton_build/tasks/doctor.clj +++ b/src/bb/automaton_build/tasks/doctor.clj @@ -3,7 +3,6 @@ (:require [automaton-build.code.formatter :as build-formatter] [automaton-build.data.schema :as build-data-schema] - [automaton-build.doc.mermaid :as build-mermaid] [automaton-build.echo.headers :refer [h1 h1-error h1-error! @@ -71,39 +70,6 @@ [app-dir] (doctor-cmd (build-user/user-id-cmd) app-dir "group is found" "group is not found")) -(defn mermaid-installed - "Check mermaid is installed." - [app-dir] - (doctor-cmd (build-mermaid/mermaid-pull-cli-cmd) - app-dir - "mermaid is valid" - "mermaid is not properly setup.")) - -(defn mermaid-running - "Check mermaid is installed." - [app-dir] - (let - [user-id (-> (build-user/user-id-cmd) - (blocking-cmd "" "" false) - build-user/id-analyze) - group-id (-> (build-user/group-id-cmd) - (blocking-cmd "" "" false) - build-user/id-analyze) - mermaid-filename (build-file/create-temp-file) - _write-mermaid-file - (build-file/write-file - mermaid-filename - "erDiagram\nCUSTOMER ||--o{ ORDER : places\nORDER ||--|{ LINE-ITEM : contains\nCUSTOMER }|..|{ DELIVERY-ADDRESS : uses") - tmp-dir (build-file/create-temp-dir) - {:keys [output-file cmd]} - (build-mermaid/mermaid-build-image-cmd mermaid-filename user-id group-id tmp-dir) - res (blocking-cmd cmd app-dir "Should not appear" false)] - (if (build-file/is-existing-file? output-file) - {:message "mmdc is valid" - :status :ok} - {:message "mmdc is not properly setup." - :details (:out res)}))) - (defn git-installed "Git tooling is installed." [app-dir] @@ -236,10 +202,6 @@ :fn-to-call group-id} {:check-name "user-id" :fn-to-call user-id} - {:check-name "mermaid installed" - :fn-to-call mermaid-installed} - {:check-name "mermaid running" - :fn-to-call mermaid-running} {:check-name "zprint" :fn-to-call zprint} {:check-name "zprint-setup" diff --git a/src/bb/automaton_build/tasks/test.clj b/src/bb/automaton_build/tasks/test.clj new file mode 100644 index 0000000..5533d2a --- /dev/null +++ b/src/bb/automaton_build/tasks/test.clj @@ -0,0 +1,97 @@ +(ns automaton-build.tasks.test + "Test the project" + (:require + [automaton-build.echo.headers :refer [errorln h1 h1-error! h1-valid!]] + [automaton-build.os.cli-opts :as build-cli-opts] + [automaton-build.os.edn-utils :as build-edn-utils] + [automaton-build.os.filename :refer [absolutize]] + [automaton-build.tasks.impl.headers.cmds :as headers-cmds] + [clojure.set :as set] + [clojure.string :as str])) + +; ******************************************************************************** +; *** Task setup +; ******************************************************************************** + +(def ^:private cli-opts + (-> [] + (concat build-cli-opts/help-options build-cli-opts/verbose-options) + build-cli-opts/parse-cli)) + +(def verbose (get-in cli-opts [:options :verbose])) + +(def help (get-in cli-opts [:options :help])) + +; ******************************************************************************** +; *** Task code +; ******************************************************************************** + +(defn test-command + [test-runner-alias test-definitions] + (->> test-definitions + (mapv (fn [{:keys [alias]}] + {:cmd ["clojure" (str "-M:" test-runner-alias alias)] + :alias alias})))) + +(defn alias-in-deps-edn + [] + (let [{:keys [invalid? edn dir]} (build-edn-utils/read-edn "deps.edn")] + (if invalid? + (do (errorln "`deps.edn` file is invalid in dir " (absolutize dir)) (System/exit -1)) + (-> edn + :aliases + keys)))) + +(defn validate-definitions + [test-definitions alias-in-deps-edn] + (let [alias-in-deps-edn (set alias-in-deps-edn)] + (group-by (fn [{:keys [alias]}] + (if (contains? alias-in-deps-edn alias) :alias-exist :alias-doesnt-exist)) + test-definitions))) + +(defn select + "Limit test definitions to the one selected by the user" + [test-definitions selected] + (let [selected + (if (contains? (set selected) :all) (set (mapv :alias test-definitions)) (set selected))] + {:selected (set/intersection selected (set (mapv :alias test-definitions))) + :test-definitions test-definitions + :non-existing (set/difference selected (set (mapv :alias test-definitions))) + :filtered (set (filterv #(contains? selected (:alias %)) test-definitions))})) + +(defn run + "Run tests" + [test-runner-alias test-definitions] + (if help + (println + (build-cli-opts/print-usage-with-arguments cli-opts "test" "test" "[unit|development|la]")) + (let [alias-in-deps-edn (alias-in-deps-edn) + {:keys [alias-doesnt-exist alias-exist]} (validate-definitions test-definitions + alias-in-deps-edn) + arguments (mapv keyword (:arguments cli-opts)) + {:keys [non-existing selected filtered]} (select alias-exist arguments)] + (when-not (empty? alias-doesnt-exist) + (errorln "These tests are skipped as alias doesnt exist in `deps.edn`: " + (str/join "," (map :alias alias-doesnt-exist)))) + (when-not (empty? non-existing) (errorln "The following test are unkonwn: " non-existing)) + (if (empty? selected) + (do (h1-error! "Nothing to test, pick one of " (mapv :alias test-definitions) ", or all") + -1) + (do (h1 "Tested environments:" selected) + (let [exit-codes (->> (test-command test-runner-alias filtered) + (keep (fn [{:keys [cmd alias]}] + (let [{:keys [exit] + :as res} + (headers-cmds/blocking-cmd + cmd + "." + (str "Tests" alias "have failed") + verbose)] + (when (headers-cmds/success res) + (h1-valid! "Tests" alias "passed")) + exit))))] + (if (every? zero? exit-codes) + 0 + (->> exit-codes + (remove zero?) + first)))))))) diff --git a/test/bb/automaton_build/tasks/test_test.clj b/test/bb/automaton_build/tasks/test_test.clj new file mode 100644 index 0000000..de06851 --- /dev/null +++ b/test/bb/automaton_build/tasks/test_test.clj @@ -0,0 +1,57 @@ +(ns automaton-build.tasks.test-test + (:require + [automaton-build.tasks.test :as sut] + [clojure.test :refer [deftest is]])) + +(def test-definitions + #{{:description "test for la" + :alias :la} + {:description "test for unit" + :alias :unit} + {:description "dev test" + :alias :dev}}) + +(deftest test-command-test + (is (= [{:cmd ["clojure" "-M:foo:bb"] + :alias :bb} + {:cmd ["clojure" "-M:foo:a"] + :alias :a}] + (sut/test-command "foo" #{{:alias :a} {:alias :bb}})))) + +(deftest alias-in-deps-edn-test (is (sut/alias-in-deps-edn))) + +(deftest validate-definitions-test + (is (= {:alias-doesnt-exist #{{:description "test for la" + :alias :la}} + :alias-exist #{{:description "test for unit" + :alias :unit} + {:description "dev test" + :alias :dev}}} + (-> (sut/validate-definitions test-definitions #{:unit :dev}) + (update-vals set))))) + +(deftest select-test + (is (= {:selected (set (mapv :alias test-definitions)) + :test-definitions test-definitions + :non-existing #{} + :filtered test-definitions} + (sut/select test-definitions [:all])) + "All selected") + (is (= {:test-definitions test-definitions + :filtered #{{:description "test for la" + :alias :la} + {:description "test for unit" + :alias :unit}} + :non-existing #{} + :selected #{:la :unit}} + (sut/select test-definitions [:la :unit])) + "Two selected") + (is (= {:filtered #{{:description "test for la" + :alias :la} + {:description "test for unit" + :alias :unit}} + :test-definitions test-definitions + :non-existing #{"non-existing"} + :selected #{:la :unit}} + (sut/select test-definitions [:la :unit "non-existing"])) + "A non existing selected")) diff --git a/test/dev/bb/automaton_build/code/vcs_test.clj b/test/dev/bb/automaton_build/code/vcs_test.clj index 38eed42..c38fb97 100644 --- a/test/dev/bb/automaton_build/code/vcs_test.clj +++ b/test/dev/bb/automaton_build/code/vcs_test.clj @@ -19,8 +19,7 @@ (is (= ["" 0 false] ((juxt :err :exit (comp str/blank? :out)) (-> (sut/latest-commit-message-cmd) - (blocking-cmd "." "Unexpected error during commit message test" false) - (dissoc :dir)))) + (blocking-cmd "." "Unexpected error during commit message test" false)))) "Is the log message return no error, a zero exit code and a message.")) (deftest latest-commit-sha-cmd-test @@ -130,3 +129,62 @@ (select-keys [:is-commit :nothing-to-commit]) vals)) "A modification is detected and the nothing-to-commit is false."))) + +(deftest current-repo-url-test + (is (zero? (-> (sut/current-repo-url-cmd) + (blocking-cmd "" "test current repo url failed" true) + :exit)) + "Is the execution ok?") + (is + (= + "git@github.com:hephaistox/automaton-build.git" + (-> + {:exit 0 + :out + "origin git@github.com:hephaistox/automaton-build.git (fetch) +origin git@github.com:hephaistox/automaton-build.git (push)"} + sut/current-repo-url-analyze)) + "Is the analyzis finding finding the url?")) + +(comment + (-> (sut/current-tag-cmd) + (blocking-cmd "." "Unexpected error during commit message test" false) + sut/current-tag-analyze)) + +(deftest gh-run-wip?-test + (comment + (-> (sut/gh-run-wip?-cmd) + (blocking-cmd "" "Unable to execute `gh` run wip" false) + #_sut/gh-run-wip?-analyze) + "completed\tfailure\tClean build\tCommit validation - Delaguardo flavor\tclean_build\tpush\t12622334211\t36s\t2025-01-05T19:25:35Z" + "completed\tsuccess\tClean build\tCommit validation - Delaguardo flavor\tclean_build\tpush\t12622284876\t1m43s\t2025-01-05T19:17:40Z") + (is + (= + {:status :run-failed + :run-id "12622334211"} + (-> + {:exit 0 + :out + "completed\tfailure\tClean build\tCommit validation - Delaguardo flavor\tclean_build\tpush\t12622334211\t36s\t2025-01-05T19:25:35Z"} + sut/gh-run-wip?-analyze)) + "A failure") + (is + (= + {:status :run-ok + :run-id "12622284876"} + (-> + {:exit 0 + :out + "completed\tsuccess\tClean build\tCommit validation - Delaguardo flavor\tclean_build\tpush\t12622284876\t1m43s\t2025-01-05T19:17:40Z"} + sut/gh-run-wip?-analyze)) + "A success") + (is + (= + {:run-id "12622284876" + :status :wip} + (-> + {:exit 0 + :out + "aze\twip\tClean build\tCommit validation - Delaguardo flavor\tclean_build\tpush\t12622284876\t1m43s\t2025-01-05T19:17:40Z"} + sut/gh-run-wip?-analyze)) + "A wip")) diff --git a/test/dev/bb/automaton_build/doc/mermaid_test.clj b/test/dev/bb/automaton_build/doc/mermaid_test.clj deleted file mode 100644 index 48c0db6..0000000 --- a/test/dev/bb/automaton_build/doc/mermaid_test.clj +++ /dev/null @@ -1,24 +0,0 @@ -(ns automaton-build.doc.mermaid-test - (:require - [automaton-build.doc.mermaid :as sut] - [automaton-build.os.file :as build-file] - [automaton-build.os.filename :as build-filename] - [automaton-build.os.user :as build-user] - [automaton-build.tasks.impl.headers.cmds :refer [blocking-cmd]] - [clojure.test :refer [deftest is]])) - -(def filename (build-filename/create-file-path (build-file/create-temp-dir) "foo.mermaid")) -(deftest mermaid-build-image-cmd-test - (let [filename (build-filename/create-file-path (build-file/create-temp-dir) "foo.mermaid") - _ (build-file/write-file filename "erDiagram\ne ||--|| f: z") - {:keys [output-file cmd]} (sut/mermaid-build-image-cmd filename - (-> (build-user/user-id-cmd) - (blocking-cmd "" "" false) - build-user/id-analyze) - (-> (build-user/group-id-cmd) - (blocking-cmd "" "" false) - build-user/id-analyze) - (build-file/create-temp-dir - "out-data"))] - (blocking-cmd cmd "." nil false) - (is (build-file/is-existing-file? output-file) "Is the file generated?"))) diff --git a/test/la/bb/.keep b/test/la/bb/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/unit/bb/automaton_build/code/files_test.clj b/test/unit/bb/automaton_build/code/files_test.clj index 6915bad..a7428ae 100644 --- a/test/unit/bb/automaton_build/code/files_test.clj +++ b/test/unit/bb/automaton_build/code/files_test.clj @@ -5,14 +5,15 @@ [clojure.test :refer [deftest is]])) (deftest project-dirs-test - (is (empty? (sut/project-dirs "" {})) "If no path is provided, not dir is.") - (is (= #{"env/test/src/"} - (sut/project-dirs "" {:paths ["non-existing-dir" "env/test/src" "env/non-exist/src"]})) - "Values in `:paths` are returned") - (is (= #{"env/test/src/"} + (is (empty? (sut/project-dirs "" {})) "If paths is empty, no dir is returned.") + (is (= #{"test/bb/"} (sut/project-dirs "" {:paths ["test/bb"]})) "Existing path is kept") + (is (= #{"test/bb/"} + (sut/project-dirs "" {:paths ["non-existing-dir" "test/bb" "env/non-exist/src"]})) + "Non existing dirs are skipped") + (is (= #{"test/bb/"} (sut/project-dirs "" - {:paths ["env/test/src"] - :aliases {:foo {:extra-paths ["env/test/src"]}}})) + {:paths ["test/bb"] + :aliases {:foo {:extra-paths ["test/bb"]}}})) "If the same path is at many places, it is returned only once.") (is (seq (apply sut/project-dirs ((juxt :dir :edn) (build-edn/read-edn "deps.edn")))) "A project in a sub directory manages properly the paths.")) diff --git a/version.edn b/version.edn deleted file mode 100644 index 959061b..0000000 --- a/version.edn +++ /dev/null @@ -1 +0,0 @@ -{:version "3.3.0"} \ No newline at end of file