diff --git a/src/antq/upgrade/github_action.clj b/src/antq/upgrade/github_action.clj index 4d0111e9..e456efc7 100644 --- a/src/antq/upgrade/github_action.clj +++ b/src/antq/upgrade/github_action.clj @@ -1,5 +1,6 @@ (ns antq.upgrade.github-action (:require + [antq.constant.github-action :as const.gh-action] [antq.dep.github-action :as dep.gh-action] [antq.log :as log] [antq.upgrade :as upgrade] @@ -50,10 +51,15 @@ (defmethod upgrade-dep "DeLaGuardo/setup-clojure" [loc version-checked-dep] - (let [target-re (case (:name version-checked-dep) - "clojure/brew-install" #"cli\s*:" - "technomancy/leiningen" #"lein\s*:" - "boot-clj/boot" #"boot\s*:" + (let [target-re (condp = (:name version-checked-dep) + const.gh-action/setup-clojure-name #"cli\s*:" + const.gh-action/setup-leiningen-name #"lein\s*:" + const.gh-action/setup-boot-name #"boot\s*:" + const.gh-action/setup-babashka-name #"bb\s*:" + const.gh-action/setup-clj-kondo-name #"clj-kondo\s*:" + const.gh-action/setup-cljfmt-name #"cljfmt\s*:" + const.gh-action/setup-cljstyle-name #"cljstyle\s*:" + const.gh-action/setup-zprint-name #"zprint\s*:" nil)] (if-not target-re (log/error (format "%s: Unexpected name for setup-clojure" diff --git a/test/antq/upgrade/github_action/third_party.clj b/test/antq/upgrade/github_action/third_party.clj new file mode 100644 index 00000000..80ac6659 --- /dev/null +++ b/test/antq/upgrade/github_action/third_party.clj @@ -0,0 +1,89 @@ +(ns antq.upgrade.github-action.third-party + (:require + [antq.constant.github-action :as const.gh-action] + [antq.dep.github-action :as dep.gha] + [antq.record :as r] + [antq.test-helper :as h] + [antq.upgrade :as upgrade] + [antq.upgrade.github-action] + [clojure.java.io :as io] + [clojure.test :as t])) + +(defn- map->Dependency + [m] + (-> (merge {:project :github-action + :type :github-tag + :latest-version "9.0.0" + :file (io/resource "dep/third-party/setup-clojure.yml") + :extra {const.gh-action/type-key "DeLaGuardo/setup-clojure"}} + m) + (r/map->Dependency))) + +(defn upgrading-diff + [dep] + (let [from-deps (->> (:file dep) + (slurp) + (dep.gha/extract-deps "")) + to-deps (->> (upgrade/upgrader dep) + (dep.gha/extract-deps ""))] + (h/diff-deps from-deps to-deps))) + +(t/deftest upgrade-setup-clojure-dep-test + (t/testing "Clojure CLI" + (t/is (= #{{:name const.gh-action/setup-clojure-name :version {:- 1 :+ "9.0.0"}} + {:name const.gh-action/setup-clojure-name :version {:- -1 :+ "9.0.0"}}} + (-> {:name const.gh-action/setup-clojure-name} + (map->Dependency) + (upgrading-diff))))) + + (t/testing "Leiningen" + (t/is (= #{{:name const.gh-action/setup-leiningen-name :version {:- 2 :+ "9.0.0"}} + {:name const.gh-action/setup-leiningen-name :version {:- -2 :+ "9.0.0"}}} + (-> {:name const.gh-action/setup-leiningen-name} + (map->Dependency) + (upgrading-diff))))) + + (t/testing "Boot" + (t/is (= #{{:name const.gh-action/setup-boot-name :version {:- 3 :+ "9.0.0"}} + {:name const.gh-action/setup-boot-name :version {:- -3 :+ "9.0.0"}}} + (-> {:name const.gh-action/setup-boot-name} + (map->Dependency) + (upgrading-diff))))) + + (t/testing "Babashka" + (t/is (= #{{:name const.gh-action/setup-babashka-name :version {:- 4 :+ "9.0.0"}} + {:name const.gh-action/setup-babashka-name :version {:- -4 :+ "9.0.0"}}} + (-> {:name const.gh-action/setup-babashka-name + :type :java} + (map->Dependency) + (upgrading-diff))))) + + (t/testing "clj-kondo" + (t/is (= #{{:name const.gh-action/setup-clj-kondo-name :version {:- 5 :+ "9.0.0"}} + {:name const.gh-action/setup-clj-kondo-name :version {:- -5 :+ "9.0.0"}}} + (-> {:name const.gh-action/setup-clj-kondo-name + :type :java} + (map->Dependency) + (upgrading-diff))))) + + (t/testing "cljfmt" + (t/is (= #{{:name const.gh-action/setup-cljfmt-name :version {:- 6 :+ "9.0.0"}} + {:name const.gh-action/setup-cljfmt-name :version {:- -6 :+ "9.0.0"}}} + (-> {:name const.gh-action/setup-cljfmt-name} + (map->Dependency) + (upgrading-diff))))) + + (t/testing "cljstyle" + (t/is (= #{{:name const.gh-action/setup-cljstyle-name :version {:- 7 :+ "9.0.0"}} + {:name const.gh-action/setup-cljstyle-name :version {:- -7 :+ "9.0.0"}}} + (-> {:name const.gh-action/setup-cljstyle-name} + (map->Dependency) + (upgrading-diff))))) + + (t/testing "zprint" + (t/is (= #{{:name const.gh-action/setup-zprint-name :version {:- 8 :+ "9.0.0"}} + {:name const.gh-action/setup-zprint-name :version {:- -8 :+ "9.0.0"}}} + (-> {:name const.gh-action/setup-zprint-name + :type :java} + (map->Dependency) + (upgrading-diff)))))) diff --git a/test/antq/upgrade/github_action_test.clj b/test/antq/upgrade/github_action_test.clj index 44571b6c..8a620f87 100644 --- a/test/antq/upgrade/github_action_test.clj +++ b/test/antq/upgrade/github_action_test.clj @@ -25,30 +25,6 @@ :latest-version "v9.0.0" :file (io/resource "dep/test_github_action.yml")})) -(def ^:private dummy-clojure-cli-dep - (r/map->Dependency {:project :github-action - :type :github-tag - :name "clojure/brew-install" - :latest-version "9.0.0" - :file (io/resource "dep/test_github_action_third_party.yml") - :extra {const.gh-action/type-key "DeLaGuardo/setup-clojure"}})) - -(def ^:private dummy-leiningen-dep - (r/map->Dependency {:project :github-action - :type :github-tag - :name "technomancy/leiningen" - :latest-version "9.0.0" - :file (io/resource "dep/test_github_action_third_party.yml") - :extra {const.gh-action/type-key "DeLaGuardo/setup-clojure"}})) - -(def ^:private dummy-boot-dep - (r/map->Dependency {:project :github-action - :type :github-tag - :name "boot-clj/boot" - :latest-version "9.0.0" - :file (io/resource "dep/test_github_action_third_party.yml") - :extra {const.gh-action/type-key "DeLaGuardo/setup-clojure"}})) - (def ^:private dummy-clj-kondo-dep (r/map->Dependency {:project :github-action :type :java @@ -95,40 +71,6 @@ (t/is (nil? (upgrade/upgrader dummy-not-supported-dep))))) (t/deftest upgrade-third-party-dep-test - (t/testing "clojure" - (t/testing "clojure cli" - (let [from-deps (->> (:file dummy-clojure-cli-dep) - (slurp) - (dep.gha/extract-deps "")) - to-deps (->> dummy-clojure-cli-dep - (upgrade/upgrader) - (dep.gha/extract-deps ""))] - (t/is (= #{{:name "clojure/brew-install" :version {:- 1 :+ "9.0.0"}} - {:name "clojure/brew-install" :version {:- -1 :+ "9.0.0"}}} - (h/diff-deps from-deps to-deps))))) - - (t/testing "leiningen" - (let [from-deps (->> (:file dummy-leiningen-dep) - (slurp) - (dep.gha/extract-deps "")) - to-deps (->> dummy-leiningen-dep - (upgrade/upgrader) - (dep.gha/extract-deps ""))] - (t/is (= #{{:name "technomancy/leiningen" :version {:- 2 :+ "9.0.0"}} - {:name "technomancy/leiningen" :version {:- -2 :+ "9.0.0"}}} - (h/diff-deps from-deps to-deps))))) - - (t/testing "boot" - (let [from-deps (->> (:file dummy-boot-dep) - (slurp) - (dep.gha/extract-deps "")) - to-deps (->> dummy-boot-dep - (upgrade/upgrader) - (dep.gha/extract-deps ""))] - (t/is (= #{{:name "boot-clj/boot" :version {:- 3 :+ "9.0.0"}} - {:name "boot-clj/boot" :version {:- -3 :+ "9.0.0"}}} - (h/diff-deps from-deps to-deps)))))) - (t/testing "clj-kondo" (let [from-deps (->> (:file dummy-clj-kondo-dep) (slurp) diff --git a/test/resources/dep/test_github_action_third_party.yml b/test/resources/dep/test_github_action_third_party.yml index 0ffde0a2..3b07bb00 100644 --- a/test/resources/dep/test_github_action_third_party.yml +++ b/test/resources/dep/test_github_action_third_party.yml @@ -4,12 +4,6 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: DeLaGuardo/setup-clojure@master - with: - cli: 1 - lein: 2 - boot: 3 - bb: 4 - uses: DeLaGuardo/setup-clj-kondo@master with: version: '5' @@ -20,13 +14,6 @@ jobs: with: cljstyle-version: "7" - - name: with name - uses: DeLaGuardo/setup-clojure@master - with: - cli: -1 - lein: -2 - boot: -3 - bb: -4 - name: with name uses: DeLaGuardo/setup-clj-kondo@master with: diff --git a/test/resources/dep/third-party/setup-clojure.yml b/test/resources/dep/third-party/setup-clojure.yml new file mode 100644 index 00000000..4383f46e --- /dev/null +++ b/test/resources/dep/third-party/setup-clojure.yml @@ -0,0 +1,28 @@ +name: dummy +on: [push] +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: DeLaGuardo/setup-clojure@master + with: + cli: 1 + lein: 2 + boot: 3 + bb: 4 + clj-kondo: 5 + cljfmt: 6 + cljstyle: 7 + zprint: 8 + + - name: with name + uses: DeLaGuardo/setup-clojure@master + with: + cli: -1 + lein: -2 + boot: -3 + bb: -4 + clj-kondo: -5 + cljfmt: -6 + cljstyle: -7 + zprint: -8