Skip to content

Commit

Permalink
fix: Fix github action upgrader to support bb, clj-kondo, cljfmt, clj…
Browse files Browse the repository at this point in the history
…style, zprint on setup-clojure

cf. #248
  • Loading branch information
liquidz committed Feb 10, 2024
1 parent 02aaa04 commit badf6c9
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 75 deletions.
14 changes: 10 additions & 4 deletions src/antq/upgrade/github_action.clj
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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"
Expand Down
89 changes: 89 additions & 0 deletions test/antq/upgrade/github_action/third_party.clj
Original file line number Diff line number Diff line change
@@ -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))))))
58 changes: 0 additions & 58 deletions test/antq/upgrade/github_action_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 0 additions & 13 deletions test/resources/dep/test_github_action_third_party.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions test/resources/dep/third-party/setup-clojure.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit badf6c9

Please sign in to comment.