Skip to content

Commit

Permalink
GH action to run all jvm & bb tests on [mac,ubuntu,win]x[jdk8,11,17] (#…
Browse files Browse the repository at this point in the history
…65)

Co-authored-by: ikappaki <[email protected]>
  • Loading branch information
ikappaki and ikappaki authored Oct 16, 2022
1 parent 959477b commit 864d6c5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 17 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: CI

on: [push, pull_request]

jobs:
test-and-maybe-uberjar:
# Runs the JVM and babashka tests across all OSs and JDKs, and
# creates an uberjar when the OS and JDK matches the UBERJAR_OS
# and UBERJAR_JDK env variables respectively.
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
jdk: [8, 11, 17]
env:
UBERJAR_OS: 'ubuntu'
UBERJAR_JDK: 8

runs-on: ${{matrix.os}}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Prepare java ${{ matrix.jdk }}
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ matrix.jdk }}

- name: Install Clojure
uses: DeLaGuardo/[email protected]
with:
bb: '0.10.163'
cli: '1.10.3.1013'
lein: '2.9.10'

- name: Cache clojure dependencies
uses: actions/cache@v3
with:
path: |
~/.m2/repository
~/.gitlibs
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn', 'project.clj') }}
restore-keys: cljdeps-

- name: Run JVM tests
run: bb jvm-test

- name: Run babashka tests
run: bb babashka-test

- name: Create ubejar
if: "startsWith (matrix.os, env.UBERJAR_OS) && env.UBERJAR_JDK == matrix.jdk"
run: |
mkdir -p /tmp/release
lein do clean, uberjar
VERSION=$(cat resources/DEPS_CLJ_VERSION)
cp target/deps.clj-$VERSION-standalone.jar /tmp/release
- name: Upload artifacts
if: "startsWith (matrix.os, env.UBERJAR_OS) && env.UBERJAR_JDK == matrix.jdk"
uses: actions/upload-artifact@v2
with:
name: release
path: /tmp/release/
if-no-files-found: error
27 changes: 10 additions & 17 deletions test/borkdude/deps_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
[clojure.string :as str]
[clojure.test :as t :refer [deftest is testing]]))

;; Print out information about the java executable that will be used
;; by deps.clj, useful for user validation.
(let [java (#'deps/get-java-cmd)
version (-> (process [java "-version"] {:err :string})
check
:err str/split-lines first)]
(println :deps.clj/java :path (pr-str java) :version version))

(defn invoke-deps-cmd
"Returns the command string that can be used to invoke the
`borkdude.deps/-main` fn with the given ARGS from the command line.
Expand Down Expand Up @@ -81,17 +89,6 @@
{:exit-code exit-code# :msg msg#}))))]
(deps/-main ~@command-line-args)))

(defn java-major-version-get
"Returns the major version number of the java executable used to run
the java command at run time."
[]
(-> (process [(#'deps/get-java-cmd) "-version"] {:err :string})
check
:err
(->> (re-find #"version \"(\d+)"))
second
Integer/parseInt))

(deftest whitespace-test
(testing "jvm opts"
(let [temp-dir (fs/create-temp-dir)
Expand All @@ -103,18 +100,14 @@
out (slurp temp-file-path)]
(is (= "foo bar" out))))
(testing "main opts"
(let [java-major-version (java-major-version-get)
temp-dir (fs/create-temp-dir)
(let [temp-dir (fs/create-temp-dir)
temp-file (fs/create-file (fs/path temp-dir "temp.txt"))
temp-file-path (str temp-file)
_ (deps-main-throw "-Sdeps"
(format
(if-not deps/windows?
"{:aliases {:space {:main-opts [\"-e\" \"(spit \\\"%s\\\" (+ 1 2 3))\"]}}}"

(if (< java-major-version 17)
"{:aliases {:space {:main-opts [\"-e\" \"(spit \\\\\"%s\\\\\" (+ 1 2 3))\"]}}}"
"{:aliases {:space {:main-opts [\"-e\" \"(spit \\\"\\\\\"%s\\\"\\\\\" (+ 1 2 3))\"]}}}"))
"{:aliases {:space {:main-opts [\"-e\" \"(spit \\\\\"%s\\\\\" (+ 1 2 3))\"]}}}")
(.toURI (fs/file temp-file-path)))
"-M:space")
out (slurp temp-file-path)]
Expand Down

0 comments on commit 864d6c5

Please sign in to comment.