Skip to content

Commit

Permalink
Merge pull request #114 from liquidz/dev
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
liquidz authored Sep 18, 2021
2 parents 6c20a49 + 941a87e commit 88f8263
Show file tree
Hide file tree
Showing 18 changed files with 314 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
strategy:
matrix:
java: ['8', '11', '14', '15', '16']
java: ['8', '11', '16', '17-ea']

runs-on: ubuntu-latest
steps:
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. This change

== Unreleased (dev)

== 1.1.0 (2021-09-19)
// {{{
=== Added
* https://github.com/liquidz/antq/issues/93[#93]: Added support for upgrading `:tag` and `:git/tag` in deps.edn.

=== Changed
* Bumped tools.deps.alpha to 0.12.1048.

=== Fixed
* https://github.com/liquidz/antq/issues/113[#113]: Fixed to keep SHA length when upgrading deps.edn with `:tag` or `:git/tag`.
// }}}

== 1.0.2 (2021-09-18)
// {{{
=== Changed
Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ From Clojure CLI ver `1.10.3.933`, https://clojure.org/reference/deps_and_cli#to
[source,sh]
----
# install
clojure -Ttools install com.github.liquidz/antq '{:git/tag "1.0.2"}' :as antq
clojure -Ttools install com.github.liquidz/antq '{:git/tag "1.1.0"}' :as antq
# uninstall
clojure -Ttools remove :tool antq
# execute
Expand Down
6 changes: 2 additions & 4 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
org.clojure/data.xml {:mvn/version "0.2.0-alpha6"}
org.clojure/data.zip {:mvn/version "1.0.0"}
org.clojure/tools.cli {:mvn/version "1.0.206"}
org.clojure/tools.deps.alpha {:mvn/version "0.12.1041"}
org.clojure/tools.deps.alpha {:mvn/version "0.12.1048"}
org.clojure/data.json {:mvn/version "2.4.0"}
clj-commons/clj-yaml {:mvn/version "0.7.107"}
version-clj/version-clj {:mvn/version "2.0.2"}
Expand Down Expand Up @@ -42,9 +42,7 @@
:exec-args {}}

:deploy
{:extra-deps {slipset/deps-deploy {;; :mvn/version "RELEASE"
:git/url "https://github.com/slipset/deps-deploy"
:sha "3d20d0ee86c35c431e4fcf5b0830a3785e8116c0"}}
{:extra-deps {slipset/deps-deploy {:mvn/version "RELEASE"}}
:exec-fn deps-deploy.deps-deploy/deploy
:exec-args {}}

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.liquidz</groupId>
<artifactId>antq</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
<name>antq</name>
<description>Point out your outdated dependencies</description>
<url>https://github.com/liquidz/antq</url>
Expand Down Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>org.clojure</groupId>
<artifactId>tools.deps.alpha</artifactId>
<version>0.12.1041</version>
<version>0.12.1048</version>
</dependency>
<dependency>
<groupId>org.clojure</groupId>
Expand Down
1 change: 1 addition & 0 deletions src/antq/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
[antq.upgrade.shadow]
[antq.ver :as ver]
[antq.ver.git-sha]
[antq.ver.git-tag-and-sha]
[antq.ver.github-tag]
[antq.ver.java]
[clojure.string :as str]
Expand Down
24 changes: 22 additions & 2 deletions src/antq/dep/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,21 @@
(defmulti extract-type-and-version
(fn [opt]
(if (map? opt)
(or (and (:mvn/version opt) :java)
(and (:git/url opt) :git-sha))
(cond
(contains? opt :mvn/version)
:java

(and (contains? opt :git/url)
(some #(contains? opt %) [:tag :git/tag])
(some #(contains? opt %) [:sha :git/sha]))
:git-tag-and-sha

(and (contains? opt :git/url)
(some #(contains? opt %) [:sha :git/sha]))
:git-sha

:else
::unknown)
::unknown)))

(defmethod extract-type-and-version :default
Expand All @@ -37,6 +50,13 @@
:version (:sha opt (:git/sha opt))
:extra {:url (:git/url opt)}})

(defmethod extract-type-and-version :git-tag-and-sha
[opt]
{:type :git-tag-and-sha
:version (:tag opt (:git/tag opt))
:extra {:url (:git/url opt)
:sha (:sha opt (:git/sha opt))}})

(defn- adjust-version-via-deduction
[dep-name opt]
(if (and (map? opt)
Expand Down
62 changes: 49 additions & 13 deletions src/antq/upgrade/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require
[antq.upgrade :as upgrade]
[antq.util.dep :as u.dep]
[antq.util.git :as u.git]
[antq.util.zip :as u.zip]
[rewrite-clj.zip :as z]))

Expand All @@ -10,27 +11,62 @@
(->> loc z/up z/left z/sexpr
(contains? #{:deps :extra-deps :replace-deps :override-deps})))

(defn- find-version-key
(defmulti replace-versions
(fn [_loc version-checked-dep]
(:type version-checked-dep)))

(defmethod replace-versions :default
[loc version-checked-dep]
(some-> loc
(z/find-value z/right :mvn/version)
(z/right)
(z/replace (:latest-version version-checked-dep))))

(defmethod replace-versions :git-sha
[loc version-checked-dep]
(if (= :git-sha (:type version-checked-dep))
(or (z/find-value loc z/right :sha)
(z/find-value loc z/right :git/sha))
(z/find-value loc z/right :mvn/version)))
(some-> (or (z/find-value loc z/right :sha)
(z/find-value loc z/right :git/sha))
(z/right)
(z/replace (:latest-version version-checked-dep))))

(defmethod replace-versions :git-tag-and-sha
[loc version-checked-dep]
(let [tag-loc (some-> (or (z/find-value loc z/right :tag)
(z/find-value loc z/right :git/tag))
(z/right)
(z/replace (:latest-version version-checked-dep))
(z/up)
(z/down))
sha-loc (when tag-loc
(or (z/find-value tag-loc z/right :sha)
(z/find-value tag-loc z/right :git/sha)))]
(cond
(and tag-loc sha-loc)
(let [{:keys [latest-version extra]} version-checked-dep
;; NOTE: the result of `git ls-remote` should be cached by `memoize`
new-sha (-> (u.git/tag-sha-by-ls-remote (:url extra) latest-version)
(subs 0 (count (:sha extra))))]
(-> sha-loc
(z/right)
(z/replace new-sha)))

tag-loc
tag-loc

:else
loc)))

(defn upgrade-dep
[loc version-checked-dep]
(let [name-set (u.dep/name-candidates (:name version-checked-dep))]
(loop [loc loc]
(if-let [loc (z/find-value loc z/next name-set)]
(recur (if (in-deps? loc)
(some-> loc
;; move to map
(z/right) (z/down)
;; find version key
(find-version-key version-checked-dep)
;; replace
(z/right)
(z/replace (:latest-version version-checked-dep)))
(or (some-> loc
;; move to map
(z/right) (z/down)
(replace-versions version-checked-dep))
(z/next loc))
(z/next loc)))
(u.zip/move-to-root loc)))))

Expand Down
33 changes: 31 additions & 2 deletions src/antq/util/git.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
(filter #(= 0 (.indexOf ^String % "refs/tags")))
(map #(str/replace % #"^refs/tags/" ""))))

(defn- sh-git-ls-remote
(defn- extract-sha-by-ref-name
[ls-remote-resp target-ref-name]
(some->> (:out ls-remote-resp)
(str/split-lines)
(some (fn [line]
(let [[sha ref-name] (str/split line #"\t" 2)]
(and (= target-ref-name ref-name)
sha))))))

(defn- ls-remote*
[url]
(loop [i 0]
(when (< i const/retry-limit)
Expand All @@ -29,9 +38,29 @@
(do (log/error "git ls-remote timed out, retrying")
(recur (inc i))))))))

(def ^:private ls-remote
(memoize ls-remote*))

(defn tags-by-ls-remote*
[url]
(-> (sh-git-ls-remote url)
(-> (ls-remote url)
(extract-tags)))

(def tags-by-ls-remote
(memoize tags-by-ls-remote*))

(defn head-sha-by-ls-remote*
[url]
(-> (ls-remote url)
(extract-sha-by-ref-name "HEAD")))

(defn tag-sha-by-ls-remote*
[url tag-name]
(-> (ls-remote url)
(extract-sha-by-ref-name (str "refs/tags/" tag-name))))

(def head-sha-by-ls-remote
(memoize head-sha-by-ls-remote*))

(def tag-sha-by-ls-remote
(memoize tag-sha-by-ls-remote*))
27 changes: 6 additions & 21 deletions src/antq/ver/git_sha.clj
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
(ns antq.ver.git-sha
(:require
[antq.ver :as ver]
[clojure.java.shell :as sh]
[clojure.string :as str]))

(defn- extract-head-sha
[ls-remote-resp]
(some->> (:out ls-remote-resp)
(str/split-lines)
(some (fn [line]
(let [[sha ref-name] (str/split line #"\t" 2)]
(and (= "HEAD" ref-name)
sha))))))

(defn- git-ls-remote
[url]
(sh/sh "git" "ls-remote" url))
[antq.util.git :as u.git]
[antq.ver :as ver]))

(defmethod ver/get-sorted-versions :git-sha
[dep]
(let [resp (->> (get-in dep [:extra :url])
(git-ls-remote))]
(or (some-> (extract-head-sha resp)
(vector))
[])))
(or (some-> (get-in dep [:extra :url])
(u.git/head-sha-by-ls-remote)
(vector))
[]))

(defmethod ver/latest? :git-sha
[dep]
Expand Down
17 changes: 17 additions & 0 deletions src/antq/ver/git_tag_and_sha.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns antq.ver.git-tag-and-sha
(:require
[antq.util.git :as u.git]
[antq.util.ver :as u.ver]
[antq.ver :as ver]
[version-clj.core :as version]))

(defmethod ver/get-sorted-versions :git-tag-and-sha
[dep]
(or (some->> (get-in dep [:extra :url])
(u.git/tags-by-ls-remote)
(filter (comp u.ver/sem-ver? u.ver/normalize-version))
(sort (fn [& args]
(apply version/version-compare
(map u.ver/normalize-version args))))
(reverse))
[]))
32 changes: 23 additions & 9 deletions test/antq/dep/clojure_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@
:file file-path
:repositories {"antq-test" {:url "s3://antq-repo/"}}}
m)))
(defn- git-dependency
(defn- git-sha-dependency
[m]
(r/map->Dependency (merge {:project :clojure
:type :git-sha
:file file-path
:repositories {"antq-test" {:url "s3://antq-repo/"}}}
m)))

(defn- git-tag-dependency
[m]
(r/map->Dependency (merge {:project :clojure
:type :git-tag-and-sha
:file file-path
:repositories {"antq-test" {:url "s3://antq-repo/"}}}
m)))

(t/deftest extract-deps-test
(let [deps (sut/extract-deps
file-path
Expand All @@ -35,13 +43,19 @@
(java-dependency {:name "baz/baz" :version "3.0.0"})
(java-dependency {:name "rep/rep" :version "4.0.0"})
(java-dependency {:name "ovr/ovr" :version "5.0.0"})
(git-dependency {:name "git/hello" :version "dummy-sha"
:extra {:url "https://github.com/example/hello.git"}})
(git-dependency {:name "com.github.liquidz/dummy"
:version "123abcd"
:extra {:url "https://github.com/liquidz/dummy.git"}})
(git-dependency {:name "git/world" :version "dummy-sha2"
:extra {:url "https://github.com/example/world.git"}})}
(git-sha-dependency {:name "sha/sha" :version "dummy-sha"
:extra {:url "https://github.com/example/sha.git"}})
(git-sha-dependency {:name "git-sha/git-sha" :version "dummy-git-sha"
:extra {:url "https://github.com/example/git-sha.git"}})
(git-sha-dependency {:name "com.github.liquidz/dummy"
:version "dummy-inferring-url"
:extra {:url "https://github.com/liquidz/dummy.git"}})
(git-tag-dependency {:name "tag-short-sha/tag-short-sha" :version "v1.2.3"
:extra {:url "https://github.com/example/tag-short.git"
:sha "123abcd"}})
(git-tag-dependency {:name "git-tag-long-sha/git-tag-long-sha" :version "v2.3.4"
:extra {:url "https://github.com/example/git-tag-long.git"
:sha "1234567890abcdefghijklmnopqrstuvwxyz1234"}})}
(set deps)))))

(t/deftest extract-deps-unexpected-test
Expand All @@ -51,4 +65,4 @@

(t/deftest load-deps-test
(let [deps (sut/load-deps "test/resources/dep")]
(t/is (every? #(contains? #{:java :git-sha} (:type %)) deps))))
(t/is (every? #(contains? #{:java :git-sha :git-tag-and-sha} (:type %)) deps))))
13 changes: 11 additions & 2 deletions test/antq/test_helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
(defn name-version-sorted-list
[deps]
(->> deps
(map #(select-keys % [:name :version]))
(map #(let [url (get-in % [:extra :url])
sha (get-in % [:extra :sha])]
(cond-> (select-keys % [:name :version])
url (assoc :url url)
sha (assoc :sha sha))))
(sort-by #(str (:name %) (:version %)))))

(defn diff-deps
Expand All @@ -22,5 +26,10 @@
(name-version-sorted-list actual-deps))
(filter #(instance? Mismatch (:version %)))
;; convert `:version` to a simple map
(map #(update % :version (fn [m] (merge {} m))))
(map #(cond-> %
(contains? % :version)
(update :version (fn [m] (merge {} m)))

(contains? % :sha)
(update :sha (fn [m] (merge {} m)))))
(set)))
Loading

0 comments on commit 88f8263

Please sign in to comment.