diff --git a/.build/bb.edn b/.build/bb.edn index 24c26ab4..eb2028a4 100644 --- a/.build/bb.edn +++ b/.build/bb.edn @@ -1,26 +1,7 @@ -{:deps {borkdude/gh-release-artifact +{:paths ["script"] + :deps {borkdude/gh-release-artifact #_{:local/root "../gh-release-artifact"} {:git/url "https://github.com/borkdude/gh-release-artifact" - :sha "fc00f75f4ba9ab6bd9f228e9ed288e019a534e0c"}} + :sha "2f8898d84126a4e922c490f8614211a8b0cf67cd"}} :tasks {:requires ([clojure.string :as str]) - -current-sha {:requires ([clojure.java.shell :refer [sh]]) - :task (-> (sh "git" "rev-parse" "HEAD") - :out - str/trim)} - -current-version {:task (-> (slurp "resources/BABASHKA_VERSION") - str/trim)} - -github-token (if-let [ght (System/getenv "GITHUB_TOKEN")] - ght - (do - (println "Terminating early since GITHUB_TOKEN wasn't set") - (System/exit 0))) - release-artifact {:requires ([borkdude.gh-release-artifact :as ghr]) - :depends [-github-token -current-sha -current-version] - :task (let [file (first *command-line-args*)] - (assert file "File name must be provided") - (ghr/overwrite-asset {:org "babashka" - :repo "babashka" - :file file - :commit -current-sha - :tag (str "v" -current-version)}) - nil)}}} + release-artifact babashka.release-artifact/release}} diff --git a/script/babashka/release_artifact.clj b/script/babashka/release_artifact.clj new file mode 100644 index 00000000..ce9b8ff3 --- /dev/null +++ b/script/babashka/release_artifact.clj @@ -0,0 +1,24 @@ +(ns babashka.release-artifact + (:require [borkdude.gh-release-artifact :as ghr] + [clojure.java.shell :refer [sh]] + [clojure.string :as str])) + +(defn current-branch [] + (-> (sh "git" "rev-parse" "--abbrev-ref" "HEAD") + :out + str/trim)) + +(defn release [& args] + (let [current-version (-> (slurp "resources/BABASHKA_VERSION") + str/trim) + ght (System/getenv "GITHUB_TOKEN") + file (first args) + branch (current-branch)] + (if (and ght (contains? #{"master" "main"} branch)) + (do (assert file "File name must be provided") + (ghr/overwrite-asset {:org "babashka" + :repo "babashka" + :file file + :tag (str "vx" current-version)})) + (println "Skipping release artifact (no GITHUB_TOKEN or not on main branch)")) + nil))