Compare commits
2 Commits
0c2c5954ba
...
1109c5a965
| Author | SHA1 | Date | |
|---|---|---|---|
| 1109c5a965 | |||
| e7e270d1ec |
@@ -18,17 +18,6 @@ jobs:
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
|
||||
# Install Leiningen
|
||||
- name: Install Leiningen
|
||||
run: |
|
||||
curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > lein
|
||||
chmod +x lein
|
||||
sudo mv lein /usr/local/bin/lein
|
||||
|
||||
# Install dependencies
|
||||
- name: Install dependencies
|
||||
run: lein deps
|
||||
|
||||
# Optional: cache dependencies
|
||||
- name: Cache dependencias
|
||||
@@ -40,20 +29,20 @@ jobs:
|
||||
${{ runner.os }}-m2-
|
||||
|
||||
# Get leiningen's version
|
||||
- name: Get leiningen version
|
||||
run: lein -v
|
||||
- name: Get clojure version
|
||||
run: clojure --version
|
||||
|
||||
# Test the code
|
||||
- name: Run tests
|
||||
env:
|
||||
TFT_API: ${{ secrets.DEV_API }}
|
||||
run: lein test
|
||||
#- name: Run tests
|
||||
# env:
|
||||
# TFT_API: ${{ secrets.DEV_API }}
|
||||
# run: lein test
|
||||
|
||||
# Send jar to repository
|
||||
- name: Deploy on Gitea Maven
|
||||
if: github.ref == 'refs/heads/main'
|
||||
env:
|
||||
GITEA_USER: ${{ secrets.DEPLOY_USER }}
|
||||
GITEA_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
||||
run: |
|
||||
lein deploy gitea
|
||||
#- name: Deploy on Gitea Maven
|
||||
# if: github.ref == 'refs/heads/main'
|
||||
# env:
|
||||
# GITEA_USER: ${{ secrets.DEPLOY_USER }}
|
||||
# GITEA_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
||||
# run: |
|
||||
# lein deploy gitea
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -9,8 +9,7 @@ pom.xml.asc
|
||||
/.lein-*
|
||||
/.nrepl-port
|
||||
/.prepl-port
|
||||
.hgignore
|
||||
.hg/
|
||||
.cpcache
|
||||
.clj-kondo
|
||||
.lsp
|
||||
.calva
|
||||
|
||||
176
build.clj
Normal file
176
build.clj
Normal file
@@ -0,0 +1,176 @@
|
||||
(ns build
|
||||
(:refer-clojure :exclude [test])
|
||||
(:require [clojure.tools.build.api :as b]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.pprint :as pp]
|
||||
[clojure.java.basis :as basis]))
|
||||
|
||||
(def lib-group "es.rcorral")
|
||||
(def artifact-prefix "clj-totp")
|
||||
(def subprojs-base "projects")
|
||||
(def curr-version (format "2.0.%s" (b/git-count-revs nil)))
|
||||
|
||||
|
||||
;; Builds artifact's full descriptor for each subproject
|
||||
(defn lib [subproj]
|
||||
(symbol (str lib-group "/" artifact-prefix "-" subproj )))
|
||||
|
||||
|
||||
;; Basis for each subproject, using their own deps.edn
|
||||
;; Injects :extra-deps from :build as additional dependencies
|
||||
(defn basis [subproj]
|
||||
(delay (b/create-basis {:project (str subprojs-base "/" subproj "/deps.edn")
|
||||
;; Inject extra deps as deps
|
||||
:extra {:deps (get-in (basis/initial-basis) [:aliases :build :extra-deps])}
|
||||
})))
|
||||
|
||||
|
||||
;; Show basis generated for a subproject
|
||||
#_{:clojure-lsp/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn show-basis [subproj]
|
||||
(println (with-out-str
|
||||
(pp/pprint
|
||||
@(basis subproj)
|
||||
;(basis/initial-basis)
|
||||
))))
|
||||
|
||||
(comment
|
||||
(pp/pprint (keys (basis/initial-basis)))
|
||||
(pp/pprint (:deps (basis/initial-basis)))
|
||||
(pp/pprint (:libs (basis/initial-basis)))
|
||||
(pp/pprint (sort (keys (:aliases (basis/initial-basis)))))
|
||||
(get-in (basis/initial-basis) [:aliases :build :extra-deps])
|
||||
)
|
||||
|
||||
;; Target dir for each subproject
|
||||
(defn target-dir [subproj]
|
||||
(str "target/" subproj))
|
||||
|
||||
|
||||
;; Path for compiled classes
|
||||
(defn class-dir [subproj]
|
||||
(str (target-dir subproj) "/" "classes"))
|
||||
|
||||
|
||||
;; Jar file for each subproject. :uber type adds -standalone suffix
|
||||
(defn jar-file [subproj version type]
|
||||
(format "target/%s-%s-%s%s.jar" artifact-prefix subproj version
|
||||
(if (= type :uber) "-standalone" "")))
|
||||
|
||||
|
||||
;; Clean target dir for subproject
|
||||
(defn clean [{:keys [subproj]}]
|
||||
(b/delete {:path (target-dir subproj)})
|
||||
(println "Project" subproj "cleaned"))
|
||||
|
||||
|
||||
;; Compile java classes, only if java subdir exists
|
||||
(defn compile-java [{:keys [subproj]}]
|
||||
(let [java-dir (str subprojs-base "/" subproj "/java")]
|
||||
(if (.exists (io/file java-dir))
|
||||
(do
|
||||
(println "Compiling java code for" subproj)
|
||||
(b/javac {:src-dirs [java-dir]
|
||||
:class-dir (class-dir subproj)
|
||||
:basis @(basis subproj)
|
||||
:javac-opts ["-source" "11" "--target" "11" "-proc:none"]}))
|
||||
(println "Java dir" java-dir "not found"))))
|
||||
|
||||
|
||||
;; Create a jar file
|
||||
(defn jar
|
||||
"Build a simple jar file, with no dependencies included."
|
||||
[{:keys [subproj version]
|
||||
:or {version curr-version}}]
|
||||
(let [target-dir (target-dir subproj)
|
||||
class-dir (class-dir subproj)
|
||||
src-dir (str subprojs-base "/" subproj "/src")
|
||||
resources-dir (str subprojs-base "/" subproj "/resources")
|
||||
basis (basis subproj)
|
||||
jar-file (jar-file subproj version :plain)]
|
||||
;; Clean only class dir
|
||||
(b/delete {:path class-dir})
|
||||
;; Copy code
|
||||
(b/copy-dir {:src-dirs [src-dir]
|
||||
:target-dir class-dir})
|
||||
;; Copy resources
|
||||
(b/copy-dir {:src-dirs [resources-dir]
|
||||
:target-dir target-dir})
|
||||
;; Compile java code, if exists
|
||||
(compile-java {:subproj subproj})
|
||||
;; Build jar
|
||||
(b/jar {:class-dir class-dir
|
||||
:basis @basis
|
||||
:jar-file jar-file
|
||||
:lib (lib subproj)
|
||||
:version version})
|
||||
(println "Generated jar file:" jar-file)))
|
||||
|
||||
|
||||
;; Create an uber jar, with all dependencies inside
|
||||
#_{:clojure-lsp/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn uber
|
||||
"Build a uberjar with all dependencies included"
|
||||
[{:keys [subproj version main-ns]
|
||||
:or {version curr-version}}]
|
||||
(let [target-dir (target-dir subproj)
|
||||
basis (basis subproj)
|
||||
class-dir (class-dir subproj)
|
||||
src-dir (str subprojs-base "/" subproj "/src")
|
||||
resources-dir (str subprojs-base "/" subproj "/resources")
|
||||
uber-file (jar-file subproj version :uber)]
|
||||
;(println "Using basis: ")(show-basis subproj)
|
||||
(b/delete {:path class-dir})
|
||||
(b/copy-dir {:src-dirs [src-dir]
|
||||
:target-dir class-dir})
|
||||
(b/copy-dir {:src-dirs [resources-dir]
|
||||
:target-dir target-dir})
|
||||
(compile-java {:subproj subproj})
|
||||
(b/compile-clj {:basis @basis
|
||||
:src-dirs [src-dir] :class-dir class-dir})
|
||||
(b/uber {:class-dir class-dir
|
||||
:uber-file uber-file
|
||||
:basis @basis
|
||||
:main main-ns})
|
||||
(println "Generated uberjar executable:" uber-file)))
|
||||
|
||||
|
||||
;; Multimethod to get the name of all subdirs in a dir.
|
||||
;; Accepts strings or files
|
||||
(defmulti get-subdirs type)
|
||||
|
||||
(defmethod get-subdirs
|
||||
java.lang.String [dir]
|
||||
(get-subdirs (io/file dir)))
|
||||
|
||||
(defmethod get-subdirs
|
||||
java.io.File [dir]
|
||||
(if (.isDirectory dir)
|
||||
(filter #(.isDirectory %) (.listFiles dir))
|
||||
(println "Directory" subprojs-base "doesn't exists!")))
|
||||
|
||||
|
||||
;; Get the name of all subdir in a given directory
|
||||
(defn get-subdir-names
|
||||
"Get a list projects in the 'projects' directory"
|
||||
[dir-name]
|
||||
(map #(.getName %) (get-subdirs dir-name)))
|
||||
|
||||
(comment
|
||||
(get-subdirs "projects")
|
||||
(get-subdirs (io/file "projects"))
|
||||
(get-subdir-names "projects")
|
||||
)
|
||||
|
||||
|
||||
;; Generate jar files for all projects
|
||||
(defn jar-all
|
||||
"Build jar files for all projects"
|
||||
[& {:keys [version]
|
||||
:or {version curr-version}}]
|
||||
(dorun (map #(jar {:subproj % :version version}) (get-subdir-names subprojs-base))))
|
||||
|
||||
(comment
|
||||
(jar-all )
|
||||
|
||||
)
|
||||
51
deps.edn
Executable file
51
deps.edn
Executable file
@@ -0,0 +1,51 @@
|
||||
{:paths ["projects/core/src"
|
||||
"projects/core/resources"
|
||||
"projects/cli/src"]
|
||||
|
||||
:deps {org.clojure/clojure {:mvn/version "1.12.1"}
|
||||
;; Local subprojects
|
||||
clj-tmpl/core {:local/root "projects/core"}
|
||||
clj-tmpl/cli {:local/root "projects/cli"}
|
||||
}
|
||||
|
||||
:aliases {;; Execute the app.
|
||||
:run {:main-opts ["-m" "riot.app"]}
|
||||
;:run {:exec-fn totp.app/-main}
|
||||
|
||||
;; Execute the app (prepared for more subprojects)
|
||||
:run/cli {:main-opts ["-m" "riot.app"]}
|
||||
|
||||
;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
||||
;; Check test.edn for kaocha runner's config
|
||||
:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}
|
||||
lambdaisland/kaocha-cloverage {:mvn/version "1.1.89"}}
|
||||
:main-opts ["-m" "kaocha.runner"]}
|
||||
|
||||
;; Run with clj -T:build function-in-build
|
||||
:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||
;; Used by all compilations
|
||||
:extra-deps {clj-tmpl/core {:local/root "projects/core"}}
|
||||
:ns-default build}
|
||||
|
||||
;; Aliases for easy building
|
||||
:build/core {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||
:ns-default build
|
||||
:exec-fn jar
|
||||
:exec-args {:subproj "core"}}
|
||||
|
||||
:build/cli {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||
:ns-default build
|
||||
:exec-fn jar
|
||||
:exec-args {:subproj "cli"}}
|
||||
|
||||
;; Build all projects
|
||||
:build/all {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||
:ns-default build
|
||||
:exec-fn jar-all}
|
||||
|
||||
;; Build uber jar for CLI app
|
||||
:uber/cli {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||
:ns-default build
|
||||
:exec-fn uber
|
||||
:exec-args {:subproj "cli" :main-ns "riot.app"}}}}
|
||||
|
||||
8
projects/cli/deps.edn
Executable file
8
projects/cli/deps.edn
Executable file
@@ -0,0 +1,8 @@
|
||||
{:paths ["src" "resources" "target/classes"]
|
||||
:deps {org.clojure/clojure {:mvn/version "1.12.1"}
|
||||
cli-matic/cli-matic {:mvn/version "0.5.4"} ;; https://github.com/l3nz/cli-matic
|
||||
}
|
||||
:aliases {;; Execute the app
|
||||
;:run {:main-opts ["-m" "totp.app"]}
|
||||
}}
|
||||
|
||||
9
projects/cli/src/riot/app.clj
Normal file
9
projects/cli/src/riot/app.clj
Normal file
@@ -0,0 +1,9 @@
|
||||
(ns riot.app
|
||||
#_{:clj-kondo/ignore [:refer-all]}
|
||||
(:require [riot.core :refer :all])
|
||||
(:gen-class))
|
||||
|
||||
(def cli-options {})
|
||||
|
||||
(defn -main [& args]
|
||||
(greeting-emisor (generate-greeting :high "Juan")))
|
||||
8
projects/core/deps.edn
Executable file
8
projects/core/deps.edn
Executable file
@@ -0,0 +1,8 @@
|
||||
{:paths ["src" "resources" "target/classes"]
|
||||
:deps {org.clojure/clojure {:mvn/version "1.12.1"}}
|
||||
|
||||
:aliases {;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
||||
:test {:extra-paths ["test"]
|
||||
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
|
||||
:main-opts ["-m" "kaocha.runner"]}}}
|
||||
|
||||
21
projects/core/src/riot/core.clj
Normal file
21
projects/core/src/riot/core.clj
Normal file
@@ -0,0 +1,21 @@
|
||||
(ns riot.core
|
||||
;(:import [riot.core Hello])
|
||||
)
|
||||
|
||||
(def ^:private byte-array-type (type (.getBytes "")))
|
||||
|
||||
(def enphasis #{:low :medium :high})
|
||||
|
||||
(defn generate-greeting
|
||||
[enphasis person]
|
||||
(let [first-part (case enphasis
|
||||
:low "Oh, eh, hi"
|
||||
:medium "Hello"
|
||||
:high "Greetings, I love to see you here"
|
||||
"Hi")]
|
||||
(str first-part " " person)))
|
||||
|
||||
(defn greeting-emisor
|
||||
[greeting]
|
||||
(println greeting)
|
||||
)
|
||||
10
projects/core/test/riot/core_test.clj
Normal file
10
projects/core/test/riot/core_test.clj
Normal file
@@ -0,0 +1,10 @@
|
||||
(ns riot.core-test
|
||||
#_{:clj-kondo/ignore [:refer-all]}
|
||||
(:require [clojure.test :refer :all]
|
||||
[tmpl.core :refer :all])
|
||||
(:import (java.util Arrays)))
|
||||
|
||||
(deftest generate-greeting-test
|
||||
(testing "Some test cases"
|
||||
(is (generate-greeting nil nil)) ;; Not nill
|
||||
(is (= "Hello test" (generate-greeting :medium "test")))))
|
||||
6
tests.edn
Normal file
6
tests.edn
Normal file
@@ -0,0 +1,6 @@
|
||||
#kaocha/v1
|
||||
{:tests [{:test-paths ["projects/core/src" "projects/core/test"]}]
|
||||
:plugins [:kaocha.plugin/cloverage]
|
||||
:cloverage/opts {:src-ns-path ["projects/core/src" "projects/core/test"]
|
||||
:ns-regex ["tmpl\\..*(?<!test)$"] ;; All starting with "totp" but not ending by "test"
|
||||
}}
|
||||
Reference in New Issue
Block a user