introduce debug & dry run

This commit is contained in:
Michael Jerger 2024-07-27 16:30:30 +02:00
parent 1b91da0e3d
commit 0cbd256547
4 changed files with 45 additions and 5 deletions

View file

@ -9,9 +9,11 @@
(s/def ::stage string?)
(s/def ::project-root-path string?)
(s/def ::build-dir-name string?)
(s/def ::debug boolean?)
(s/def ::dry-run boolean?)
(s/def ::devops
(s/keys :req-un [::name ::stage ::project-root-path ::build-dir-name]
(s/keys :req-un [::name ::stage ::project-root-path ::build-dir-name ::debug ::dry-run]
:opt-un [::module]))
(defn-spec build-path string?

View file

@ -0,0 +1,13 @@
(ns dda.build.infrastructure
(:require [orchestra.core :refer [defn-spec]]
[babashka.tasks :as t]
[dda.build.devops.domain :as d]))
(defn-spec execute nil?
[command string?
devops ::d/devops]
(let [{:keys [dry-run debug]} devops]
(when debug
(println command))
(when-not dry-run
(apply t/shell command))))

View file

@ -0,0 +1,17 @@
(ns dda.build.terragrunt.domain
(:require [clojure.spec.alpha :as s]
[orchestra.core :refer [defn-spec]]
[dda.build.devops.domain :as d]))
(s/def ::devops
(s/keys :req-un [::name ::stage ::project-root-path ::build-dir-name ::debug ::dry-run ::module]
:opt-un []))
(defn-spec clean-build-dir-command seq?
[devops ::devops]
["rm" "-rf" (d/build-path (dissoc devops :module))])
(defn-spec copy-terragrunt-command seq?
[devops ::devops]
(let [{:keys [module]} devops]
["cp" "." (d/build-path devops) "&&" "cp" module (d/build-path devops)]))

View file

@ -13,14 +13,18 @@
:project-root-path "../.."
:build-dir-name "target"
:version "4.11.8-dev"
:stage "dev"})))
:stage "dev"
:debug false
:dry-run false})))
(is (= "../../target/dda/backup"
(cut/build-path {:name "dda"
:module "backup"
:project-root-path "../.."
:build-dir-name "target"
:version "4.11.8-dev"
:stage "dev"}))))
:stage "dev"
:debug false
:dry-run false}))))
(deftest should-calculate-clean-build-dir-command
(is (= ["rm" "-rf" "../../target/dda-backup"]
@ -28,7 +32,9 @@
:project-root-path "../.."
:build-dir-name "target"
:version "4.11.8-dev"
:stage "dev"}))))
:stage "dev"
:debug false
:dry-run false}))))
(deftest should-calculate-create-build-dir-command
(is (= ["mkdir" "-p" "../../target/dda-backup"]
@ -36,5 +42,7 @@
:project-root-path "../.."
:build-dir-name "target"
:version "4.11.8-dev"
:stage "dev"}))))
:stage "dev"
:debug false
:dry-run false}))))