diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e63e5e6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: Example workflow + +on: [push] + +jobs: + + clojure: + + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + + # It is important to install java before installing clojure tools which needs java + # exclusions: babashka, clj-kondo and cljstyle + - name: Prepare java + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: '8' + + - name: Install clojure tools + uses: DeLaGuardo/setup-clojure@10.0 + with: + bb: latest + + # Optional step: + - name: Cache clojure dependencies + uses: actions/cache@v3 + with: + path: | + ~/.m2/repository + ~/.gitlibs + ~/.deps.clj + # List all files containing dependencies: + key: cljdeps-${{ hashFiles('deps.edn') }} + # key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }} + # key: cljdeps-${{ hashFiles('project.clj') }} + # key: cljdeps-${{ hashFiles('build.boot') }} + restore-keys: cljdeps- + + - name: Test Clojure + run: bb test:jvm + + - name: Test bb + run: bb test:bb diff --git a/.gitignore b/.gitignore index c7cdb2a..f0d45f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .cache .cpcache +test/out diff --git a/bb.edn b/bb.edn index ed0478b..e64312e 100644 --- a/bb.edn +++ b/bb.edn @@ -3,8 +3,6 @@ :task (api/quickdoc {:git/branch "main" :github/repo "https://github.com/borkdude/quickdoc" :toc true})} - test {:requires ([quickdoc.api :as api]) - :task (api/quickdoc {:git/branch "main" - :source-uri "https://dev.azure.com/company/_git/project?path={filename}&version=GBmain&_a=contents&line={row}&lineEnd={end-row}&lineStartColumn={col}&lineEndColumn={end-col}&lineStyle=plain" - :toc true - :outfile "API.md"})}}} + test:bb {:extra-paths ["test"] + :task (exec 'runner/run-tests)} + test:jvm {:task (clojure "-Sdeps" '{:paths ["src" "test"]} "-X" 'runner/run-tests)}}} diff --git a/deps.edn b/deps.edn index ccd9a31..81e522d 100644 --- a/deps.edn +++ b/deps.edn @@ -1 +1,3 @@ -{:paths ["src"]} +{:paths ["src"] + :deps {clj-kondo/clj-kondo {:mvn/version "2022.10.05"}} + :tools/usage {:ns-default quickdoc.api}} diff --git a/jvm/deps.edn b/jvm/deps.edn index 83ef510..fa71cea 100644 --- a/jvm/deps.edn +++ b/jvm/deps.edn @@ -1,4 +1,2 @@ -{:deps {;; only necessary for JVM usage - use :exclusions [clj-kondo/clj-kondo] - io.github.borkdude/quickdoc-sources {:local/root ".."} - clj-kondo/clj-kondo {:mvn/version "2022.10.05"}} +{:deps {io.github.borkdude/quickdoc-sources {:local/root ".."}} :tools/usage {:ns-default quickdoc.api}} diff --git a/src/quickdoc/api.cljc b/src/quickdoc/api.cljc index eaa6563..64c806c 100644 --- a/src/quickdoc/api.cljc +++ b/src/quickdoc/api.cljc @@ -3,7 +3,8 @@ (:require #?(:bb [babashka.pods :as pods] :clj [clj-kondo.core :as clj-kondo]) - [quickdoc.impl :as impl])) + [quickdoc.impl :as impl] + [clojure.java.io :as io])) #?(:bb (or (try (requiring-resolve 'pod.borkdude.clj-kondo/run!) @@ -72,5 +73,6 @@ (sort-by first nss))) docs (str toc docs)] (when outfile + (io/make-parents outfile) (spit outfile docs)) {:markdown docs})) diff --git a/test-resources/source.clj b/test-resources/source.clj new file mode 100644 index 0000000..733f4a1 --- /dev/null +++ b/test-resources/source.clj @@ -0,0 +1,5 @@ +(ns source) + +(defn foo + "Hello" + []) diff --git a/test/quickdoc/api_test.clj b/test/quickdoc/api_test.clj new file mode 100644 index 0000000..fe13649 --- /dev/null +++ b/test/quickdoc/api_test.clj @@ -0,0 +1,16 @@ +(ns quickdoc.api-test + (:require + [clojure.string :as str] + [clojure.test :as t :refer [deftest is testing]] + [quickdoc.api :as api])) + +(deftest foo-test + (testing "source link template" + (api/quickdoc {:git/branch "main" + :source-uri "https://dev.azure.com/company/_git/project?path={filename}&version=GBmain&_a=contents&line={row}&lineEnd={end-row}&lineStartColumn={col}&lineEndColumn={end-col}&lineStyle=plain" + :toc true + :source-paths ["test-resources/source.clj"] + :outfile "test/out/API.md"}) + (let [out (slurp "test/out/API.md")] + (is (str/includes? out + "https://dev.azure.com/company/_git/project?path=test-resources/source.clj&version=GBmain&_a=contents&line=3&lineEnd=5&lineStartColumn=1&lineEndColumn=6&lineStyle=plain"))))) diff --git a/test/runner.clj b/test/runner.clj new file mode 100644 index 0000000..7bf79d7 --- /dev/null +++ b/test/runner.clj @@ -0,0 +1,9 @@ +(ns runner + (:require + [clojure.test] + [quickdoc.api-test])) + +(defn run-tests [_] + (let [{:keys [fail error]} (clojure.test/run-tests 'quickdoc.api-test)] + (when (pos? (+ fail error)) + (System/exit 1))))