-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a GitHub action that will run Fulcro Demo with each of the supported databases and verify that it actually runs. It also verified that cljs compiles.
- Loading branch information
Showing
7 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: smoke-test | ||
|
||
on: | ||
- pull_request | ||
#- push # for testing only | ||
|
||
permissions: read-all | ||
|
||
jobs: | ||
smoke-test: | ||
name: App smoke test | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
# NOTE: if sql is removed then update the `if` condition of 'Verify ClojureScript compiles' | ||
db_deps_alias: [sql, asami, xtdb] # datomic TODO add after we solve access to dev-local datomic .jar | ||
steps: | ||
|
||
- name: Cache All The Things | ||
uses: actions/cache@v2 | ||
with: | ||
# TODO /opt/hostedtoolcache or ${{ RUNNER_TOOL_CACHE }} ? bb is downloaded here <> reset cache on version change | ||
path: | | ||
~/.m2/repository | ||
~/.gitlibs | ||
~/.clojure | ||
~/.cpcache | ||
/opt/hostedtoolcache | ||
**/node_modules | ||
key: ${{ runner.os }}-${{ hashFiles('**/deps.edn','**/yarn.lock') }} | ||
- uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'adopt' | ||
java-version: 11 | ||
- name: Setup Clojure | ||
uses: DeLaGuardo/[email protected] | ||
with: | ||
cli: '1.11.1.1208' | ||
# TODO Find out how to cache bb; see https://github.com/turtlequeue/setup-babashka/issues/15 | ||
- name: Setup Babashka | ||
uses: turtlequeue/[email protected] | ||
with: | ||
babashka-version: 1.0.169 | ||
|
||
- uses: actions/checkout@v2 | ||
- uses: bahmutov/npm-install@v1 | ||
- name: Babashka version | ||
run: bb --version | ||
- name: Verify ClojureScript compiles | ||
if: matrix.db_deps_alias == 'sql' # so that we only run this once | ||
run: bb compile-cljs | ||
- name: Run the actual smoke test | ||
env: | ||
DB_DEPS_ALIAS: ${{ matrix.db_deps_alias }} | ||
run: bb run --prn smoke-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{:paths ["." "smoke-test.bb"] | ||
:tasks {compile-cljs (shell "npx shadow-cljs compile main") | ||
smoke-test {:doc "Start the app, run smoke test" | ||
:task (load-file "./smoke-test.bb")}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
(ns smoke-test | ||
"Check that Demo is running, we can log in, and list accounts" | ||
(:require [babashka.wait :as wait] | ||
[babashka.process :as p] | ||
[cognitect.transit :as transit] | ||
[org.httpkit.client :as http])) | ||
|
||
(def sigterm-exit-code "JVM exits with this when it gets SIGTERM from p/delete-tree" 143) | ||
(def ok-exitcode? #{0 sigterm-exit-code}) | ||
|
||
(defn transit-str [data] | ||
(with-open [out (java.io.ByteArrayOutputStream.)] | ||
(let [writer (transit/writer out :json nil #_{:handlers nil})] | ||
(transit/write writer data) | ||
(.toString out "UTF-8")))) | ||
|
||
(defn parse-transit-str [text] | ||
(transit/read | ||
(transit/reader (java.io.ByteArrayInputStream. (.getBytes text "UTF-8")) | ||
:json {:handlers nil}))) | ||
|
||
(defn try-slurp [f] | ||
(try (slurp f) | ||
(catch Exception e | ||
(println "Warning: Failed to slurp" e) | ||
nil))) | ||
|
||
(def db-deps-alias | ||
(doto (System/getenv "DB_DEPS_ALIAS") | ||
(assert "Missing env var DB_DEPS_ALIAS"))) | ||
|
||
(println "Starting the server for" db-deps-alias "...") | ||
(def server-process (p/process {:shutdown p/destroy-tree | ||
;; TODO It seems the exit-fn is never called?! | ||
:exit-fn (fn [{:keys [exit err out] :as resp}] | ||
(if (ok-exitcode? exit) | ||
(println "Server exited OK, out:" | ||
(slurp out)) | ||
(do | ||
(println "Server failed with code" exit | ||
(slurp out) "\n" (slurp err)) | ||
(System/exit exit))))} | ||
(format "clojure -X:%s:dev development/cli-start" db-deps-alias))) | ||
|
||
(def success? (atom false)) | ||
|
||
(try | ||
|
||
(println "Waiting for the server to start...") | ||
(assert (not= (wait/wait-for-port "localhost" 3000 {:timeout 60000 :default ::timeout}) | ||
::timeout) | ||
"Timeout waiting for the server to start") | ||
(println "OK, server is running") | ||
|
||
(def res1 | ||
@(http/post "http://localhost:3000/api" | ||
{:as :text | ||
:headers {"Content-Type" "application/transit+json"} | ||
:body (transit-str | ||
'[{(com.example.model.account/login | ||
{:username "[email protected]", :password "letmein"}) [*]}])})) | ||
|
||
(assert (= 200 (:status res1)) (str "Expected 200, got " res1)) | ||
(println "OK, managed to log in") | ||
|
||
(def res2 | ||
(-> | ||
@(http/post "http://localhost:3000/api" | ||
{:as :text | ||
:headers {"Content-Type" "application/transit+json"} | ||
:body (transit-str '[{:account/all-accounts [:account/id :account/name]}])}) | ||
(select-keys [:status :body]))) | ||
|
||
(assert (= 200 (:status res2)) (str "Expected 200, got " res2)) | ||
|
||
(let [resp-data (parse-transit-str (:body res2))] | ||
(assert (sequential? (:account/all-accounts resp-data)) | ||
(str "Expected an accounts list, got " resp-data)) | ||
;; NOTE The list may be empty if seed!, which runs async, has not finished yet | ||
(println "OK, managed to list accounts:" (count (:account/all-accounts resp-data)))) | ||
|
||
(reset! success? true) | ||
(finally | ||
(p/destroy-tree server-process) | ||
(let [{:keys [exit out err]} @server-process | ||
out (not-empty (try-slurp out)), err (not-empty (try-slurp err)) | ||
problem? (or (not @success?) (not (ok-exitcode? exit)))] | ||
(when problem? | ||
(println "Server OUT:" out (when err (str "\nERR: " err))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters