Skip to content

Commit 48500fb

Browse files
authored
ci: reduce build time (#247)
CI build times were extremely ridiculous; now, they are only somewhat ridiculous. * ci: optimize downloading clojure deps Do the work from build.clj to avoid repeated JVM launch costs. * ci: only install planck if job requires it Planck can take a while to install on CI Linux, so only install it if necessary. * lint fix: unsorted namespace * ci yaml fixes * ci: fix oopsie in libs tests typo resulted in running ALL libs test for each invidual lib job * ci: only npm if required by unit test Sometimes `npm ci` is zippy on ci, sometimes not. Skip it if not needed by particular unit test. * ci: run against all clj versions in a single job Clojure tests now hit all supported versions of Clojure in a single job. This reduces number of GitHub Actions jobs which will reduce job queuing which will reduce overall ci build time.
1 parent 8ffdf28 commit 48500fb

File tree

7 files changed

+58
-34
lines changed

7 files changed

+58
-34
lines changed

.github/workflows/libs-test.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ jobs:
3535
strategy:
3636
fail-fast: false
3737
matrix:
38-
lib: ${{ fromJSON(needs.enumerate-libs.outputs.libs) }}
38+
include: ${{ fromJSON(needs.enumerate-libs.outputs.libs) }}
39+
40+
name: ${{ matrix.lib-name }}
3941

4042
steps:
4143
- name: Checkout
@@ -46,11 +48,12 @@ jobs:
4648
- name: Setup
4749
uses: ./.github/workflows/shared-setup
4850
with:
49-
clj-cache-prefix: clj-libs-deps-${{ matrix.lib }}
51+
clj-cache-prefix: clj-libs-deps-${{ matrix.lib-name }}
5052
clj-cache-hash-files: "'script/test_libs.clj','deps.edn','bb.edn'"
5153

52-
- name: Install planck
54+
- name: Install Planck
5355
uses: ./.github/workflows/setup-planck
56+
if: contains( matrix.requires, 'planck' )
5457

5558
- name: Run Libs Tests
56-
run: bb test-libs run ${{ matrix.lib }}
59+
run: bb test-libs run ${{ matrix.lib-name }}

.github/workflows/unit-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,19 @@ jobs:
5757

5858
- name: Install Planck
5959
uses: ./.github/workflows/setup-planck
60-
if: matrix.os != 'windows'
60+
if: contains( matrix.requires, 'planck' )
6161

6262
- name: Node modules cache
6363
uses: actions/cache@v3
6464
with:
6565
path: ./node_modules
6666
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
6767
restore-keys: ${{ runner.os }}-node-
68+
if: contains( matrix.requires, 'npm' )
6869

6970
- name: Install node packages
7071
run: npm ci
72+
if: contains( matrix.requires, 'npm' )
7173

7274
- name: Run Tests
7375
run: ${{ matrix.cmd }}

build.clj

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(ns build
22
(:require [build-shared]
3-
[clojure.tools.build.api :as b]))
3+
[clojure.edn :as edn]
4+
[clojure.tools.build.api :as b]
5+
[clojure.tools.deps :as deps]))
46

57
(def version (build-shared/lib-version))
68
(def lib (build-shared/lib-artifact-name))
@@ -48,3 +50,18 @@
4850
{:installer :remote
4951
:artifact jar-file
5052
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}))
53+
54+
(defn download-deps
55+
"Download all deps for all aliases"
56+
[_]
57+
(let [aliases (->> "deps.edn"
58+
slurp
59+
edn/read-string
60+
:aliases
61+
keys)]
62+
;; one at a time because aliases with :replace-deps will... well... you know.
63+
(println "Bring down default deps")
64+
(deps/create-basis {})
65+
(doseq [a (sort aliases)]
66+
(println "Bring down deps for alias" a)
67+
(deps/create-basis {:aliases [a]}))))

script/ci_unit_tests.clj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
{:desc "import-vars" :cmd "bb apply-import-vars check" :oses all-oses :jdks ["8"]}
2828
{:desc "lint" :cmd "bb lint" :oses all-oses :jdks ["8"]}
2929
;; test-docs on default clojure version across all oses and jdks
30-
{:desc "test-doc" :cmd "bb test-doc" :oses all-oses :jdks all-jdks}]
31-
(for [version ["1.8" "1.9" "1.10" "1.11"]]
30+
{:desc "test-doc" :cmd "bb test-doc" :oses all-oses :jdks all-jdks
31+
:requires ["npm"]}]
32+
(for [version ["all"]]
3233
{:desc (str "clj-" version)
3334
:cmd (str "bb test-clj --clojure-version " version)
3435
:oses all-oses
@@ -43,23 +44,26 @@
4344
(when (:desc opt) (str "-" (:desc opt))))
4445
:cmd (str "bb test-cljs --env " (:param env) " --optimizations " (:param opt))
4546
:oses all-oses
46-
:jdks ["8"]})
47+
:jdks ["8"]
48+
:requires ["npm"]})
4749
;; shadow-cljs requires a min of jdk 11 so we'll test on that
4850
[{:desc "shadow-cljs" :cmd "bb test-shadow-cljs" :oses all-oses :jdks ["11"]
4951
:skip-reason-fn (fn [{:keys [jdk]}] (when (< (parse-long jdk) 11)
50-
"jdk must be >= 11"))}]
52+
"jdk must be >= 11"))
53+
:requires ["npm"]}]
5154
;; planck does not run on windows, and I don't think it needs a jdk
5255
[{:desc "cljs-bootstrap" :cmd "bb test-cljs --env planck --optimizations none"
53-
:oses ["macos" "ubuntu"] :jdks ["8"]}]))
56+
:oses ["macos" "ubuntu"] :jdks ["8"] :requires ["planck"]}]))
5457

5558
(defn- ci-test-matrix []
56-
(for [{:keys [desc cmd oses jdks]} (test-tasks)
59+
(for [{:keys [desc cmd oses jdks requires]} (test-tasks)
5760
os oses
5861
jdk jdks]
5962
{:desc (str desc " " os " jdk" jdk)
6063
:cmd cmd
6164
:os os
62-
:jdk jdk}))
65+
:jdk jdk
66+
:requires (or requires [])}))
6367

6468
(defn- local-test-list [local-os local-jdk]
6569
(for [{:keys [desc cmd oses skip-reason-fn]} (test-tasks)]
@@ -96,7 +100,7 @@ By default, will run all tests applicable to your current jdk and os.")
96100
(if (= "json" (get opts "--format"))
97101
(status/line :detail (json/generate-string matrix))
98102
(do
99-
(status/line :detail (doric/table [:os :jdk :desc :cmd] matrix))
103+
(status/line :detail (doric/table [:os :jdk :desc :cmd :requires] matrix))
100104
(status/line :detail "Total jobs found: %d" (count matrix)))))
101105
(let [cur-os (matrix-os)
102106
cur-jdk (jdk/version)

script/download_deps.clj

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
(ns download-deps
2-
(:require [babashka.tasks :as t]
3-
[clojure.edn :as edn]
4-
[lread.status-line :as status]))
2+
(:require [babashka.tasks :as t]))
53

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

97
(defn -main [& _args]
10-
(let [aliases (->> "deps.edn"
11-
slurp
12-
edn/read-string
13-
:aliases
14-
keys)]
15-
;; one at a time because aliases with :replace-deps will... well... you know.
16-
(status/line :detail "Bring down default deps")
17-
(t/clojure "-P")
18-
(doseq [a (sort aliases)]
19-
(status/line :detail "Bring down deps for alias: %s" a)
20-
(t/clojure "-P" (str "-M" a)))))
8+
;; do all the work from build.clj to avoid repeated JVM launch costs
9+
(t/clojure "-T:build download-deps"))

script/test_clj.clj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@
2828
(def args-usage "Valid args: [options]
2929
3030
Options:
31-
-v, --clojure-version VERSION Test with Clojure [1.8, 1.9, 1.10, 1.11] [default: 1.8]
31+
-v, --clojure-version VERSION Test with Clojure [1.8, 1.9, 1.10, 1.11 all] [default: 1.8]
3232
--help Show this help")
3333

3434
(defn -main [& args]
3535
(when-let [opts (main/doc-arg-opt args-usage args)]
3636
(let [clojure-version (get opts "--clojure-version")]
37-
(if (not (some #{clojure-version} allowed-clojure-versions))
37+
38+
(if (not (some #{clojure-version} (conj allowed-clojure-versions "all")))
3839
(status/die 1 args-usage)
39-
(do
40-
(run-unit-tests clojure-version)
41-
(run-isolated-tests clojure-version)))))
40+
(let [clojure-versions (if (= "all" clojure-version)
41+
allowed-clojure-versions
42+
[clojure-version])]
43+
(doseq [v clojure-versions]
44+
(run-unit-tests v)
45+
(run-isolated-tests v))))))
4246
nil)
4347

4448
(main/when-invoked-as-script

script/test_libs.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@
441441
:test-cmds ["clojure -M:cljtest"
442442
;; disable zprint cljs tests for now, see https://github.com/planck-repl/planck/issues/1088
443443
#_"clojure -M:cljs-runner"]
444+
;; :requires ["planck"] ;; re-enable when cljs tests are re-enabled
444445
:cleanup-fn zprint-cleanup}])
445446

446447
(defn- header [text]
@@ -558,7 +559,11 @@ Specifying no lib-names selects all libraries.")
558559
(cond
559560
(get opts "list")
560561
(if (= "json" (get opts "--format"))
561-
(status/line :detail (->> libs (map :name) json/generate-string))
562+
(status/line :detail (->> libs
563+
(map (fn [{:keys [name requires]}]
564+
{:lib-name name
565+
:requires (or requires [])}))
566+
json/generate-string))
562567
(status/line :detail (str "available libs: " (string/join " " (map :name libs)))))
563568

564569
:else

0 commit comments

Comments
 (0)