diff --git a/.github/workflows/commit_validation.yml b/.github/workflows/commit_validation.yml index 91090b0..2b50215 100644 --- a/.github/workflows/commit_validation.yml +++ b/.github/workflows/commit_validation.yml @@ -27,12 +27,12 @@ jobs: check-latest: true - name: Install clojure tools # See https://github.com/DeLaGuardo/setup-clojure/commits/main/ - uses: DeLaGuardo/setup-clojure@ada62bb3282a01a296659d48378b812b8e097360 #v13.2 + uses: DeLaGuardo/setup-clojure@3fe9b3ae632c6758d0b7757b0838606ef4287b08 #v13.2 with: - cli: 1.12.0.1530 - bb: 1.12.197 - clj-kondo: 2025.02.20 - zprint: 1.2.9 + cli: 1.12.1.1550 + bb: 1.12.207 + clj-kondo: 2025.07.28 + zprint: 1.3.0 - name: Lint run: bb lint -v - name: Setup zprint @@ -51,7 +51,7 @@ jobs: run: git diff - name: Pushed code should already be formatted # See https://github.com/CatChen/check-git-status-action - uses: CatChen/check-git-status-action@fb60fe626b56d5a4adcb227327ba4d24326a873a #v1.4.4 + uses: CatChen/check-git-status-action@7ff019ee29f2307dca95397ae225037aa88eb4c7 #v1.4.4 with: fail-if-not-clean: true request-changes-if-not-clean: false diff --git a/deps.edn b/deps.edn index fdf1873..7afa0ca 100644 --- a/deps.edn +++ b/deps.edn @@ -14,9 +14,9 @@ :source-uri "https://github.com/hephaistox/auto-build/blob/{version}/{filepath}#L{line}"} :exec-fn codox.main/generate-docs :extra-deps {codox/codox {:mvn/version "0.10.8"}}} - :for-clj-repl {:doc "Dependencies necessary to use" - :extra-deps {babashka/fs {:mvn/version "0.5.24"} - babashka/process {:mvn/version "0.5.22"}}} + :for-clj-repl {:doc "Dependencies necessary to use bb in clojure" + :extra-deps {babashka/fs {:mvn/version "0.5.26"} + babashka/process {:mvn/version "0.6.23"}}} :test-bb {:extra-paths ["test/src" "test/resources"] :main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/src"]} :test-unit {:extra-paths ["env/unit/test/" "env/unit/resources"] diff --git a/src/auto_build/tasks/frontend.clj b/src/auto_build/tasks/frontend.clj index 7ba7bab..5b9c85c 100644 --- a/src/auto_build/tasks/frontend.clj +++ b/src/auto_build/tasks/frontend.clj @@ -28,70 +28,70 @@ [printers app-dir app-alias target-dir repo-url] (let [shadow-cljs (build-shadow/read printers app-dir) shadow-output-dir (get-in shadow-cljs [:edn :builds (keyword app-alias) :output-dir])] - (-> {:status :success} - (execute-if-success printers - app-dir - verbose - ["rm" "-fr" target-dir] - "Delete previous build" - "Error when deleting previous build" - :build-installation) - (execute-if-success printers - app-dir - verbose - ["rm" "-fr" shadow-output-dir] - "Delete previous js build" - "Error when deleting previous js build" - :cljs-release-clean) - (execute-if-success printers - app-dir - verbose - ["npm" "install"] - "Install npm packages" - "Error during npm packages installation" - :npm-installation) - (execute-if-success printers - app-dir - verbose - ["npx" "shadow-cljs" "release" app-alias] - "Create a cljs release" - "Error during creation of a cljs release" - :cljs-release) - (execute-if-success printers - app-dir - verbose - ["clojure" "-T:uberjar" ":target-dir" target-dir] - "Build the uberjar" - "Error during uberjar creation" - :uberjar) - (execute-if-success printers - target-dir - verbose - ["git" "init" "-b" "master"] - "Creates a repo" - "Error during repo creation" - :create-repo) - (execute-if-success printers - target-dir - verbose - ["git" "remote" "add" "clever" repo-url] - "Add clever remotes" - "Error when adding clever remotes" - :add-remote) - (execute-if-success printers - target-dir - verbose - ["git" "add" "."] - "Add jar to index" - "Error when adding jar to index" - :add-jar-to-index) - (execute-if-success printers - target-dir - verbose - ["git" "commit" "-m" "\"auto\""] - "Commit" - "Error during commit creation" - :commit)))) + (cond-> {:status :success} + true (execute-if-success printers + app-dir + verbose + ["rm" "-fr" target-dir] + "Delete previous build" + "Error when deleting previous build" + :build-installation) + true (execute-if-success printers + app-dir + verbose + ["rm" "-fr" shadow-output-dir] + "Delete previous js build" + "Error when deleting previous js build" + :cljs-release-clean) + true (execute-if-success printers + app-dir + verbose + ["npm" "install"] + "Install npm packages" + "Error during npm packages installation" + :npm-installation) + app-alias (execute-if-success printers + app-dir + verbose + ["npx" "shadow-cljs" "release" app-alias] + "Create a cljs release" + "Error during creation of a cljs release" + :cljs-release) + true (execute-if-success printers + app-dir + verbose + ["clojure" "-T:uberjar" ":target-dir" target-dir] + "Build the uberjar" + "Error during uberjar creation" + :uberjar) + true (execute-if-success printers + target-dir + verbose + ["git" "init" "-b" "master"] + "Creates a repo" + "Error during repo creation" + :create-repo) + true (execute-if-success printers + target-dir + verbose + ["git" "remote" "add" "clever" repo-url] + "Add clever remotes" + "Error when adding clever remotes" + :add-remote) + true (execute-if-success printers + target-dir + verbose + ["git" "add" "."] + "Add jar to index" + "Error when adding jar to index" + :add-jar-to-index) + true (execute-if-success printers + target-dir + verbose + ["git" "commit" "-m" "\"auto\""] + "Commit" + "Error during commit creation" + :commit)))) ;; ******************************************************************************** ;; *** Task diff --git a/src/auto_build/tasks/repl_fe.clj b/src/auto_build/tasks/repl_fe.clj new file mode 100644 index 0000000..f5c65a3 --- /dev/null +++ b/src/auto_build/tasks/repl_fe.clj @@ -0,0 +1,41 @@ +(ns auto-build.tasks.repl-fe + (:require + [auto-build.os.cli-opts :as build-cli-opts] + [babashka.process :as p])) + +;; ******************************************************************************** +;; *** Task setup +;; ******************************************************************************** + +(def cli-opts + (-> [] + (concat build-cli-opts/help-options build-cli-opts/verbose-options) + build-cli-opts/parse-cli-args)) + +(def verbose (get-in cli-opts [:options :verbose])) + +;; ******************************************************************************** +;; *** Task code +;; ******************************************************************************** + +(defn repl-fe* + [app-dir repl-aliases] + (let [cmd (concat ["npx" "shadow-cljs" "watch"] repl-aliases)] + (println "Execute" cmd) + (-> (apply p/shell + {:continue true + :dir app-dir} + cmd) + :exit))) + +(defn repl-fe + [{:keys [title] + :as _printers} + app-dir + current-task + repl-aliases] + (if-let [exit-code (build-cli-opts/enter cli-opts current-task)] + exit-code + (let [title-msg (str "Start clj repl - alias " repl-aliases)] + (title title-msg) + (repl-fe* app-dir repl-aliases)))) diff --git a/src/auto_build/tasks/web/css.clj b/src/auto_build/tasks/web/css.clj new file mode 100644 index 0000000..22ce2ae --- /dev/null +++ b/src/auto_build/tasks/web/css.clj @@ -0,0 +1,48 @@ +(ns auto-build.tasks.web.css + (:require + [auto-build.os.cli-opts :as build-cli-opts] + [auto-build.os.cmd :as build-cmd + :refer [printing]])) + +;; ******************************************************************************** +;; *** Task setup +;; ******************************************************************************** + +(def cli-opts + (-> (concat build-cli-opts/help-options build-cli-opts/verbose-options) + build-cli-opts/parse-cli-args)) + +(def verbose (get-in cli-opts [:options :verbose])) + +;; ******************************************************************************** +;; *** Task code +;; ******************************************************************************** + +(defn css-repl-watch* + "Generate cljs repl" + [{:keys [normalln errorln]} app-dir css-file target-dir] + (normalln "Build frontend in production mode") + (let [cmd ["npx" "@tailwindcss/cli" "-i" css-file "-o" target-dir "--watch"]] + (when verbose + (-> cmd + build-cmd/to-str + print)) + (printing cmd app-dir normalln errorln 100))) + +(defn css-repl-watch + "Build the css file in dev mode, and deploy remotely + + `uberjar-aliases` is a string of keywords that should be assembled to build the jar (called with -T) + `app-name` if the name as found in `shadow-cljs.edn`" + [{:keys [title _errorln] + :as printers} + app-dir + current-task + css-file + target-dir] + (if-let [exit-code (build-cli-opts/enter cli-opts current-task)] + exit-code + (let [title-msg "Starts web dev repl"] + (title title-msg) + (-> (css-repl-watch* printers app-dir css-file target-dir) + (build-cmd/status-to-exit-code printers title-msg))))) diff --git a/src/auto_build/tasks/web/dev_repl.clj b/src/auto_build/tasks/web/dev_repl.clj new file mode 100644 index 0000000..5f25a3b --- /dev/null +++ b/src/auto_build/tasks/web/dev_repl.clj @@ -0,0 +1,42 @@ +(ns auto-build.tasks.web.dev-repl + (:require + [auto-build.os.cli-opts :as build-cli-opts] + [auto-build.os.cmd :as build-cmd + :refer [printing]])) + +;; ******************************************************************************** +;; *** Task setup +;; ******************************************************************************** + +(def cli-opts + (-> (concat build-cli-opts/help-options build-cli-opts/verbose-options) + build-cli-opts/parse-cli-args)) + +(def verbose (get-in cli-opts [:options :verbose])) + +;; ******************************************************************************** +;; *** Task code +;; ******************************************************************************** + +(defn cljs-repl-watch* + "Generate cljs repl" + [{:keys [uri-str normalln errorln]} app-dir app-name] + (normalln "Build " (uri-str app-name) " frontend in production mode") + (printing ["npx" "shadow-cljs" "watch" app-name] app-dir normalln errorln 100)) + +(defn cljs-repl-watch + "Build the project in production mode, and deploy remotely + + `uberjar-aliases` is a string of keywords that should be assembled to build the jar (called with -T) + `app-name` if the name as found in `shadow-cljs.edn`" + [{:keys [title _errorln] + :as printers} + app-dir + current-task + app-name] + (if-let [exit-code (build-cli-opts/enter cli-opts current-task)] + exit-code + (let [title-msg "Starts web dev repl"] + (title title-msg) + (-> (cljs-repl-watch* printers app-dir app-name) + (build-cmd/status-to-exit-code printers title-msg))))) diff --git a/src/auto_build/tasks/web/prod_build.clj b/src/auto_build/tasks/web/prod_build.clj new file mode 100644 index 0000000..647ac05 --- /dev/null +++ b/src/auto_build/tasks/web/prod_build.clj @@ -0,0 +1,143 @@ +(ns auto-build.tasks.web.prod-build + "Move the web app to production" + (:require + [auto-build.os.cli-opts :as build-cli-opts] + [auto-build.os.cmd :as build-cmd + :refer [execute-if-success execute-whateverstatus]])) + +;; ******************************************************************************** +;; *** Task setup +;; ******************************************************************************** + +(def cli-opts + (-> (concat build-cli-opts/help-options build-cli-opts/verbose-options) + build-cli-opts/parse-cli-args)) + +(def verbose (get-in cli-opts [:options :verbose])) + +;; ******************************************************************************** +;; *** Task code +;; ******************************************************************************** + +(defn build* + "Generate jar" + [{:keys [uri-str] + :as printers} + app-dir + uberjar-aliases + fe-app-names + repo-url + target-dir] + (cond-> {:status :success} + true (execute-if-success printers + app-dir + verbose + ["rm" "-fr" "resources/public/js/compiled" "target"] + "Clean previous frontend build" + "Error during target directory cleaning" + :clean-dir) + fe-app-names (execute-whateverstatus + printers + app-dir + verbose + (concat ["npx" "shadow-cljs" "release"] fe-app-names) + (str "Build " (uri-str fe-app-names) " frontend in production mode") + (str "Frontend building of " (uri-str fe-app-names) " has failed") + :git-status) + true (execute-if-success printers + app-dir + verbose + ["rm" "-fr" target-dir] + "Clean previous build" + "Error during target directory cleaning" + :clean-dir) + true (execute-if-success + printers + app-dir + verbose + ["clojure" (apply str "-T" uberjar-aliases) :production-dir (str "'\"" target-dir "\"'")] + "Build uberjar" + "Error during uberjar creation" + :create-uberjar) + true (execute-if-success printers + target-dir + verbose + ["git" "init" "-b" "master"] + "Creates a local repo" + "Error during local repo creation" + :init-repo) + true (execute-if-success printers + target-dir + verbose + ["git" "remote" "add" "clever" repo-url] + "Link to remote repo" + "Error during remote repo linking" + :remote-repo) + true (execute-if-success printers + target-dir + verbose + ["git" "add" "."] + "Add all to index" + "Error during index creation" + :create-stage) + true (execute-if-success printers + target-dir + verbose + ["git" "commit" "-m" "\"auto\""] + "Link to remote repo" + "Error during remote repo linking" + :commit))) + +(defn build + "Build the project in production mode, and deploy remotely + + `uberjar-aliases` is a string of keywords that should be assembled to build the jar (called with -T) + `fe-app-names` if the name as found in `shadow-cljs.edn`" + [{:keys [title errorln] + :as printers} + app-dir + current-task + uberjar-aliases + fe-app-names + env-varname + target-dir] + (if-let [exit-code (build-cli-opts/enter cli-opts current-task)] + exit-code + (if-let [repo-url (System/getenv env-varname)] + (let [title-msg "Generate uberjar"] + (title title-msg) + (-> (build* printers app-dir uberjar-aliases fe-app-names repo-url target-dir) + (build-cmd/status-to-exit-code printers title-msg))) + (errorln "For security reasons, the repo url should be saved as a system environment")))) + +(defn build-and-push + "Build the project in production mode, and deploy remotely + + `uberjar-aliases` is a string of keywords that should be assembled to build the jar (called with -T) + `fe-app-names` if the name as found in `shadow-cljs.edn`" + [{:keys [title errorln] + :as printers} + app-dir + current-task + uberjar-aliases + fe-app-names + env-varname + target-dir] + (if-let [exit-code (build-cli-opts/enter cli-opts current-task)] + exit-code + (if-let [repo-url (System/getenv env-varname)] + (let [title-msg "Generate and push uberjar"] + (title title-msg) + (-> (build* printers app-dir uberjar-aliases fe-app-names repo-url target-dir) + (execute-if-success printers + target-dir + verbose + ["git" "push" "--force"] + (str "Push to `" repo-url "`") + "Error during push" + :push) + (build-cmd/status-to-exit-code printers title-msg))) + (errorln + "For security reasons, the repo url should be set as a system environment variable named `" + env-varname + "`"))))