From ad377050c2cd1f5b95671bee5cead32cb7f0bcf8 Mon Sep 17 00:00:00 2001 From: lread Date: Fri, 21 Jun 2024 10:59:38 -0400 Subject: [PATCH] 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. --- script/helper/natural_sort.clj | 28 ++++++++++++++++++++++++++++ script/test_matrix.clj | 3 ++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 script/helper/natural_sort.clj diff --git a/script/helper/natural_sort.clj b/script/helper/natural_sort.clj new file mode 100644 index 00000000..1d5d75c4 --- /dev/null +++ b/script/helper/natural_sort.clj @@ -0,0 +1,28 @@ +;; Thanks to https://gist.github.com/wilkerlucio/db54dc83a9664124f3febf6356f04509 +(ns helper.natural-sort + (:refer-clojure :exclude [sort sort-by]) + (:require [clojure.string])) + +(defn vector-compare [[value1 & rest1] [value2 & rest2]] + (let [result (compare value1 value2)] + (cond + (not (zero? result)) result + (nil? value1) 0 + :else (recur rest1 rest2)))) + +(defn prepare-string [s] + (let [s (or s "") + parts (vec (clojure.string/split s #"\d+")) + numbers (->> (re-seq #"\d+" s) + (map parse-long) + (vec))] + (vec (interleave (conj parts "") (conj numbers -1))))) + +(defn natural-compare [a b] + (vector-compare (prepare-string a) + (prepare-string b))) + +(defn sort [coll] (clojure.core/sort natural-compare coll)) + +(defn sort-by [keyfn coll] + (clojure.core/sort-by keyfn natural-compare coll)) diff --git a/script/test_matrix.clj b/script/test_matrix.clj index 284d967e..224b3e52 100644 --- a/script/test_matrix.clj +++ b/script/test_matrix.clj @@ -3,6 +3,7 @@ [cheshire.core :as json] [clojure.string :as string] [doric.core :as doric] + [helper.natural-sort :as natural-sort] [helper.main :as main] [lread.status-line :as status])) @@ -76,7 +77,7 @@ (for [jdk-version (get os-jdks "ubuntu") :when (not= jdk-version (:jdk-version default-opts))] (test-doc {:jdk-version jdk-version :os "ubuntu"}))) - (sort-by :desc) + (natural-sort/sort-by :desc) (into [(merge default-opts {:os "ubuntu" :cmd "bb lint" :desc "lint"})]) (mapv #(assoc % :id (string/replace (:desc %) " " "-"))))))