diff --git a/.circleci/config.yml b/.circleci/config.yml index 74f2ebd9..9aea3e94 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: diff --git a/.circleci/script/short.clj b/.circleci/script/short.clj new file mode 100644 index 00000000..490bdb38 --- /dev/null +++ b/.circleci/script/short.clj @@ -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))