Skip to content

Commit

Permalink
Switch from lein to clojure tools cli
Browse files Browse the repository at this point in the history
Apologies to any lein lovers out there!

Reference to lein either converted to clojure cli or deleted.

- Figuring out how to call the official clojure distribution on Windows
is an exercise in frustration. Instead we use babashka's clojure function to
launch clojure. Works like a charm.
- Added new bb task to download clojure deps for CI
- Added an anemic pom.xml to preserve data previously held by project.clj.
This will be used by release flow once I get to clj-commons#432.
- Unlike lein, the clojure test-runner does not allow selection of tests
based on metadata at the namespace level. To easily distinguish unit tests I
moved them under a `unit` directory.
- I noticed that ide tests were failing for me.
This is because we are now testing with our documented minimum Clojure
version of 1.9. The ide code was taking advantage of a 1.10 feature.
Making it 1.9 compatible was an easy fix.
- Switched to logback for logging during for dev and testing to avoid
any log4j security concern stink.
- Noticed that we had `./resources/` `./env/dev/resources` and
`./env/test/resources`. But `resources/` contains only test resources, so I
moved it under `./env/test/resources`.  `./env/dev/resources` seems to
be a way to turn on debug logging, so left it as that and created a
deps.edn `:debug` alias for it.
- Our Makefile is getting smaller. Docker tasks now certainly broken.
I'll make a separate issue to deal with this (and move to bb tasks).

Helps me with clj-commons#380
Closes clj-commons#432
  • Loading branch information
lread committed May 22, 2022
1 parent f53a1c4 commit d773d90
Show file tree
Hide file tree
Showing 33 changed files with 162 additions and 130 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test

on:
push:
branches: ['master']
branches: ['lread-*']
pull_request:

jobs:
Expand All @@ -22,8 +22,8 @@ jobs:
~/.m2/repository
~/.deps.clj
~/.gitlibs
key: cljdeps-${{ hashFiles('project.clj, bb.edn') }}
restore-keys: ${{ runner.os }}-cljdeps-
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
restore-keys: cljdeps-

- name: "Setup Java"
uses: actions/setup-java@v3
Expand All @@ -35,13 +35,11 @@ jobs:
uses: DeLaGuardo/[email protected]
with:
bb: 'latest'
lein: 'latest'
cli: 'latest'

# This assumes downloaded deps are same for all OSes
- name: Bring down deps
run: |
lein deps
bb --version
run: bb download-deps

- id: set-tests
name: Set test var for matrix
Expand Down Expand Up @@ -69,8 +67,8 @@ jobs:
~/.m2/repository
~/.deps.clj
~/.gitlibs
key: cljdeps-${{ hashFiles('project.clj, bb.edn') }}
restore-keys: ${{ runner.os }}-cljdeps-
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
restore-keys: cljdeps-

- name: "Setup Java"
uses: actions/setup-java@v3
Expand All @@ -82,7 +80,6 @@ jobs:
uses: DeLaGuardo/[email protected]
with:
bb: 'latest'
lein: 'latest'

- name: Tools versions
run: bb tools-versions
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
Expand All @@ -23,3 +22,5 @@ build.xml
.cache
# VSCode Calva extension
/.calva
# Clojure tools cli classpath cache
/.cpcache
33 changes: 6 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@

repl:
lein repl

repl-1.9:
lein with-profile +1.9 repl

.PHONY: test
test:
lein test

orig:
find . -name '*.orig' -delete

.PHONY: tags
tags:
ctags -e -R ./src

deploy:
lein deploy clojars

.PHONY: release
release:
lein release
;; TODO: lread move to bb tasks

.PHONY: kill
kill:
Expand All @@ -30,9 +7,9 @@ kill:
pkill safaridriver || true
pkill phantomjs || true


IMAGE := etaoin

;; TODO: lread: have never tried, test, fix if necessary
.PHONY: docker-build
docker-build:
docker build --no-cache -t ${IMAGE}:latest .
Expand All @@ -43,6 +20,7 @@ check-host:
$(error The HOST variable is not set, please do `export HOST=$$HOST` first)
endif

;; TODO: lread: have never tried, test, fix if necessary
# works only on mac + quartz
.PHONY: docker-test-display
docker-test-display: check-host
Expand All @@ -51,12 +29,13 @@ docker-test-display: check-host
-v ${CURDIR}:/etaoin \
-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$(HOST):0 \
-w /etaoin ${IMAGE}:latest \
lein test || \
bb test all || \
xhost -

;; TODO: lread: have never tried, test, fix if necessary
.PHONY: docker-test
docker-test:
docker run --rm \
-v ${CURDIR}:/etaoin \
-w /etaoin ${IMAGE}:latest \
lein test
bb test all
14 changes: 8 additions & 6 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ You may run tests for this library by launching:

[source,bash]
----
lein test
bb test all
----

You'll see browser windows open and close in series.
Expand Down Expand Up @@ -1870,7 +1870,9 @@ Once an error occurs, you will find a PNG image that represents your browser pag

Since UI tests may take lots of time to pass, it's definitely a good practice to pass both server and UI tests independently from each other.

First, add `+^:integration+` tag to all the tests that are run inder the browser like follows:
If you are using lneiningen, here are a few tips.

First, add `+^:integration+` tag to all the tests that are run under the browser like follows:

[source,clojure]
----
Expand All @@ -1896,7 +1898,7 @@ To run integration tests, launch `lein test :integration`.
The main difference between a program and a human is that the first one operates very fast.
It means so fast, that sometimes a browser cannot render new HTML in time.
So after each action you need to put `wait-<something>` function that just polls a browser checking for a predicate.
O just `(wait <seconds>)` if you don't care about optimization.
Or just `(wait <seconds>)` if you don't care about optimization.

=== Check whether a file has been downloaded

Expand Down Expand Up @@ -1986,11 +1988,11 @@ Everything related to the IDE is stored under the `etaoin.ide` package.
=== CLI arguments

You may also run a script from the command line.
Here is the `lein run` example:
Here is a `clojure` example:

[source,shell]
----
lein run -m etaoin.ide.main -d firefox -p '{:port 8888 :args ["--no-sandbox"]}' -r ide/test.side
clojure -M -m etaoin.ide.main -d firefox -p '{:port 8888 :args ["--no-sandbox"]}' -r ide/test.side
----

As well as from an uberjar.
Expand All @@ -2001,7 +2003,7 @@ In this case, Etaoin must be in the primary dependencies, not the `:dev` or `:te
java -cp .../poject.jar -m etaoin.ide.main -d firefox -p '{:port 8888}' -f ide/test.side
----

We support the following arguments (check them out using the `lein run -m etaoin.ide.main -h` command):
We support the following arguments (check them out using the `clojure -M -m etaoin.ide.main -h` command):

----
-d, --driver-name name :chrome The name of driver. The default is `:chrome`
Expand Down
1 change: 1 addition & 0 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
:leave (let [{:keys [name]} (current-task)] (status/line :detail "\nTASK %s done." name))

;; commands
download-deps {:task download-deps/-main :doc "download all deps (useful for CI prep)"}
tools-versions {:task tools-versions/-main :doc "report on tools versions"}
test {:task test/-main :doc "run all or a subset of tests, use --help for args"}}}
14 changes: 14 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.9.0"} ;; min clojure version
babashka/fs {:mvn/version "0.1.6"}
clj-http/clj-http {:mvn/version "3.10.1"}
cheshire/cheshire {:mvn/version "5.9.0"}
org.clojure/tools.cli {:mvn/version "1.0.194"}
org.clojure/tools.logging {:mvn/version "0.3.1"}}
:aliases
{:1.11 {:replace-deps {org.clojure/clojure {:mvn/version "1.11.1"}}}
:debug {:extra-paths ["env/dev/resources"]}
:test {:extra-paths ["test" "env/test/resources"]
:extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}
ch.qos.logback/logback-classic {:mvn/version "1.3.0-alpha16"}}
:main-opts ["-m" "cognitect.test-runner"]}}}
5 changes: 0 additions & 5 deletions env/dev/resources/log4j.properties

This file was deleted.

19 changes: 19 additions & 0 deletions env/dev/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<configuration>
<!-- Stop output INFO at start -->
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %-5level %logger{36} - %message%n</pattern>
</encoder>
</appender>

<logger name="etaoin" level="debug" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>

<root level="info">
<appender-ref ref="STDOUT"/>
</root>

</configuration>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions env/test/resources/log4j.properties

This file was deleted.

19 changes: 19 additions & 0 deletions env/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<configuration>
<!-- Stop output INFO at start -->
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %-5level %logger{36} - %message%n</pattern>
</encoder>
</appender>

<logger name="etaoin" level="info" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>

<root level="info">
<appender-ref ref="STDOUT"/>
</root>

</configuration>
34 changes: 34 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>etaoin</name>
<description>Pure Clojure Webdriver protocol implementation</description>
<url>https://github.com/clj-commons/etaoin</url>
<licenses>
<license>
<name>Eclipse Public License</name>
<url>http://www.eclipse.org/legal/epl-v10.html</url>
</license>
</licenses>
<scm>
<url>https://github.com/clj-commons/etaoin</url>
<connection>scm:git:git://github.com/clj-commons/etaoin.git</connection>
<developerConnection>scm:git:ssh://[email protected]/clj-commons/etaoin.git</developerConnection>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>clojars</id>
<url>https://repo.clojars.org/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>clojars</id>
<name>Clojars repository</name>
<url>https://clojars.org/repo</url>
</repository>
</distributionManagement>
</project>
53 changes: 0 additions & 53 deletions project.clj

This file was deleted.

22 changes: 22 additions & 0 deletions script/download_deps.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(ns download-deps
(:require [clojure.edn :as edn]
[helper.main :as main]
[helper.shell :as shell]
[lread.status-line :as status]))

;; clojure has a -P command, but to bring down all deps we need to specify all aliases
;; bb deps will be brought down just from running bb (which assumedly is how this code is run)

(defn -main [& args]
(when (main/doc-arg-opt args)
(let [aliases (->> "deps.edn"
slurp
edn/read-string
:aliases
keys)]
;; one at a time because aliases with :replace-deps will... well... you know.
(status/line :detail "Bring down default deps")
(shell/clojure "-P")
(doseq [a aliases]
(status/line :detail "Bring down deps for alias: %s" a)
(shell/clojure "-P" (str "-M" a))))))
18 changes: 14 additions & 4 deletions script/helper/shell.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

(def default-opts {:error-fn
(fn die-on-error [{{:keys [exit cmd]} :proc}]
(status/die exit
"shell exited with %d for: %s"
exit
(with-out-str (pprint/pprint cmd))))})
(status/die exit
"exited with %d for: %s"
exit
(with-out-str (pprint/pprint cmd))))})

(defn command
"Thin wrapper on babashka.tasks/shell that on error, prints status error message and exits.
Expand All @@ -31,3 +31,13 @@
;; hence the secret exit sauce here
(str full-cmd ";exit $LASTEXITCODE") ))
(apply tasks/shell opts cmd args))))


(defn clojure
"Wrap tasks/clojure for my loud error reporting treatment"
[& args]
(let [[opts args] (if (map? (first args))
[(first args) (rest args)]
[nil args])
opts (merge opts default-opts)]
(apply tasks/clojure opts args)))
Loading

0 comments on commit d773d90

Please sign in to comment.