Skip to content

Commit

Permalink
task sequence fix
Browse files Browse the repository at this point in the history
  • Loading branch information
caumond committed Nov 9, 2023
1 parent 9b419a0 commit d0485f0
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 32 additions & 4 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -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 {})
Expand All @@ -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
Expand All @@ -25,25 +27,36 @@
: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"
:task (execute-build-app-task (quote automaton-build-app.tasks.gha-lconnect/gha-lconnect))}
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 "
Expand All @@ -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))}}}
: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))}}}
7 changes: 4 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -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"}}
Expand Down Expand Up @@ -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"]}
4 changes: 2 additions & 2 deletions docs/code/deps-ns.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/code/stats.md
Original file line number Diff line number Diff line change
@@ -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
* clj-test-nb-lines - 1906
* clj-total-nb-lines - 6064
* ratio-in-pct - 45.83
2 changes: 1 addition & 1 deletion src/clj/automaton_core/adapters/deps_edn.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
46 changes: 9 additions & 37 deletions src/clj/automaton_core/adapters/edn_utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)))
11 changes: 0 additions & 11 deletions src/clj/automaton_core/adapters/files.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/clj/automaton_core/adapters/version.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")))
23 changes: 10 additions & 13 deletions src/clj/automaton_core/os/code_formatter.clj
Original file line number Diff line number Diff line change
@@ -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)))
2 changes: 1 addition & 1 deletion test/clj/automaton_core/adapters/build_config_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))))
24 changes: 9 additions & 15 deletions test/clj/automaton_core/adapters/edn_utils_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions version.edn
Original file line number Diff line number Diff line change
@@ -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"}
:minor-version 5
:version "0.0.5"}

0 comments on commit d0485f0

Please sign in to comment.