Skip to content

Commit

Permalink
New option to exit with >0 code if old deps are found
Browse files Browse the repository at this point in the history
Closes #39

----

BTW, in the README I found that some paragraphs were hard-wrapped and
some were not, so I wasn’t sure what to do. So I did the only logical
thing: introduced an additional wrapping style!

The wrapping style used in the new paragraphs is sometimes called
“semantic linebreaks” and sometimes “one sentence per line”

Some reading on this style, if you’re as geeky as me:

https://rhodesmill.org/brandon/2012/one-sentence-per-line/
https://nathangrigg.com/2012/05/strategic-line-breaks
  • Loading branch information
Avi Flax committed Mar 4, 2020
1 parent cc9e732 commit b98e1fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
22 changes: 22 additions & 0 deletions README.new.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ Checking virtual versions in: deps.edn
cider/piggieback {:mvn/version "0.4.1-SNAPSHOT"} -> {:mvn/version "0.4.1-20190222.154954-1"}
```

### Non-zero exit code

By default Depot exits with the [exit code][exit-code] `0` (which, by convention, denotes success) whether or not it finds any old/outdated dependencies.
To have Depot exit with a non-zero exit code when it does find such dependencies, include the `--fail` flag.
Depot will then set its exit code to the number of old/outdated dependencies.

This can be useful when running Depot as part of a script or in some automated context, such as a [Continuous Delivery][continuous-delivery] pipeline, workflow, or job.

For example:

```bash
$ clojure -Aoutdated --fail
Checking for old versions in: deps.edn
olical/depot {:mvn/version "..."} -> {:mvn/version "..."}
eastwood {:sha "..."} -> {:sha "..."}
$ echo $?
2
```


## Existing work

This project is inspired by [lein-ancient][], it relies on [version-clj][] (by the same author, [xsc][]) for parsing and comparison of version numbers.
Expand All @@ -117,6 +137,8 @@ Find the full [unlicense][] in the `UNLICENSE` file, but here's a snippet.
Do what you want. Learn as much as you can. Unlicense more software.

[continuous-delivery]: https://en.wikipedia.org/wiki/Continuous_delivery
[exit-code]: https://en.wikipedia.org/wiki/Exit_code
[unlicense]: http://unlicense.org/
[lein-ancient]: https://github.com/xsc/lein-ancient
[version-clj]: https://github.com/xsc/version-clj
Expand Down
11 changes: 8 additions & 3 deletions src/depot/outdated/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
["-e" "--every" "Expand search to all aliases."]
["-w" "--write" "Instead of just printing changes, write them back to the file."]
["-r" "--resolve-virtual" "Convert -SNAPSHOT/RELEASE/LATEST versions into immutable references."]
;; Not assigning -f to the following option because -f is an extremely common shorthand for a
;; --force option and I don’t want to risk anyone getting confused.
[nil "--fail" "If any old versions are found, exits with a non-zero status code."]
["-h" "--help"]])

(def ^:private messages
Expand All @@ -37,7 +40,7 @@
:no-changes " All up to date!"}})

(defn -main [& args]
(let [{{:keys [aliases consider-types every help write resolve-virtual]} :options
(let [{{:keys [aliases consider-types every fail help write resolve-virtual]} :options
files :arguments
summary :summary} (cli/parse-opts args cli-options)]
(cond
Expand All @@ -55,10 +58,12 @@
(:update-old messages))
new-versions (if resolve-virtual
resolve-virtual/pinned-versions
depot/newer-versions)]
depot/newer-versions)
exit-code (if fail (count new-versions) 0)]
(when (and every aliases)
(println "--every and --aliases are mutually exclusive.")
(System/exit 1))
(run! #(update/apply-new-versions % consider-types check-alias? write messages new-versions)
files)))
files)
(System/exit exit-code)))
(shutdown-agents)))

0 comments on commit b98e1fe

Please sign in to comment.