-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
166 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: 2.1 | ||
|
||
orbs: | ||
node: circleci/[email protected] | ||
docker: circleci/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(ns antq.dep.circle-ci | ||
(:require | ||
[clojure.java.io :as io] | ||
[clojure.string :as str] | ||
[clj-yaml.core :as yaml] | ||
[antq.util.dep :as u.dep] | ||
[antq.record :as r])) | ||
|
||
(defn extract-deps [file-path content-str] | ||
(let [parsed (yaml/parse-string content-str)] | ||
(->> parsed | ||
:orbs | ||
vals | ||
(into | ||
[] | ||
(map (fn [orb-s] | ||
(let [[name version] (str/split orb-s #"@")] | ||
(r/map->Dependency {:name name | ||
:version version | ||
:type :circle-ci-orb | ||
:project :circle-ci | ||
:file file-path})))))))) | ||
|
||
(defn load-deps | ||
{:malli/schema [:function | ||
[:=> :cat [:maybe r/?dependencies]] | ||
[:=> [:cat 'string?] [:maybe r/?dependencies]]]} | ||
([] (load-deps ".")) | ||
([dir] | ||
(let [config-file (io/file dir ".circleci/config.yml")] | ||
(when (.exists config-file) | ||
(extract-deps (u.dep/relative-path config-file) | ||
(slurp config-file)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(ns antq.upgrade.circle-ci | ||
(:require | ||
[clojure.string :as str] | ||
[antq.upgrade :as upgrade] | ||
[rewrite-indented.zip :as ri.zip])) | ||
|
||
(defn- update-value | ||
[new-value] | ||
(fn [line] | ||
(str/replace line #"([^@]+\s*@\s*['\"]?)[^\s'\"]+(['\"]?)" | ||
(str "$1" new-value "$2")))) | ||
|
||
(defn upgrade-dep [loc version-checked-dep] | ||
(loop [loc loc] | ||
(if-let [loc (ri.zip/find-next-string loc #(re-seq (re-pattern (str "[^:]+\\s*:\\s*" (:name version-checked-dep) "@")) %))] | ||
(recur (-> (ri.zip/update loc (update-value (:latest-version version-checked-dep))) | ||
ri.zip/next)) | ||
(ri.zip/move-to-root loc)))) | ||
|
||
(defmethod upgrade/upgrader :circle-ci | ||
[version-checked-dep] | ||
(some-> (:file version-checked-dep) | ||
(ri.zip/of-file) | ||
(upgrade-dep version-checked-dep) | ||
(ri.zip/root-string))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(ns antq.ver.circle-ci-orb | ||
(:require | ||
[clojure.java.io :as io] | ||
[clojure.string :as str] | ||
[clojure.data.json :as json] | ||
[antq.ver :as ver])) | ||
|
||
(defn orb-id [ns name] | ||
(-> (io/as-url (str "https://internal.circleci.com/api/v2/orbs?ns=" ns "&name=" name)) | ||
slurp | ||
(json/read-str :key-fn keyword) | ||
:items | ||
first | ||
:id)) | ||
|
||
(defn orb-versions [id] | ||
(-> (io/as-url (str "https://internal.circleci.com/api/v2/orbs/" id)) | ||
slurp | ||
(json/read-str :key-fn keyword) | ||
:versions)) | ||
|
||
(defmethod ver/get-sorted-versions :circle-ci-orb | ||
[dep _options] | ||
(let [[ns name] (str/split (:name dep) #"/") | ||
id (orb-id ns name)] | ||
(orb-versions id))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(ns antq.dep.circle-ci-test | ||
(:require | ||
[antq.dep.circle-ci :as sut] | ||
[antq.record :as r] | ||
[clojure.test :as t] | ||
[clojure.java.io :as io])) | ||
|
||
(defn- git-tag-dependency | ||
[m] | ||
(r/map->Dependency (merge {:project :circle-ci | ||
:type :circle-ci-orb | ||
:file "dep/test_circle_ci.yml"} m))) | ||
|
||
(t/deftest extract-deps-test | ||
(let [deps (sut/extract-deps "dep/test_circle_ci.yml" | ||
(slurp (io/resource "dep/test_circle_ci.yml")))] | ||
(t/is (sequential? deps)) | ||
(t/is (every? #(instance? antq.record.Dependency %) deps)) | ||
(t/is (= #{(git-tag-dependency {:name "circleci/node" :version "6.3.0"}) | ||
(git-tag-dependency {:name "circleci/docker" :version "2.8.0"})} | ||
(set deps))))) | ||
|
||
(t/deftest load-deps-test | ||
(let [deps (sut/load-deps)] | ||
(t/is (= #{".circleci/config.yml"} | ||
(set (map :file deps))))) | ||
|
||
(t/is (nil? (sut/load-deps "non_existing_directory")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(ns antq.upgrade.circle-ci-test | ||
(:require | ||
[antq.upgrade :as upgrade] | ||
[antq.upgrade.circle-ci] | ||
[antq.record :as r] | ||
[antq.dep.circle-ci :as dep.circle-ci] | ||
[antq.test-helper :as h] | ||
[clojure.java.io :as io] | ||
[clojure.test :as t])) | ||
|
||
(def ^:private node-dep | ||
(r/map->Dependency {:project :circle-ci | ||
:type :circle-ci-orb | ||
:name "circleci/node" | ||
:version "6.3.0" | ||
:latest-version "7.0.0" | ||
:file (io/resource "dep/test_circle_ci.yml")})) | ||
|
||
(t/deftest upgrade-dep-test | ||
(t/testing "supported" | ||
(let [from-deps (->> (:file node-dep) | ||
(slurp) | ||
(dep.circle-ci/extract-deps "")) | ||
temp-content (->> node-dep | ||
(upgrade/upgrader)) | ||
to-deps (h/with-temp-file | ||
[temp-file temp-content] | ||
(->> (assoc node-dep | ||
:version "7.0.0" | ||
:file temp-file) | ||
(upgrade/upgrader) | ||
(dep.circle-ci/extract-deps "")))] | ||
(t/is (= #{{:name "circleci/node" :version {:- "6.3.0" :+ "7.0.0"}}} | ||
(h/diff-deps from-deps to-deps)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: 2.1 | ||
|
||
orbs: | ||
node: circleci/[email protected] | ||
docker: circleci/[email protected] |