Skip to content

Commit 68c7242

Browse files
committed
feat: introduce deps.edn (#164)
fix: tests in main flow
1 parent 43bd502 commit 68c7242

File tree

16 files changed

+268
-89
lines changed

16 files changed

+268
-89
lines changed

.github/workflows/flow.yml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
13+
- name: Install Clojure tools
14+
uses: DeLaGuardo/setup-clojure@10.3
15+
with:
16+
cli: latest
1317
- name: Install dependencies
14-
run: lein deps
15-
- name: Run Clojure Tests
16-
run: lein test
17-
- name: Run Java Tests
18-
run: lein pom && mvn test --batch-mode --fail-at-end
18+
run: make prepare
19+
- name: Run Tests
20+
run: make clj-test java-test
1921
coverage:
2022
needs: build
2123
runs-on: ubuntu-latest
2224
steps:
2325
- uses: actions/checkout@v2
26+
- name: Install Clojure tools
27+
uses: DeLaGuardo/setup-clojure@10.3
28+
with:
29+
cli: latest
2430
- name: Coverage
25-
run: lein coverage
31+
run: make coverage
2632
- name: Codecov
2733
uses: codecov/codecov-action@v2
2834
with:
@@ -33,13 +39,20 @@ jobs:
3339
runs-on: ubuntu-latest
3440
steps:
3541
- uses: actions/checkout@v2
36-
- name: Install dependencies
37-
run: lein deps
42+
- name: Install Clojure tools
43+
uses: DeLaGuardo/setup-clojure@10.3
44+
with:
45+
cli: latest
46+
- name: Create jar and pom files
47+
run: /
48+
make prepare jar
49+
&& cp ./target/classes/META-INF/maven/io.github.erdos/stencil-core/pom.xml ./pom.xml
50+
&& cp ./target/stencil-core-*.jar ./stencil-core.jar
3851
- name: Release Clojars
3952
env:
40-
CLOJARS_USER: ${{ secrets.CLOJARS_USER }}
41-
CLOJARS_PASS: ${{ secrets.CLOJARS_PASS }}
42-
run: lein deploy snapshots || echo skipping
53+
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USER }}
54+
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASS }}
55+
run: clojure -X:deploy || echo skipping
4356
docker_push:
4457
needs: clojars_push
4558
runs-on: ubuntu-latest

.github/workflows/gh-pages.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ jobs:
2525
steps:
2626
- name: Checkout
2727
uses: actions/checkout@v3
28-
- name: Compile uberjar
29-
run: lein uberjar
28+
- name: Install Clojure tools
29+
uses: DeLaGuardo/setup-clojure@10.3
30+
with:
31+
cli: latest
3032
- name: Run javadoc tool
31-
run: mkdir -p _site/javadoc && javadoc -d _site/javadoc --source-path ./java-src -cp target/stencil-core-*-standalone.jar -subpackages io.github.erdos.stencil
33+
run: mkdir _site && make javadoc && cp -R target/javadoc _site
3234
- name: Setup Pages
3335
uses: actions/configure-pages@v3
3436
- name: Build with Jekyll

.github/workflows/pr_flow.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
15-
- name: Install dependencies
16-
run: lein deps
17-
- name: Compile Java
18-
run: lein javac
15+
- name: Install Clojure tools
16+
uses: DeLaGuardo/setup-clojure@10.3
17+
with:
18+
cli: latest
1919
- name: Coverage
20-
run: lein coverage
20+
run: make coverage
2121
- name: Codecov
2222
uses: codecov/codecov-action@v2
2323
with:
2424
token: ${{ secrets.CODECOV_TOKEN }}
2525
files: ./target/coverage/codecov.json
26-
- name: Run Java Tests
27-
run: lein pom && mvn test --batch-mode --fail-at-end
28-
- name: Unit tests in Clojure
29-
run: lein test
26+
- name: Run unit tests
27+
run: make clj-test java-test
3028
- name: Test Report
3129
uses: dorny/test-reporter@v1
3230
if: success() || failure()

.github/workflows/pr_visual_flow.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ jobs:
1717
run: sudo apt-get update && sudo apt-get install -y libreoffice-core libreoffice-writer libreoffice-java-common imagemagick ghostscript --no-install-recommends
1818
- name: Set PDF Policy
1919
run: sudo sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
20-
- name: Install dependencies
21-
run: lein deps
22-
- name: Compile Java
23-
run: lein javac
20+
- name: Install Clojure tools
21+
uses: DeLaGuardo/setup-clojure@10.3
22+
with:
23+
cli: latest
2424
- name: Test Clojure
25-
run: lein test stencil.visual-test
25+
run: make visual-test
2626
- name: Archive diff png
2727
uses: actions/upload-artifact@v3
2828
if: failure()
@@ -35,5 +35,5 @@ jobs:
3535
if: success() || failure()
3636
with:
3737
name: Visual Tests
38-
path: target/visual-reports/*.xml
38+
path: target/surefire-reports/*.xml
3939
reporter: java-junit

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ junit.xml
2121
.lsp/
2222
*.jfr
2323
.clj-kondo/
24-
/_site/
24+
/_site/
25+
.cpcache/

Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.PHONY: clean prepare lint pom jar uberjar javadoc compile clj-test java-test visual-test coverage test all
2+
.DEFAULT_GOAL := all
3+
4+
clean:
5+
clojure -T:build clean
6+
7+
prepare:
8+
clojure -P
9+
10+
lint: clean
11+
clojure -M:lint/clj-kondo
12+
13+
pom: clean
14+
clojure -T:build pom
15+
16+
jar: clean
17+
clojure -T:build jar
18+
19+
uberjar: clean
20+
clojure -T:build uber
21+
22+
javadoc: clean
23+
clojure -T:build javadoc
24+
25+
compile: clean prepare
26+
clojure -T:build compile-java
27+
28+
clj-test: clean compile
29+
clojure -M:test
30+
31+
java-test: clean
32+
clojure -T:build java-test
33+
34+
visual-test: clean compile
35+
clojure -M:test --focus stencil.visual-test
36+
37+
coverage: clean prepare compile
38+
clojure -M:coverage
39+
40+
test: clean prepare compile clj-test java-test visual-test
41+
42+
all: clean compile lint test javadoc uberjar

build.clj

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
(ns build
2+
(:require [clojure.tools.build.api :as b]
3+
[clojure.tools.build.util.file :as file]))
4+
5+
(def build-folder "target")
6+
(def jar-content (str build-folder "/classes"))
7+
(def javadoc-dir "target/javadoc")
8+
9+
(def basis (b/create-basis {:project "deps.edn"}))
10+
11+
(def version (-> basis :aliases :stencil/version (doto assert)))
12+
13+
(def lib 'io.github.erdos/stencil-core)
14+
15+
(def jar-file-name (format "%s/%s-%s.jar" build-folder (name lib) version))
16+
(def uber-file-name (format "%s/%s-%s-standalone.jar" build-folder (name lib) version))
17+
18+
(defn clean [opts]
19+
(b/delete {:path build-folder})
20+
(println (format "Build folder \"%s\" removed" build-folder))
21+
opts)
22+
23+
(defn compile-java [opts]
24+
(clean opts)
25+
(println :should-compile-java-here)
26+
(b/javac {:src-dirs ["java-src"]
27+
:basis basis
28+
:class-dir jar-content
29+
:javac-opts ["-source" "8" "-target" "8"]})
30+
(b/copy-file {:src "java-src/io/github/erdos/stencil/standalone/help.txt"
31+
:target "target/classes/io/github/erdos/stencil/standalone/help.txt"})
32+
(spit (str jar-content "/stencil-version") version)
33+
opts)
34+
35+
(defn javadoc [opts]
36+
(file/ensure-dir javadoc-dir)
37+
(let [src-dirs ["java-src"]
38+
args ["-d" javadoc-dir]
39+
java-files (mapcat #(file/collect-files (b/resolve-path %) :collect (file/suffixes ".java")) src-dirs)
40+
args (into args (map str) java-files)
41+
tool (javax.tools.ToolProvider/getSystemDocumentationTool)
42+
exit (.run tool nil nil nil (into-array String args))]
43+
(if (zero? exit)
44+
opts
45+
(throw (ex-info "Javadoc command error" {:exit exit})))))
46+
47+
(defn pom [opts]
48+
(println "Generating pom.xml file")
49+
(b/write-pom
50+
{:class-dir jar-content
51+
:basis basis
52+
:version version
53+
:lib lib
54+
:pom-data
55+
[[:licenses
56+
[:license
57+
[:name "Eclipse Public License - v 2.0"]
58+
[:url "https://www.eclipse.org/legal/epl-2.0/"]
59+
[:distribution "repo"]]]]})
60+
opts)
61+
62+
(defn jar [opts]
63+
(clean opts)
64+
(compile-java opts)
65+
(pom opts)
66+
(b/copy-dir {:src-dirs ["src"] :target-dir jar-content})
67+
(b/jar {:class-dir jar-content
68+
:jar-file jar-file-name})
69+
(println "Built JAR file")
70+
opts)
71+
72+
(defn java-test [_]
73+
(def basis (b/create-basis {:project "deps.edn" :aliases [:junit]}))
74+
75+
(println "Running Java test cases")
76+
(println "- compiling java sources")
77+
(b/javac {:src-dirs ["java-src" "java-test"]
78+
:basis basis
79+
:class-dir jar-content
80+
:javac-opts ["-source" "8" "-target" "8"]})
81+
(println "- compiling clj sources")
82+
(b/compile-clj {:basis basis
83+
:src-dirs ["src"]
84+
:class-dir jar-content
85+
:bindings {#'*warn-on-reflection* true}})
86+
(-> {:basis basis
87+
:main "org.junit.platform.console.ConsoleLauncher"
88+
:main-args ["-p" "io.github.erdos.stencil"
89+
"--fail-if-no-tests"
90+
"--reports-dir=target/surefire-reports"]}
91+
(b/java-command)
92+
(b/process)
93+
(#(when-not (zero? (:exit %)) (throw (ex-info "junit error" %)))))
94+
(println "Done"))
95+
96+
(defn uber [opts]
97+
(jar opts)
98+
(b/uber {:class-dir jar-content
99+
:uber-file uber-file-name
100+
:basis basis
101+
:main 'io.github.erdos.stencil.Main})
102+
(println (format "Uber file created: \"%s\"" uber-file-name))
103+
opts)
104+
105+
(defn install [opts]
106+
(jar opts)
107+
(b/install {:basis basis
108+
:lib lib
109+
:version version
110+
:class-dir jar-content
111+
:jar-file jar-file-name})
112+
opts)

deps.edn

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{:deps {org.clojure/clojure {:mvn/version "1.11.1"}
2+
org.clojure/data.xml {:mvn/version "0.2.0-alpha8"}
3+
org.slf4j/slf4j-api {:mvn/version "2.0.9"}}
4+
:paths ["src" "target/classes"]
5+
:aliases
6+
{:stencil/version "0.5.10-SNAPSHOT"
7+
8+
:build
9+
{:deps {org.clojure/clojure {:mvn/version "1.12.0-beta1"}
10+
io.github.clojure/tools.build {:git/tag "v0.10.5" :git/sha "2a21b7a"}}
11+
:ns-default build}
12+
13+
:junit
14+
{:extra-deps {junit/junit {:mvn/version "4.13.2"}
15+
org.slf4j/slf4j-simple {:mvn/version "1.7.32"}
16+
org.junit.platform/junit-platform-console-standalone {:mvn/version "1.10.3"}}
17+
:extra-paths ["target/classes" "test-resources"]}
18+
19+
:lint/clj-kondo
20+
{:extra-deps {clj-kondo/clj-kondo {:mvn/version "2024.05.24"}}
21+
:main-opts ["-m" "clj-kondo.main" "--lint" "src"]}
22+
23+
:coverage
24+
{:extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}}
25+
:extra-paths ["test" "test-resources"]
26+
:main-opts ["-m" "cloverage.coverage"
27+
"--codecov"
28+
"--exclude-call" "clojure.core/assert"
29+
"--exclude-call" "stencil.util/trace"
30+
"--exclude-call" "stencil.util/fail"
31+
"--exclude-call" "clojure.spec.alpha/def"
32+
"-p" "src" "-s" "test"]}
33+
34+
:test
35+
{:extra-paths ["test" "test-resources"]
36+
:extra-deps {lambdaisland/kaocha {:mvn/version "1.87.1366"}
37+
lambdaisland/kaocha-junit-xml {:mvn/version "1.17.101"}
38+
org.slf4j/slf4j-simple {:mvn/version "1.7.32"}}
39+
:main-opts ["-e" "(require 'stencil.api 'stencil.process 'stencil.model) ((requiring-resolve 'stencil.spec/instrument))"
40+
"-m" "kaocha.runner"
41+
"--plugin" "kaocha.plugin/junit-xml"
42+
"--junit-xml-file" "target/surefire-reports/kaocha.xml"]
43+
:jvm-opts ["-Dorg.slf4j.simpleLogger.defaultLogLevel=debug"]}
44+
45+
:deploy
46+
{:extra-deps {slipset/deps-deploy {:mvn/version "0.2.2"}}
47+
:exec-fn deps-deploy.deps-deploy/deploy
48+
:exec-args {:installer :remote
49+
:sign-releases? false ;; TODO for later
50+
:artifact "stencil-core.jar"}}}}

docs/Standalone.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ It may also be easier if your application's architecture is not written in java.
55

66
## Building
77

8-
Build the project with the `lein uberjar` command to get a standalone application. The built output will be found in the `target` directory.
8+
Build the project with the `make uberjar` command to get a standalone application. The built output will be found in the `target` directory.
99

1010
Run the file with the `java -jar *-standalone.jar` command.
1111

0 commit comments

Comments
 (0)