forked from clj-commons/rewrite-clj
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: rework unit tests (clj-commons#185)
Treat tests to run as data. Have GitHub Actions source its matrix from that data. This allows us more flexibility in adapting to changes (ex. shadow-cljs now requires >= jdk11) It greatly breaks down the granularity of tests. Although we might have gone a bit too far here? We'll see how elapsed ci times are affected and adapt as necessary. Although we are running many more GitHub Actions jobs, we are running fewer tests. For example, cljs tests are now only run under a single JDK instead of all JDKs. Linting tests are run under all oses (to make sure they will work for contributors, regardless of os) but under only a single JDK version and Clojure version. Also: I avoided the complexity of optimizing setup. Ex. we rarely need Planck but always install it. We only need npm setup for cljs but always set it up. Can add in that complexity at a later date if there is merit.
- Loading branch information
Showing
6 changed files
with
191 additions
and
50 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 |
---|---|---|
@@ -1,17 +1,56 @@ | ||
name: Unit Tests | ||
|
||
on: [push, pull_request] | ||
on: | ||
push: | ||
branches: ['main'] | ||
pull_request: | ||
|
||
jobs: | ||
setup: | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
tests: ${{ steps.set-tests.outputs.tests }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Clojure deps cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.m2/repository | ||
~/.deps.clj | ||
~/.gitlibs | ||
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }} | ||
restore-keys: cljdeps- | ||
|
||
- name: "Setup Java" | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '11' | ||
|
||
- name: Install Clojure Tools | ||
uses: DeLaGuardo/[email protected] | ||
with: | ||
cli: 'latest' | ||
bb: 'latest' | ||
|
||
- id: set-tests | ||
name: Set test var for matrix | ||
# run test.clj directly instead of via bb task to avoid generic task output | ||
run: echo "::set-output name=tests::$(bb script/ci_unit_tests.clj matrix-for-ci --format=json)" | ||
|
||
build: | ||
needs: setup | ||
runs-on: ${{ matrix.os }}-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ windows, ubuntu, macos ] | ||
java: [ '8', '11', '17' ] | ||
include: ${{fromJSON(needs.setup.outputs.tests)}} | ||
|
||
name: ${{ matrix.os }},jdk ${{ matrix.java }} | ||
name: ${{ matrix.desc }} | ||
|
||
steps: | ||
# | ||
|
@@ -49,7 +88,7 @@ jobs: | |
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: ${{ matrix.java }} | ||
java-version: ${{ matrix.jdk }} | ||
|
||
# | ||
# Install Planck | ||
|
@@ -63,9 +102,6 @@ jobs: | |
sudo apt-get update | ||
sudo apt-get install -y planck | ||
if: matrix.os == 'ubuntu' | ||
- name: Install planck (macOS) | ||
run: brew install planck | ||
if: matrix.os == 'macos' | ||
|
||
# | ||
# Install Babashka | ||
|
@@ -133,5 +169,5 @@ jobs: | |
# | ||
# Run tests | ||
# | ||
- name: Run CI tests | ||
run: bb ci-unit-tests | ||
- name: Run Tests | ||
run: ${{ matrix.cmd }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(ns helper.jdk | ||
(:require [helper.shell :as shell])) | ||
|
||
(defn version | ||
"Returns jdk version and major version with appropriate conversion. (ex 1.8 returns major of 8)" | ||
[] | ||
(let [raw-version (->> (shell/command {:err :string} | ||
"java -version") | ||
:err | ||
(re-find #"version \"(.*)\"") | ||
last) | ||
major-minor (->> raw-version | ||
(re-find #"(\d+)(?:\.(\d+))?.*") | ||
rest | ||
(map #(when % (Integer/parseInt %))))] | ||
{:version raw-version | ||
:major (if (= (first major-minor) 1) | ||
(second major-minor) | ||
(first major-minor))})) |
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