Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context cleaning - Better specs - Better speration of concerns - Pom generation #12

Merged
merged 45 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
13d0b48
Removed unused function.
JeremS Nov 1, 2019
1a0a68f
Parinfer formatting.
JeremS Nov 1, 2019
b871d42
Added stricter assertion function that will always run.
JeremS Nov 1, 2019
69061e3
Pulled the bumped context in api, for use in other tools.
JeremS Nov 1, 2019
508be0d
Parinfer formatting.
JeremS Nov 1, 2019
3bf8420
Separated the merging of default options.
JeremS Nov 1, 2019
c51c83c
Added new specs.
JeremS Nov 1, 2019
f9b658c
Reworked the assertion function not to use s/assert* and adding repor…
JeremS Nov 1, 2019
1e40168
Added assert-context utility.
JeremS Nov 1, 2019
882f644
Added basics tests for the context validation.
JeremS Nov 1, 2019
b4d1f5c
Renamed assert-spec to check-spec, corrected display and added displa…
JeremS Nov 1, 2019
49f3794
Update CLI
JeremS Nov 1, 2019
b526f7d
Code styling.
JeremS Nov 4, 2019
bb2d825
Enforce checks that could have been skipped.
JeremS Nov 4, 2019
a334621
Corrected badly used spec api.
JeremS Nov 5, 2019
739b3d5
Changed how default options are merged.
JeremS Nov 7, 2019
227e93b
Placed the the context check in the operation instead of the api.
JeremS Nov 7, 2019
5141937
Use a sorted map for contexts.
JeremS Nov 7, 2019
6230c2a
Parinfer formatting.
JeremS Nov 7, 2019
2057def
Corrected bad return value.
JeremS Nov 7, 2019
8bacc74
Added full error object in cli returns.
JeremS Nov 7, 2019
3ad27f9
Refactoring.
JeremS Nov 7, 2019
5ee9906
Refactored release operation to be a sequence of more specific opera…
JeremS Nov 7, 2019
da0422d
Renaming.
JeremS Nov 7, 2019
be2d8d9
Continued refactoring.
JeremS Nov 7, 2019
66f16e2
Refactoring.
JeremS Nov 7, 2019
f9148b5
Renaming of :metav.release/without-sign in the doc.
JeremS Nov 7, 2019
9aa0d2f
Removed dangling todo.
JeremS Nov 8, 2019
a1ac5cd
Tracked down a renaming hiccup.
JeremS Nov 8, 2019
10175bc
Renamed `metav.domain.common` to `metav.domain.metadata`.
JeremS Nov 8, 2019
83df5d5
Simplified code.
JeremS Nov 8, 2019
2de4a31
Still renaming.
JeremS Nov 9, 2019
1f9916b
Renaming.
JeremS Nov 9, 2019
a94f716
Added the debs infos to the context map in preparation of the pom ope…
JeremS Nov 9, 2019
e126fcd
Remade some helpers.
JeremS Nov 9, 2019
24e9db3
Renaming utils-test to test-utils with the idea of creating test for …
JeremS Nov 9, 2019
a13e41a
Changed ensure keys to have the successive ensured map threaded.
JeremS Nov 9, 2019
e620845
Correction.
JeremS Nov 10, 2019
256e529
Removed unused function.
JeremS Nov 10, 2019
b38dcf2
Added pom.xml generation.
JeremS Nov 10, 2019
e6f17f1
Added reminder to add pom generation as an option in the release oper…
JeremS Nov 10, 2019
6487db4
Added tests for the sync-pom! operation.
JeremS Nov 10, 2019
b5733f0
Little refactoring.
JeremS Nov 10, 2019
1e8fbfa
Started adding pom.xml generation to the release operation.
JeremS Nov 10, 2019
0a775ad
Added tests for the pom generation.
JeremS Nov 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
:deps {org.clojure/clojure {:mvn/version "1.10.1"}
org.clojure/tools.cli {:mvn/version "0.4.1"}
org.clojure/tools.logging {:mvn/version "0.4.1"}
org.clojure/tools.deps.alpha {:mvn/version "0.8.584"}
org.clojure/data.json {:mvn/version "0.2.6"}

cljstache {:mvn/version "2.0.1"}
clj-commons/fs {:mvn/version "1.5.0"}
org.apache.maven/maven-artifact {:mvn/version "3.6.0"}}
clj-commons/fs {:mvn/version "1.5.0"}}

:jvm-opts ["-Djava.io.tmpdir=./tmp"]
:aliases {:dev {:extra-paths ["logging"]
:extra-deps {org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version"2.12.1"}
Expand Down
6 changes: 3 additions & 3 deletions docs/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ versioning data is presented as follow in clojure edn format:
```clojure
{:module-name artefact-name ;; the artefact name ase discussed above
:version (str version)
:tag tag ;; (str artefact-name "-" version)
:tag tag ;; (str artefact-name "-" version)
:generated-at (iso-now)
:path (if git-prefix git-prefix ".")}
```
Expand Down Expand Up @@ -85,7 +85,7 @@ With metav in the classpath in a terminal:

;; Defines some option for metav
(def options {:metav/working-dir "my/projects/dir" ;; dir from which metav bases its execution context
:metav.release/without-sign true ;; we're not signing git tags
:metav.git/without-sign true ;; we're not signing git tags
:metav.release/spit true ;; we want to spit project data before releasing
:metav.spit/output-dir "resources" ;; location where the spitted files go
:metav.spit/namespace "metav.meta" ;; namespace of the spitted files
Expand Down Expand Up @@ -133,7 +133,7 @@ The full range of options that can be passed to metav operations.
- `:metav.release/level`: `#{:alpha :beta :major :minor :patch :rc :release}`,
the bump levels available, must be correlated with `:metav/version-scheme`.
Defaults to `:patch`.
- `:metav.release/without-sign`: `boolean?`, whether version git tags
- `:metav.git/without-sign`: `boolean?`, whether version git tags
won't be signed with gpg. Defaults to `false`.
- `:metav.release/without-push`: `boolean?`, whether we don't want to push
after tagging a new version. Defaults to `false`.
Expand Down
22 changes: 12 additions & 10 deletions resources-test/dummy-deps.edn
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{:paths [\"resources\" \"src\"]
:deps {org.clojure/clojure {:mvn/version \"1.10.0\"}}
:jvm-opts [\"-Djava.io.tmpdir=./tmp\"]
:aliases {:artifact-name {:extra-deps {jgrodziski/metav {:git/url \"https://github.com/jgrodziski/metav\"
:sha \"5c4059c96ffeb3b097399f14739be8b5eb2d48b8\"}}
:main-opts [\"-m\" \"metav.display\"]}
:release {:extra-deps {jgrodziski/metav {:git/url \"https://github.com/jgrodziski/metav\"
:sha \"5c4059c96ffeb3b097399f14739be8b5eb2d48b8\"}}
:main-opts [\"-m\" \"metav.release\"]}
}}
{:paths ["resources" "src"]
:deps {org.clojure/clojure {:mvn/version "1.10.0"}}

:jvm-opts ["-Djava.io.tmpdir=./tmp"]

:aliases {:artifact-name {:extra-deps {jgrodziski/metav {:git/url "https://github.com/jgrodziski/metav"
:sha "5c4059c96ffeb3b097399f14739be8b5eb2d48b8"}}
:main-opts ["-m" "metav.display"]}
:release {:extra-deps {jgrodziski/metav {:git/url "https://github.com/jgrodziski/metav"
:sha "5c4059c96ffeb3b097399f14739be8b5eb2d48b8"}}
:main-opts ["-m" "metav.release"]}}}

1 change: 1 addition & 0 deletions resources-test/example-bad-conf.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:malformed :map
3 changes: 2 additions & 1 deletion resources-test/example-conf.edn
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
:metav.spit/template "mustache-template.txt"
:metav.spit/rendering-output "resources/rendered-conf.txt"

:metav.git/without-sign true

:metav.release/spit false
:metav.release/level :patch
:metav.release/without-sign true
:metav.release/without-push false}
99 changes: 69 additions & 30 deletions src/metav/api.clj
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
(ns metav.api
(:require
[clojure.spec.alpha :as s]
[clojure.data.json :as json]
[metav.utils :as utils]
[metav.domain.common :as common]
[metav.domain.context :as context]
[metav.domain.display :as display]
[metav.domain.spit :as spit]
[metav.domain.release :as release]
))

(def default-options
(merge context/default-options
display/default-options
spit/defaults-options
release/default-options))

(s/def :metav/options (s/and :metav.context/options
:metav.display/options
:metav.spit/options
:metav.release/options))
[clojure.spec.alpha :as s]
[clojure.data.json :as json]
[metav.utils :as utils]
[metav.domain.context :as context]
[metav.domain.display :as display]
[metav.domain.git-operations :as git-ops]
[metav.domain.metadata :as metadata]
[metav.domain.pom :as pom]
[metav.domain.release :as release]
[metav.domain.spit :as spit]))



(defn make-context
Expand All @@ -29,12 +20,15 @@
(let [working-dir (:metav/working-dir opts)
opts (cond-> opts
(not working-dir) (assoc :metav/working-dir (utils/pwd)))]
(context/make-context
(s/assert* :metav/options
(merge default-options opts))))))
(context/make-context opts))))


(defn check-context [context]
(utils/check-spec :metav/context context))


(def metadata-as-edn metadata/metadata-as-edn)

(def metadata-as-edn common/metadata-as-edn)

;;----------------------------------------------------------------------------------------------------------------------
;; Display
Expand All @@ -44,11 +38,11 @@


(defmethod display* :edn [context]
(println (common/metadata-as-edn context)))
(println (metadata/metadata-as-edn context)))


(defmethod display* :json [context]
(println (json/write-str (common/metadata-as-edn context))))
(println (json/write-str (metadata/metadata-as-edn context))))


(defmethod display* :tab [{:metav/keys [artefact-name version]}];default is tab separated module-name and version
Expand All @@ -58,8 +52,11 @@
(defn display
([] (display (make-context)))
([context]
(s/assert :metav.display/options context)
(display* context)
(-> context
(utils/merge&validate display/default-options
(s/merge :metav/context
:metav.display/options))
(display*))
context))

;;----------------------------------------------------------------------------------------------------------------------
Expand All @@ -68,10 +65,52 @@

(defn spit!
([] (spit! (make-context)))
([context] (spit/spit! context)))
([context]
(spit/spit! context)))


(defn git-add-spitted! [context]
(spit/git-add-spitted! context))

;;----------------------------------------------------------------------------------------------------------------------
;; Pom!
;;----------------------------------------------------------------------------------------------------------------------

(defn sync-pom! [context]
(pom/sync-pom! context))


(defn git-add-pom! [context]
(pom/git-add-pom! context))

;;----------------------------------------------------------------------------------------------------------------------
;; git!
;;----------------------------------------------------------------------------------------------------------------------

(defn check-commited [context]
(git-ops/check-committed? context))


(defn tag-repo! [context]
(git-ops/tag-repo! context))


(defn commit! [context msg]
(git-ops/commit! context msg))


(defn push! [context]
(git-ops/push! context))

;;----------------------------------------------------------------------------------------------------------------------
;; Release!
;;----------------------------------------------------------------------------------------------------------------------

(def release! release/release!)
(defn bump [context]
(release/bump-context context))


(defn release!
([] (release! (make-context)))
([context]
(release/release! context)))
54 changes: 36 additions & 18 deletions src/metav/cli/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[clojure.string :as string]
[clojure.edn :as edn]
[me.raynes.fs :as fs]
[metav.api :as api]))
[metav.api :as api])
(:import (clojure.lang ExceptionInfo)))


;;----------------------------------------------------------------------------------------------------------------------
Expand All @@ -21,10 +22,6 @@
;;----------------------------------------------------------------------------------------------------------------------
;; Common conf
;;----------------------------------------------------------------------------------------------------------------------
(def default-options
(merge api/default-options
#:metav.cli{:verbose? false}))

(s/def :metav.cli/verbose? boolean?)
(s/def :metav.cli/config fs/exists?)

Expand Down Expand Up @@ -85,16 +82,24 @@
(exit res))))


(defn read-config-file [path]
(try
(-> path slurp edn/read-string)
(catch Exception e
{::error-msg (.getMessage e)
::error e})))


(defn process-parsed-opts [parsed]
(let [{:keys [options]} parsed
file-config (:metav.cli/config options)
definitive-options (if file-config
(merge (-> file-config slurp edn/read-string)
(dissoc options :metav.cli/config))
options)]
(if (s/valid? :metav/options definitive-options)
(assoc parsed :custom-opts definitive-options)
(assoc parsed :exit-message (s/explain-str :metav/options definitive-options)))))
file-config (if-let [path (:metav.cli/config options)]
(read-config-file path)
nil)]
(if-let [error (::error-msg file-config)]
(assoc parsed :exit-message (str "Error reading the config file: \n" error))
(assoc parsed :custom-opts (cond->> options
file-config (merge file-config))))))


(defn make-validate-args
"Makes a function that validates command line arguments. This function
Expand Down Expand Up @@ -154,8 +159,21 @@
(let [{:keys [exit? ctxt-opts] :as parsed-and-validated} (validate-args-fn args)]
(if exit?
parsed-and-validated
(let [res (-> ctxt-opts api/make-context perform-command-fn)]
(assoc parsed-and-validated
:ret res
:exit? true
:ok? true))))))
(let [res (try
(-> ctxt-opts api/make-context perform-command-fn)
(catch ExceptionInfo e
{::error e
::error-msg (ex-message e)})
(catch Exception e
{::error e
::error-msg (.getMessage e)}))]
(if-let [error (::error-msg res)]
(assoc parsed-and-validated
:ret res
:exit? true
:ok? false
:exit-message error)
(assoc parsed-and-validated
:ret res
:exit? true
:ok? true)))))))
5 changes: 4 additions & 1 deletion src/metav/cli/release.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
(def cli-options
(conj cli-spit/cli-options
[nil "--without-sign" "Should the git tag used for release be signed with the current user's GPG key configured with git"
:id :metav.release/without-sign
:id :metav.git/without-sign
:default-desc "false"]
[nil "--spit" "Indicates the release process should spit the metadata file as with the \"spit\" task, in that case the spit options must be provided"
:id :metav.release/spit
:default-desc "false"]
[nil "--pom" "Indicates the release process should update (or create) a pom.xml file for the project."
:id :metav.release/pom
:default-desc "false"]
["-w" "--without-push" "Execute the release process but without pushing at the end, if you want to control the pushing instant yourself"
:id :metav.release/without-push
:default-desc "false"]))
Expand Down
Loading