Skip to content

Commit

Permalink
ci: test-matrix: natural sort by job description
Browse files Browse the repository at this point in the history
Small thing, but sorts jdk8 before jdk11 which makes github actions workflow
job listing easier to follow.
  • Loading branch information
lread committed Jun 21, 2024
1 parent ae9ff56 commit ad37705
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions script/helper/natural_sort.clj
Original file line number Diff line number Diff line change
@@ -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))
3 changes: 2 additions & 1 deletion script/test_matrix.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down Expand Up @@ -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 %) " " "-"))))))

Expand Down

0 comments on commit ad37705

Please sign in to comment.