From d0485f008055cfff09ebbba0299ec2447c3e4434 Mon Sep 17 00:00:00 2001 From: caumond Date: Thu, 9 Nov 2023 14:16:53 +0100 Subject: [PATCH] task sequence fix --- .github/workflows/commit_validation.yml | 2 +- bb.edn | 36 +++++++++++++-- deps.edn | 7 +-- docs/code/deps-ns.svg | 4 +- docs/code/stats.md | 6 +-- src/clj/automaton_core/adapters/deps_edn.clj | 2 +- src/clj/automaton_core/adapters/edn_utils.clj | 46 ++++--------------- src/clj/automaton_core/adapters/files.clj | 11 ----- src/clj/automaton_core/adapters/version.clj | 2 +- src/clj/automaton_core/os/code_formatter.clj | 23 ++++------ .../adapters/build_config_test.clj | 2 +- .../adapters/edn_utils_test.clj | 24 ++++------ version.edn | 6 +-- 13 files changed, 76 insertions(+), 95 deletions(-) diff --git a/.github/workflows/commit_validation.yml b/.github/workflows/commit_validation.yml index 8c3c23c1..a62bcbe2 100644 --- a/.github/workflows/commit_validation.yml +++ b/.github/workflows/commit_validation.yml @@ -12,4 +12,4 @@ jobs: # this is to fix GIT not liking owner of the checkout dir, See https://github.com/actions/runner/issues/2033 chown -R $(id -u):$(id -g) $PWD - name: Base image - uses: docker://hephaistox/gha-automaton-core:v1.0.0 + uses: docker://hephaistox/gha-automaton-core:v0.0.1 diff --git a/bb.edn b/bb.edn index 223f909a..7f59e1ef 100644 --- a/bb.edn +++ b/bb.edn @@ -1,5 +1,5 @@ {:deps {hephaistox/automaton-build-app {:git/url "https://github.com/hephaistox/automaton-build-app.git" - :sha "db42465833ea1c5c40339fddafefcea461dc21c5"}} + :sha "ad0a5b0e90d45080386460206ca6090281db1a50"}} :paths [] :tasks {:enter (do (def cust-app-task-registy {}) @@ -11,6 +11,8 @@ task-fn argv))) :requires [[babashka.process :as babahska-process] [automaton-build-app.tasks.launcher.bb-entrypoint :as build-task-bb-entrypoint]] + blog {:doc "Generate the blog files" + :task (execute-build-app-task (quote automaton-build-app.tasks.blog/blog))} clean {:doc "Clean cache files for compiles, and logs" :task (execute-build-app-task (quote automaton-build-app.tasks.clean/clean))} clean-hard @@ -25,10 +27,13 @@ :task (execute-build-app-task (quote automaton-build-app.tasks.container-clear/container-clear))} container-list {:doc "List all available containers" :task (execute-build-app-task (quote automaton-build-app.tasks.container-list/container-list))} + docstring {:doc "Generate the documentation based on docstring" + :task (execute-build-app-task (quote automaton-build-app.tasks.docstring/doc-string))} format {:doc "Format the whole documentation" :task (execute-build-app-task (quote automaton-build-app.tasks.format-files/format-files))} - gha {:doc "Github action command - launched is automatically by github" - :task (execute-build-app-task (quote automaton-build-app.tasks.gha/gha))} + gha {:doc "Github action tests - launched is automatically by github" + :task + (execute-build-app-task (quote automaton-build-app.tasks.workflow.composer/composer) (quote is-cicd) (quote lint) (quote lbe-test))} gha-container-publish {:doc "Update the gha container to run that app" :task (execute-build-app-task (quote automaton-build-app.tasks.gha-container-publish/gha-container-publish))} gha-lconnect {:doc "Connect to a local container running this code" @@ -36,14 +41,22 @@ ide {:doc "Quick tests to use during IDE usage" :task (execute-build-app-task (quote automaton-build-app.tasks.workflow.composer/composer) (quote report) (quote format) (quote lint))} + is-cicd {:doc "Is runned on cicd" + :task (execute-build-app-task (quote automaton-build-app.tasks.is-cicd/is-cicd))} la {:doc "Local acceptance test" :task (execute-build-app-task (quote automaton-build-app.tasks.la/la))} + lbe-test {:doc "Local Backend test" + :task (execute-build-app-task (quote automaton-build-app.tasks.lbe-test/lbe-test))} lconnect {:doc "Local connect - repl" :task (execute-build-app-task (quote automaton-build-app.tasks.lconnect/lconnect))} + lfe-test {:doc "Local frontend test" + :task (execute-build-app-task (quote automaton-build-app.tasks.lfe-test/lfe-test))} lint {:doc "linter" :task (execute-build-app-task (quote automaton-build-app.tasks.lint/lint))} ltest {:doc "Local test" :task (execute-build-app-task (quote automaton-build-app.tasks.ltest/ltest))} + mermaid {:doc "Build all mermaid files" + :task (execute-build-app-task (quote automaton-build-app.tasks.mermaid/mermaid))} push {:doc "Push this repo" :task (execute-build-app-task (quote automaton-build-app.tasks.push/push) {:executing-pf :clj})} push-local-dir-to-repo {:doc "Push this repo " @@ -52,5 +65,20 @@ :task (execute-build-app-task (quote automaton-build-app.tasks.reports/reports))} update-deps {:doc "Update the dependencies, cider-nrepl and refactor are to be updated manually" :task (execute-build-app-task (quote automaton-build-app.tasks.update-deps/update-deps))} + vizualise-deps {:doc "Vizualise the dependencies in a graph" + :task (execute-build-app-task (quote automaton-build-app.tasks.vizualise-deps/vizualise-deps))} + vizualise-ns {:doc "Vizualise the namespace in graph" + :task (execute-build-app-task (quote automaton-build-app.tasks.vizualise-ns/vizualise-ns))} wf-6 {:doc "Push the local version - create gha docker image - push to the repo" - :task (execute-build-app-task (quote automaton-build-app.tasks.workflow.composer/composer) (quote clean) (quote clean))}}} \ No newline at end of file + :task (execute-build-app-task (quote automaton-build-app.tasks.workflow.composer/composer) + (quote clean) + (quote lint) + (quote lbe-test) + (quote lfe-test) + (quote report) + (quote blog) + (quote mermaid) + (quote vizualise-ns) + (quote format) + (quote gha-container-publish) + (quote push-local-dir-to-repo))}}} \ No newline at end of file diff --git a/deps.edn b/deps.edn index 7a62569f..4035bb40 100644 --- a/deps.edn +++ b/deps.edn @@ -1,7 +1,7 @@ {:aliases {:bb-deps {:extra-deps {hephaistox/automaton-build-app {:git/url "https://github.com/hephaistox/automaton-build-app.git" - :sha "db42465833ea1c5c40339fddafefcea461dc21c5"}}} + :sha "ad0a5b0e90d45080386460206ca6090281db1a50"}}} :build {:extra-deps {hephaistox/automaton-build-app {:git/url "https://github.com/hephaistox/automaton-build-app.git" - :sha "db42465833ea1c5c40339fddafefcea461dc21c5"}}} + :sha "ad0a5b0e90d45080386460206ca6090281db1a50"}}} :cljs-deps {:extra-deps {binaryage/devtools {:mvn/version "1.0.7"} cider/cider-nrepl {:mvn/version "0.21.1"} thheller/shadow-cljs {:mvn/version "2.25.9"}} @@ -40,5 +40,6 @@ org.clojure/clojure #:mvn{:version "1.11.1"} org.clojure/tools.cli #:mvn{:version "1.0.219"} org.clojure/tools.logging #:mvn{:version "1.2.4"} - refactor-nrepl/refactor-nrepl #:mvn{:version "3.6.0"}} + refactor-nrepl/refactor-nrepl #:mvn{:version "3.6.0"} + zprint/zprint {:mvn/version "1.2.8"}} :paths ["src/clj" "src/cljc" "resources" "src/cljs"]} diff --git a/docs/code/deps-ns.svg b/docs/code/deps-ns.svg index f7502c20..d157fa8e 100644 --- a/docs/code/deps-ns.svg +++ b/docs/code/deps-ns.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:77b8269ec5a1d0fe182e2cc7d4f10ddc00c7e6670d50729292538a1c2f00785e -size 32622 +oid sha256:4e99f468019a04e7c8552208f4db51e1151b7be8f5aa1d5b68b1cae1539b183c +size 33580 diff --git a/docs/code/stats.md b/docs/code/stats.md index abcd35f6..79826e5b 100644 --- a/docs/code/stats.md +++ b/docs/code/stats.md @@ -1,4 +1,4 @@ # That statistics counts number of line of code -* clj-test-nb-lines - 1914 -* clj-total-nb-lines - 6151 -* ratio-in-pct - 45.17 \ No newline at end of file +* clj-test-nb-lines - 1906 +* clj-total-nb-lines - 6064 +* ratio-in-pct - 45.83 \ No newline at end of file diff --git a/src/clj/automaton_core/adapters/deps_edn.clj b/src/clj/automaton_core/adapters/deps_edn.clj index 6e6f4d17..bf728308 100644 --- a/src/clj/automaton_core/adapters/deps_edn.clj +++ b/src/clj/automaton_core/adapters/deps_edn.clj @@ -21,7 +21,7 @@ * `app-dir` the directory of the app, where `deps.edn` is stored Returns nil if the file does not exists or is malformed" [app-dir] - (edn-utils/read-edn-or-nil (get-deps-filename app-dir))) + (edn-utils/read-edn (get-deps-filename app-dir))) (defn update-commit-id "Update the `deps-edn` with the `commit-id` for the dependency `as-lib` diff --git a/src/clj/automaton_core/adapters/edn_utils.clj b/src/clj/automaton_core/adapters/edn_utils.clj index 6f2117ad..90b97b3a 100644 --- a/src/clj/automaton_core/adapters/edn_utils.clj +++ b/src/clj/automaton_core/adapters/edn_utils.clj @@ -27,25 +27,10 @@ (let [edn-filename (files/absolutize edn-filename) _ (log/trace "Load file:" edn-filename) edn-content (try (loader-fn edn-filename) - (catch Exception e - (throw (ex-info (format "Unable to load the file `%s`" edn-filename) - {:caused-by e - :file-name edn-filename}))))] - (try (edn/read-string edn-content) - (catch Exception e - (throw (ex-info (format "File `%s` is not an edn" edn-filename) - {:caused-by e - :file-name edn-filename})))))) + (catch Exception e (log/warn-exception e (format "Unable to load the file `%s`" edn-filename))))] + (try (edn/read-string edn-content) (catch Exception e (log/warn-exception e (format "File `%s` is not an edn" edn-filename)) nil)))) ([edn-filename] (read-edn edn-filename files/read-file))) -(defn read-edn-or-nil - "Read the `.edn` file, - * return nil if the file does not exist or is invalid - * `file` could be a string representing the name of the file to load - or a (io/resource) object representing the name of the file to load" - ([edn-file-name loader-fn] (try (read-edn edn-file-name loader-fn) (catch Exception _ nil))) - ([edn-file-name] (read-edn-or-nil edn-file-name slurp))) - (defn spit-edn "Spit the `content` in the edn file called `deps-edn-filename`. If any, the header is added at the top of the file @@ -56,14 +41,15 @@ Return the content of the file" ([edn-filename content header] (try (log/trace "Spit edn file:" edn-filename) - (files/spit-file edn-filename content) - (code-formatter/format-file edn-filename header) + (->> content + (code-formatter/format-content header) + (files/spit-file edn-filename)) content (catch Exception e - (throw (ex-info "Impossible to update the .edn file" - {:deps-edn-filename edn-filename - :exception e - :content content}))))) + (log/warn-exception (ex-info "Impossible to update the .edn file" + {:deps-edn-filename edn-filename + :content content + :caused-by e}))))) ([deps-edn-filename content] (spit-edn deps-edn-filename content nil))) (defn update-edn-content @@ -89,17 +75,3 @@ (let [edn-file (files/create-file-path (conf/read-param [:log :spitted-edns]) (str (uuid/time-based-uuid) ".edn"))] (files/create-dirs (files/extract-path edn-file)) edn-file)) - -(defn spit-in-tmp-file - "Spit the data given as a parameter to a temporary file which adress is given - This function has a trick to print exception and its stacktrace - Params: - * `data` the data to spit - * `formatting?` (Optional, default = true) is the content formatted" - ([data formatting?] - (let [filename (create-tmp-edn)] - (files/spit-file filename data) - ;; Important to print exception properly - (when formatting? (code-formatter/format-file filename)) - (format " See file `%s` for details" (files/absolutize filename)))) - ([data] (spit-in-tmp-file data true))) diff --git a/src/clj/automaton_core/adapters/files.clj b/src/clj/automaton_core/adapters/files.clj index cdeda144..db2eaf79 100644 --- a/src/clj/automaton_core/adapters/files.clj +++ b/src/clj/automaton_core/adapters/files.clj @@ -316,17 +316,6 @@ fs/path (str ".edn"))) -(defn spit-in-tmp-file - "Spit the data given as a parameter to a temporary file which adress is given - This function has a trick to print exception and its stacktrace" - [data] - (let [filename (create-tmp-edn) - formatted-data (with-out-str (prn data)) ;; Important to print - ;; exception properly - ] - (spit filename formatted-data) - (format "See file `%s` for details" (absolutize filename)))) - (defn file-name "Return the file name without the path" [path] (fs/file-name path)) (defn write-file diff --git a/src/clj/automaton_core/adapters/version.clj b/src/clj/automaton_core/adapters/version.clj index 07d77e0d..9dccb95f 100644 --- a/src/clj/automaton_core/adapters/version.clj +++ b/src/clj/automaton_core/adapters/version.clj @@ -11,6 +11,6 @@ "Get the version of the current application, if not found a local dev value is given" ([file-path] (if (files/is-existing-file? (str file-path version-filename)) - (edn-utils/read-edn-or-nil (str file-path version-filename)) + (edn-utils/read-edn (str file-path version-filename)) {release "local-dev"})) ([] (slurp-version ""))) diff --git a/src/clj/automaton_core/os/code_formatter.clj b/src/clj/automaton_core/os/code_formatter.clj index 8d016249..1031f07d 100644 --- a/src/clj/automaton_core/os/code_formatter.clj +++ b/src/clj/automaton_core/os/code_formatter.clj @@ -1,21 +1,18 @@ (ns automaton-core.os.code-formatter "Format code Proxy to [zprint](https://github.com/kkinnear/zprint)" - (:require [automaton-core.adapters.files :as files] - [automaton-core.adapters.commands :as cmds] + (:require [zprint.core :as zprint] [automaton-core.adapters.time :as time] [clojure.string :as str])) -(defn format-file +(defn format-content "Format the `clj` or `edn` file + Returns a string, ready to be spitted, with the header Params: - * `filename` to format - * `header` (optional) is written at the top of the file" - ([filename header] - (let [format-content (slurp filename)] - (files/spit-file filename (apply str [(when-not (str/blank? header) (print-str ";;" header (time/now-str) "\n")) format-content])) - (cmds/exec-cmds [[["zprint" "-w" filename] - {:dir "." - :out :string}]]))) - ([filename] (format-file filename nil))) - + * `header` (optional) is written at the top of the file + * `content` is a data structure to format" + ([header content] + (let [format-content (-> content + zprint/zprint-str)] + (apply str [(when-not (str/blank? header) (print-str ";;" header (time/now-str) "\n")) format-content]))) + ([content] (format-content nil content))) diff --git a/test/clj/automaton_core/adapters/build_config_test.clj b/test/clj/automaton_core/adapters/build_config_test.clj index 9e72afcb..0d2fc907 100644 --- a/test/clj/automaton_core/adapters/build_config_test.clj +++ b/test/clj/automaton_core/adapters/build_config_test.clj @@ -11,4 +11,4 @@ (let [tmp-dir (files/create-temp-dir) content {:foo3 :bar3}] (sut/spit-build-config tmp-dir content ";; Hey!") - (is (= content (edn-utils/read-edn-or-nil (files/create-file-path tmp-dir sut/build-config-filename))))))) + (is (= content (edn-utils/read-edn (files/create-file-path tmp-dir sut/build-config-filename))))))) diff --git a/test/clj/automaton_core/adapters/edn_utils_test.clj b/test/clj/automaton_core/adapters/edn_utils_test.clj index e0485c7d..41aa61f9 100644 --- a/test/clj/automaton_core/adapters/edn_utils_test.clj +++ b/test/clj/automaton_core/adapters/edn_utils_test.clj @@ -16,28 +16,22 @@ (is (not (sut/is-clojure-like-file nil))))) (deftest read-edn-test - (testing "Malformed files are detected " - (is (thrown-with-msg? clojure.lang.ExceptionInfo #"File.*is not an edn" (sut/read-edn "non-used-file-name" (fn [_] "1.1.1 (+ 1 1)"))))) - (testing "Non existing files are detected " - (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Unable to load the file" (sut/read-edn "not existing file")))) - (testing "Non existing files throw an exception" - (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Unable to load the file" (sut/read-edn "non existing file" slurp)))) - (testing "Non existing files throw an exception" (is (= "test1-content" (sut/read-edn (io/resource "resource-test-copy-dir/test1")))))) + (testing "Malformed files are detected " (is (nil? (sut/read-edn "non-used-file-name" (fn [_] "1.1.1 (+ 1 1)"))))) + (testing "Non existing files are detected " (is (nil? (sut/read-edn "not existing file")))) + (testing "Non existing files are skipped" (is (nil? (sut/read-edn "non existing file" slurp)))) + (testing "Resource file found" (is (= "test1-content" (sut/read-edn (io/resource "resource-test-copy-dir/test1")))))) -(deftest read-edn-or-nil-test - (testing "Skip non existing files and return nil" (is (nil? (sut/read-edn-or-nil "non existing file" slurp))))) +(deftest read-edn-or-nil-test (testing "Skip non existing files and return nil" (is (nil? (sut/read-edn "non existing file" slurp))))) -(def tmp-file - ;; => "../tmp/edns/6bfcd070-3c43-11ee-aece-d9f945498185.edn" - (sut/create-tmp-edn)) +(def tmp-file (sut/create-tmp-edn)) (deftest spit-edn-test (testing "Creates edn file" (let [tmp-file (sut/create-tmp-edn)] (sut/spit-edn tmp-file {10 20}) - (is (= {10 20} (sut/read-edn-or-nil tmp-file))) - (sut/spit-edn tmp-file "{15 25}") - (is (= {15 25} (sut/read-edn-or-nil tmp-file))) + (is (= {10 20} (sut/read-edn tmp-file))) + (sut/spit-edn tmp-file {15 25}) + (is (= {15 25} (sut/read-edn tmp-file))) (sut/spit-edn tmp-file {5 5} "Header")))) (deftest update-edn-content-test diff --git a/version.edn b/version.edn index 45fdcaf0..5a23b679 100644 --- a/version.edn +++ b/version.edn @@ -1,4 +1,4 @@ -;; Last generated version, note a failed push consume a number Wed Nov 8 13:00:30 CET 2023 +;; Last generated version, note a failed push consume a number Thu Nov 9 14:16:52 CET 2023 {:major-version "0.0.-1" - :minor-version 3 - :version "0.0.3"} \ No newline at end of file + :minor-version 5 + :version "0.0.5"} \ No newline at end of file