From 89ce2bf41d2a207b0c49cf40adcca705fccbcc50 Mon Sep 17 00:00:00 2001 From: RJ Sheperd Date: Mon, 7 Apr 2025 09:41:37 -0700 Subject: [PATCH 1/2] Use git hash to enable automated help import --- deps.edn | 4 +-- development/help_import.clj | 56 ++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/deps.edn b/deps.edn index 89fde128b..88f9a635f 100644 --- a/deps.edn +++ b/deps.edn @@ -155,11 +155,11 @@ {:extra-paths ["projects/behave_cms/src/clj" "projects/behave_cms/src/cljc"] - :exec-fn help-import/import-help} + :exec-fn help-import/import-help!} :rollback-help-import {:extra-paths ["projects/behave_cms/src/clj" "projects/behave_cms/src/cljc" "projects/behave_cms/resources"] - :exec-fn help-import/rollback-import}}} + :exec-fn help-import/rollback-import!}}} diff --git a/development/help_import.clj b/development/help_import.clj index f1731968f..fa5edbccd 100644 --- a/development/help_import.clj +++ b/development/help_import.clj @@ -7,7 +7,8 @@ [datomic.api :as d] [dita.xhtml-cleaner :refer [clean-topic clean-variables]] [me.raynes.fs :as fs] - [schema-migrate.interface :as sm])) + [schema-migrate.interface :as sm] + [clojure.java.shell :refer [sh]])) ;;; Helpers @@ -32,6 +33,10 @@ (:language/help-page) (map (fn [p] [:db/retractEntity (:db/id p)])))) +(defn- behave-docs-git-hash [] + (let [process (sh "git" "rev-parse" "--short" "HEAD" :dir "bases/behave-docs")] + (str/replace (:out process) "\n" ""))) + ;;; Topics (defn- cleaned-topics-tx [behave-docs-base-dir english-lang] @@ -61,38 +66,43 @@ ;;; Public fns -(defn import-help +(defn import-help! "Imports help from `bases/behave-docs`." [& _] (cms/init-db! (io/file "projects/behave_cms/resources/config.edn")) - (let [conn @ds/datomic-conn - db (d/db conn) - en-us (q-english-lang-id db) - -now (now) - add-tx (format "help-import-add-%s" -now) - remove-tx (format "help-import-remove-%s" -now) + (let [conn @ds/datomic-conn + db (d/db conn) + en-us (q-english-lang-id db) + git-hash (behave-docs-git-hash) + add-tx (format "help-import-add-%s" git-hash) + remove-tx (format "help-import-remove-%s" git-hash) ;; Behave Docs dir - behave-docs (io/file "bases" "behave-docs" "XHTML_Output" "BehaveAppHelp")] - - #_(println (format "Removing old help docs %s" -now)) - (d/transact conn (concat [(sm/->migration remove-tx)] - (remove-existing-pages-tx db en-us))) - - #_(println (format "Adding new help docs %s" -now)) - (d/transact conn (concat [(sm/->migration add-tx)] - (cleaned-topics-tx behave-docs en-us) - (cleaned-variables-tx behave-docs en-us))))) - -(defn rollback-import + behave-docs (io/file "bases" "behave-docs" "XHTML_Output" "BehaveAppHelp") + existing-tx? (d/q '[:find ?t . + :in $ ?mid + :where [?t :bp/migration-id ?mid]] + (d/db @ds/datomic-conn) add-tx)] + + (when-not existing-tx? + #_(println (format "Removing old help docs from hash: %s" -now)) + (d/transact conn (concat [(sm/->migration remove-tx)] + (remove-existing-pages-tx db en-us))) + + #_(println (format "Adding new help docs %s" -now)) + (d/transact conn (concat [(sm/->migration add-tx)] + (cleaned-topics-tx behave-docs en-us) + (cleaned-variables-tx behave-docs en-us)))))) + +(defn rollback-import! "Rollback imports. Option to provide a transaction date." [& args] (cms/init-db!) (let [a-datetime (first args) conn @ds/datomic-conn db (d/db conn) - -now (now) - tx-remove-id (q-tx db (format "help-import-remove-%s" (or a-datetime -now))) - tx-add-id (q-tx db (format "help-import-add-%s" (or a-datetime -now)))] + git-hash (behave-docs-git-hash) + tx-remove-id (q-tx db (format "help-import-remove-%s" (or a-datetime git-hash))) + tx-add-id (q-tx db (format "help-import-add-%s" (or a-datetime git-hash)))] (sm/rollback-tx! conn tx-remove-id) (sm/rollback-tx! conn tx-add-id))) From 22e59fe4dd844dfd0e4769db05aad003c95655cd Mon Sep 17 00:00:00 2001 From: RJ Sheperd Date: Mon, 7 Apr 2025 09:43:04 -0700 Subject: [PATCH 2/2] Update import-help bb command --- bb.edn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bb.edn b/bb.edn index ff2f039d2..f069b4cfe 100644 --- a/bb.edn +++ b/bb.edn @@ -25,7 +25,7 @@ ;;; Commands import-help (do - (clojure "-X:dev:import-help") + (clojure "-X:dev:import-help!") (fs/copy-tree "bases/behave-docs/XHTML_Output/Resources/Images/" "projects/behave/resources/public/help/images" {:replace-existing true}))