Skip to content

Commit ad37705

Browse files
committed
ci: test-matrix: natural sort by job description
Small thing, but sorts jdk8 before jdk11 which makes github actions workflow job listing easier to follow.
1 parent ae9ff56 commit ad37705

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

script/helper/natural_sort.clj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
;; Thanks to https://gist.github.com/wilkerlucio/db54dc83a9664124f3febf6356f04509
2+
(ns helper.natural-sort
3+
(:refer-clojure :exclude [sort sort-by])
4+
(:require [clojure.string]))
5+
6+
(defn vector-compare [[value1 & rest1] [value2 & rest2]]
7+
(let [result (compare value1 value2)]
8+
(cond
9+
(not (zero? result)) result
10+
(nil? value1) 0
11+
:else (recur rest1 rest2))))
12+
13+
(defn prepare-string [s]
14+
(let [s (or s "")
15+
parts (vec (clojure.string/split s #"\d+"))
16+
numbers (->> (re-seq #"\d+" s)
17+
(map parse-long)
18+
(vec))]
19+
(vec (interleave (conj parts "") (conj numbers -1)))))
20+
21+
(defn natural-compare [a b]
22+
(vector-compare (prepare-string a)
23+
(prepare-string b)))
24+
25+
(defn sort [coll] (clojure.core/sort natural-compare coll))
26+
27+
(defn sort-by [keyfn coll]
28+
(clojure.core/sort-by keyfn natural-compare coll))

script/test_matrix.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[cheshire.core :as json]
44
[clojure.string :as string]
55
[doric.core :as doric]
6+
[helper.natural-sort :as natural-sort]
67
[helper.main :as main]
78
[lread.status-line :as status]))
89

@@ -76,7 +77,7 @@
7677
(for [jdk-version (get os-jdks "ubuntu")
7778
:when (not= jdk-version (:jdk-version default-opts))]
7879
(test-doc {:jdk-version jdk-version :os "ubuntu"})))
79-
(sort-by :desc)
80+
(natural-sort/sort-by :desc)
8081
(into [(merge default-opts {:os "ubuntu" :cmd "bb lint" :desc "lint"})])
8182
(mapv #(assoc % :id (string/replace (:desc %) " " "-"))))))
8283

0 commit comments

Comments
 (0)