From 864d6c5d511182621ae198c74385dbdb1eafff17 Mon Sep 17 00:00:00 2001 From: ikappaki <34983288+ikappaki@users.noreply.github.com> Date: Sun, 16 Oct 2022 16:29:20 +0100 Subject: [PATCH] GH action to run all jvm & bb tests on [mac,ubuntu,win]x[jdk8,11,17] (#65) Co-authored-by: ikappaki --- .github/workflows/test.yml | 66 +++++++++++++++++++++++++++++++++++++ test/borkdude/deps_test.clj | 27 ++++++--------- 2 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c55bd70 --- /dev/null +++ b/.github/workflows/test.yml @@ -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/setup-clojure@9.5 + 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 diff --git a/test/borkdude/deps_test.clj b/test/borkdude/deps_test.clj index ae9466d..0c0e5b5 100644 --- a/test/borkdude/deps_test.clj +++ b/test/borkdude/deps_test.clj @@ -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. @@ -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) @@ -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)]