Skip CI run if commit only documentation changes (#1282)

This commit is contained in:
agata-anastazja 2022-05-28 21:01:20 +01:00 committed by GitHub
parent b8a3d2447c
commit 94034063db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 6 deletions

View file

@ -13,6 +13,22 @@ commands:
docker buildx create --name ci-builder --use
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:
docker:
- image: circleci/clojure:openjdk-11-lein-2.9.8-bullseye
@ -468,12 +484,25 @@ workflows:
version: 2
ci:
jobs:
- jvm
- linux
- linux-static
- mac
- linux-aarch64
- linux-aarch64-static
- short-if-irrelevant
- jvm:
requires:
- short-if-irrelevant
- linux:
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:
filters:
branches:

View 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))