Fix tests, remove accidental babashka code dependency, & add CI config (#45)
* Update clojure CLI flags in script/test * Throw error when not one of version or path ...with qualified symbol pod-spec * Fix some minor formatting issues * Check for new error message in pod-registry test * Add a test for resolve fn in edn data readers * Add CI config * Try using clojure tools-deps image in CI * Check for new error message in sci pod-registry test * Use latest version of buddy in pod-registry test ...for more platform support * Stop depending on babashka Instead accept an arg for the thing we were getting from it (location of the bb.edn file) * Save maven deps in cache in CI
This commit is contained in:
parent
f2cfdff899
commit
842ff34739
10 changed files with 82 additions and 35 deletions
28
.circleci/config.yml
Normal file
28
.circleci/config.yml
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
version: 2.1
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
docker:
|
||||||
|
- image: clojure:openjdk-11-tools-deps-1.10.3.1087-slim-bullseye
|
||||||
|
working_directory: ~/repo
|
||||||
|
environment:
|
||||||
|
LEIN_ROOT: "true"
|
||||||
|
BABASHKA_PLATFORM: linux
|
||||||
|
resource_class: large
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- restore_cache:
|
||||||
|
keys:
|
||||||
|
- v1-dependencies-{{ checksum "deps.edn" }}
|
||||||
|
# fallback to using latest cache if no exact match is found
|
||||||
|
- v1-dependencies-
|
||||||
|
- run: |
|
||||||
|
script/test
|
||||||
|
- save_cache:
|
||||||
|
paths:
|
||||||
|
- ~/.m2
|
||||||
|
key: v1-dependencies-{{ checksum "deps.edn" }}
|
||||||
|
workflows:
|
||||||
|
version: 2
|
||||||
|
ci:
|
||||||
|
jobs:
|
||||||
|
- test
|
||||||
17
script/test
17
script/test
|
|
@ -8,24 +8,25 @@ export BABASHKA_POD_TEST_SOCKET
|
||||||
# format = edn
|
# format = edn
|
||||||
BABASHKA_POD_TEST_FORMAT=edn
|
BABASHKA_POD_TEST_FORMAT=edn
|
||||||
echo "Testing edn"
|
echo "Testing edn"
|
||||||
clojure -A:test -n babashka.pods.jvm-test
|
clojure -M:test -n babashka.pods.jvm-test
|
||||||
clojure -A:sci:test -n babashka.pods.sci-test
|
clojure -M:sci:test -n babashka.pods.sci-test
|
||||||
|
clojure -M:test -n babashka.pods.impl-test
|
||||||
|
|
||||||
# format = json
|
# format = json
|
||||||
BABASHKA_POD_TEST_FORMAT=json
|
BABASHKA_POD_TEST_FORMAT=json
|
||||||
echo "Testing json"
|
echo "Testing json"
|
||||||
clojure -A:test -n babashka.pods.jvm-test
|
clojure -M:test -n babashka.pods.jvm-test
|
||||||
clojure -A:sci:test -n babashka.pods.sci-test
|
clojure -M:sci:test -n babashka.pods.sci-test
|
||||||
|
|
||||||
# format = json
|
# format = json
|
||||||
BABASHKA_POD_TEST_FORMAT="transit+json"
|
BABASHKA_POD_TEST_FORMAT="transit+json"
|
||||||
echo "Testing transit"
|
echo "Testing transit"
|
||||||
clojure -A:test -n babashka.pods.jvm-test
|
clojure -M:test -n babashka.pods.jvm-test
|
||||||
clojure -A:sci:test -n babashka.pods.sci-test
|
clojure -M:sci:test -n babashka.pods.sci-test
|
||||||
|
|
||||||
# socket = true
|
# socket = true
|
||||||
unset BABASHKA_POD_TEST_FORMAT
|
unset BABASHKA_POD_TEST_FORMAT
|
||||||
BABASHKA_POD_TEST_SOCKET=true
|
BABASHKA_POD_TEST_SOCKET=true
|
||||||
echo "Testing socket"
|
echo "Testing socket"
|
||||||
clojure -A:test -n babashka.pods.jvm-test
|
clojure -M:test -n babashka.pods.jvm-test
|
||||||
clojure -A:sci:test -n babashka.pods.sci-test
|
clojure -M:sci:test -n babashka.pods.sci-test
|
||||||
|
|
|
||||||
|
|
@ -315,6 +315,11 @@
|
||||||
(println (str/join " " (map pr-str strs)))))
|
(println (str/join " " (map pr-str strs)))))
|
||||||
|
|
||||||
(defn resolve-pod [pod-spec {:keys [:version :path :force] :as opts}]
|
(defn resolve-pod [pod-spec {:keys [:version :path :force] :as opts}]
|
||||||
|
(when (qualified-symbol? pod-spec)
|
||||||
|
(when (and (not version) (not path))
|
||||||
|
(throw (IllegalArgumentException. "Version or path must be provided")))
|
||||||
|
(when (and version path)
|
||||||
|
(throw (IllegalArgumentException. "You must provide either version or path, not both"))))
|
||||||
(let [resolved (when (and (qualified-symbol? pod-spec) version)
|
(let [resolved (when (and (qualified-symbol? pod-spec) version)
|
||||||
(resolver/resolve pod-spec version force))
|
(resolver/resolve pod-spec version force))
|
||||||
opts (if resolved
|
opts (if resolved
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
(defn- unroot-resource [^String path]
|
(defn- unroot-resource [^String path]
|
||||||
(symbol (.. path
|
(symbol (.. path
|
||||||
(substring 1)
|
(substring 1)
|
||||||
(replace \/ \. )
|
(replace \/ \.)
|
||||||
(replace \_ \-))))
|
(replace \_ \-))))
|
||||||
|
|
||||||
(defn- process-namespace [{:keys [:name :vars]}]
|
(defn- process-namespace [{:keys [:name :vars]}]
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@
|
||||||
(:require [babashka.pods.impl :as impl]
|
(:require [babashka.pods.impl :as impl]
|
||||||
[sci.core :as sci]
|
[sci.core :as sci]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[babashka.pods.impl.resolver :as resolver]
|
[babashka.pods.impl.resolver :as resolver])
|
||||||
[babashka.impl.common :as common])
|
|
||||||
(:import (java.io PushbackInputStream File)))
|
(:import (java.io PushbackInputStream File)))
|
||||||
|
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
@ -25,44 +24,47 @@
|
||||||
(string? var-value)
|
(string? var-value)
|
||||||
(sci/eval-string* ctx var-value))))))
|
(sci/eval-string* ctx var-value))))))
|
||||||
|
|
||||||
(defn metadata-cache-file ^File [pod-spec {:keys [:version :path]}]
|
(defn metadata-cache-file ^File [^File bb-edn-file pod-spec {:keys [:version :path]}]
|
||||||
(if version
|
(if version
|
||||||
(io/file (resolver/cache-dir {:pod/name pod-spec :pod/version version})
|
(io/file (resolver/cache-dir {:pod/name pod-spec :pod/version version})
|
||||||
"metadata.cache")
|
"metadata.cache")
|
||||||
(let [bb-edn-file (-> @common/bb-edn :file io/file)
|
(let [config-dir (.getParentFile bb-edn-file)
|
||||||
config-dir (.getParentFile bb-edn-file)
|
|
||||||
cache-dir (io/file config-dir ".babashka")
|
cache-dir (io/file config-dir ".babashka")
|
||||||
pod-file (-> path io/file .getName)
|
pod-file (-> path io/file .getName)
|
||||||
cache-file (io/file cache-dir (str pod-file ".metadata.cache"))]
|
cache-file (io/file cache-dir (str pod-file ".metadata.cache"))]
|
||||||
cache-file)))
|
cache-file)))
|
||||||
|
|
||||||
(defn load-metadata-from-cache [pod-spec opts]
|
(defn load-metadata-from-cache [bb-edn-file pod-spec opts]
|
||||||
(let [cache-file (metadata-cache-file pod-spec opts)]
|
(let [cache-file (metadata-cache-file bb-edn-file pod-spec opts)]
|
||||||
(when (.exists cache-file)
|
(when (.exists cache-file)
|
||||||
(with-open [r (PushbackInputStream. (io/input-stream cache-file))]
|
(with-open [r (PushbackInputStream. (io/input-stream cache-file))]
|
||||||
(impl/read r)))))
|
(impl/read r)))))
|
||||||
|
|
||||||
(defn load-pod-metadata* [pod-spec {:keys [:version :cache] :as opts}]
|
(defn load-pod-metadata* [bb-edn-file pod-spec {:keys [:version :cache] :as opts}]
|
||||||
(let [metadata (impl/load-pod-metadata pod-spec opts)
|
(let [metadata (impl/load-pod-metadata pod-spec opts)
|
||||||
cache-file (when cache (metadata-cache-file pod-spec opts))]
|
cache-file (when cache (metadata-cache-file bb-edn-file pod-spec opts))]
|
||||||
(when cache-file
|
(when cache-file
|
||||||
(io/make-parents cache-file)
|
(io/make-parents cache-file)
|
||||||
(with-open [w (io/output-stream cache-file)]
|
(with-open [w (io/output-stream cache-file)]
|
||||||
(impl/write w metadata)))
|
(impl/write w metadata)))
|
||||||
metadata))
|
metadata))
|
||||||
|
|
||||||
(defn load-pod-metadata [pod-spec {:keys [:cache] :as opts}]
|
(defn load-pod-metadata
|
||||||
(let [metadata
|
([pod-spec opts] (load-pod-metadata nil pod-spec opts))
|
||||||
(if-let [cached-metadata (when cache
|
([bb-edn-file pod-spec {:keys [:cache] :as opts}]
|
||||||
(load-metadata-from-cache pod-spec opts))]
|
(let [metadata
|
||||||
cached-metadata
|
(if-let [cached-metadata (when cache
|
||||||
(load-pod-metadata* pod-spec opts))]
|
(load-metadata-from-cache bb-edn-file
|
||||||
(reduce
|
pod-spec
|
||||||
(fn [pod-namespaces ns]
|
opts))]
|
||||||
(let [ns-sym (-> ns (get "name") impl/bytes->string symbol)]
|
cached-metadata
|
||||||
(assoc pod-namespaces ns-sym {:pod-spec pod-spec
|
(load-pod-metadata* bb-edn-file pod-spec opts))]
|
||||||
:opts (assoc opts :metadata metadata)})))
|
(reduce
|
||||||
{} (get metadata "namespaces"))))
|
(fn [pod-namespaces ns]
|
||||||
|
(let [ns-sym (-> ns (get "name") impl/bytes->string symbol)]
|
||||||
|
(assoc pod-namespaces ns-sym {:pod-spec pod-spec
|
||||||
|
:opts (assoc opts :metadata metadata)})))
|
||||||
|
{} (get metadata "namespaces")))))
|
||||||
|
|
||||||
(defn load-pod
|
(defn load-pod
|
||||||
([ctx pod-spec] (load-pod ctx pod-spec nil))
|
([ctx pod-spec] (load-pod ctx pod-spec nil))
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,6 @@
|
||||||
|
|
||||||
(defn -main [& args]
|
(defn -main [& args]
|
||||||
#_(binding [*out* *err*]
|
#_(binding [*out* *err*]
|
||||||
(prn :args args))
|
(prn :args args))
|
||||||
(when (= "true" (System/getenv "BABASHKA_POD"))
|
(when (= "true" (System/getenv "BABASHKA_POD"))
|
||||||
(run-pod (set args))))
|
(run-pod (set args))))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
(require '[babashka.pods :as pods])
|
(require '[babashka.pods :as pods])
|
||||||
|
|
||||||
(pods/load-pod 'org.babashka/buddy "0.0.1")
|
(pods/load-pod 'org.babashka/buddy "0.1.0")
|
||||||
|
|
||||||
(require '[pod.babashka.buddy.codecs :as codecs]
|
(require '[pod.babashka.buddy.codecs :as codecs]
|
||||||
'[pod.babashka.buddy.hash :as hash])
|
'[pod.babashka.buddy.hash :as hash])
|
||||||
|
|
@ -8,4 +8,4 @@
|
||||||
(println (-> (hash/sha256 "foobar")
|
(println (-> (hash/sha256 "foobar")
|
||||||
(codecs/bytes->hex)))
|
(codecs/bytes->hex)))
|
||||||
|
|
||||||
(pods/load-pod 'org.babashka/etaoin) ;; should cause error when version is missing
|
(pods/load-pod 'org.babashka/etaoin) ;; should cause error when version & path are missing
|
||||||
|
|
|
||||||
11
test/babashka/pods/impl_test.clj
Normal file
11
test/babashka/pods/impl_test.clj
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
(ns babashka.pods.impl-test
|
||||||
|
(:require [clojure.test :refer :all]
|
||||||
|
[babashka.pods.impl :refer :all]))
|
||||||
|
|
||||||
|
(deftest load-pod-test
|
||||||
|
(testing "resolve fn gets called when pod has EDN data readers"
|
||||||
|
(let [resolved? (atom false)
|
||||||
|
test-resolve (fn [_sym]
|
||||||
|
(reset! resolved? true))]
|
||||||
|
(load-pod ["clojure" "-M:test-pod"] {:resolve test-resolve})
|
||||||
|
(is @resolved?))))
|
||||||
|
|
@ -25,4 +25,4 @@
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
e)))]
|
e)))]
|
||||||
(is (str/includes? (str out) "c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2"))
|
(is (str/includes? (str out) "c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2"))
|
||||||
(is (str/includes? (pr-str ex) "Version must be provided" ))))
|
(is (str/includes? (pr-str ex) "Version or path must be provided"))))
|
||||||
|
|
|
||||||
|
|
@ -36,4 +36,4 @@
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
e)))]
|
e)))]
|
||||||
(is (str/includes? (str out) "c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2"))
|
(is (str/includes? (str out) "c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2"))
|
||||||
(is (str/includes? (pr-str ex) "Version must be provided" ))))
|
(is (str/includes? (pr-str ex) "Version or path must be provided"))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue