Skip CI run if commit only documentation changes (#1282)
This commit is contained in:
parent
b8a3d2447c
commit
94034063db
2 changed files with 77 additions and 6 deletions
|
|
@ -13,6 +13,22 @@ commands:
|
||||||
docker buildx create --name ci-builder --use
|
docker buildx create --name ci-builder --use
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
short-if-irrelevant:
|
||||||
|
docker:
|
||||||
|
- image: cimg/base:stable
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run:
|
||||||
|
name: Bootstrap Babashka
|
||||||
|
command: |
|
||||||
|
curl -sLO https://raw.githubusercontent.com/babashka/babashka/master/install
|
||||||
|
sudo bash install --dir /tmp
|
||||||
|
- run:
|
||||||
|
name: Rename bb binary
|
||||||
|
command: mv /tmp/bb /tmp/bbb
|
||||||
|
- run:
|
||||||
|
name: Short CI if only irrelevant changes
|
||||||
|
command: /tmp/bbb .circleci/script/short.clj
|
||||||
jvm:
|
jvm:
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/clojure:openjdk-11-lein-2.9.8-bullseye
|
- image: circleci/clojure:openjdk-11-lein-2.9.8-bullseye
|
||||||
|
|
@ -468,12 +484,25 @@ workflows:
|
||||||
version: 2
|
version: 2
|
||||||
ci:
|
ci:
|
||||||
jobs:
|
jobs:
|
||||||
- jvm
|
- short-if-irrelevant
|
||||||
- linux
|
- jvm:
|
||||||
- linux-static
|
requires:
|
||||||
- mac
|
- short-if-irrelevant
|
||||||
- linux-aarch64
|
- linux:
|
||||||
- linux-aarch64-static
|
requires:
|
||||||
|
- short-if-irrelevant
|
||||||
|
- linux-static:
|
||||||
|
requires:
|
||||||
|
- short-if-irrelevant
|
||||||
|
- mac:
|
||||||
|
requires:
|
||||||
|
- short-if-irrelevant
|
||||||
|
- linux-aarch64:
|
||||||
|
requires:
|
||||||
|
- short-if-irrelevant
|
||||||
|
- linux-aarch64-static:
|
||||||
|
requires:
|
||||||
|
- short-if-irrelevant
|
||||||
- deploy:
|
- deploy:
|
||||||
filters:
|
filters:
|
||||||
branches:
|
branches:
|
||||||
|
|
|
||||||
42
.circleci/script/short.clj
Normal file
42
.circleci/script/short.clj
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
(require '[babashka.process :as proc]
|
||||||
|
'[clojure.string :as str])
|
||||||
|
|
||||||
|
(def config
|
||||||
|
{:skip-if-only [#".*.md$"]})
|
||||||
|
|
||||||
|
(defn exec [cmd]
|
||||||
|
(-> cmd
|
||||||
|
(proc/process)
|
||||||
|
(proc/check)))
|
||||||
|
|
||||||
|
(defn get-changes []
|
||||||
|
(-> "git diff --name-only HEAD~1"
|
||||||
|
(exec)
|
||||||
|
(:out)
|
||||||
|
slurp
|
||||||
|
(str/split-lines)))
|
||||||
|
|
||||||
|
(defn irrelevant-change? [change regexes]
|
||||||
|
(some? (some #(re-matches % change) regexes)))
|
||||||
|
|
||||||
|
(defn relevant? [change-set regexes]
|
||||||
|
(some? (some #(not (irrelevant-change? % regexes)) change-set)))
|
||||||
|
|
||||||
|
(defn main []
|
||||||
|
(let [{:keys [skip-if-only]} config
|
||||||
|
changed-files (get-changes)]
|
||||||
|
(if (relevant? changed-files skip-if-only)
|
||||||
|
(println "Proceeding with CI run")
|
||||||
|
(do
|
||||||
|
(println "Irrelevant changes - skipping CI run")
|
||||||
|
(exec "circleci task halt")))))
|
||||||
|
|
||||||
|
(when (= *file* (System/getProperty "babashka.file"))
|
||||||
|
(main))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(def regexes [#".*.md$"
|
||||||
|
#".*.clj"]) ;ignore clojure files
|
||||||
|
(irrelevant-change? "src/file.png" regexes)
|
||||||
|
(re-matches #".*.clj$" "src/file.clj.dfff")
|
||||||
|
(relevant? ["src/file.clj"] regexes))
|
||||||
Loading…
Reference in a new issue