From 55f97b5af4435f2c630b4f7f0d1ca982929d7134 Mon Sep 17 00:00:00 2001 From: PEZ <> Date: Wed, 6 Nov 2024 18:07:29 +0100 Subject: [PATCH] Use babashka-cli --- .github/workflows/release.yml | 2 +- bb.edn | 53 +++++++++++++++++++++++---------- scripts/publish.clj | 21 ++++--------- scripts/tasks.clj | 56 +++++++++++++++-------------------- 4 files changed, 68 insertions(+), 64 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c9e9c5a..5e3e2c5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -134,4 +134,4 @@ jobs: - name: Bump Version env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: bb ci:bump-version "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" "${{ github.actor }}" \ No newline at end of file + run: bb ci:bump-version-and-push "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" "${{ github.actor }}" \ No newline at end of file diff --git a/bb.edn b/bb.edn index 6f479e8..27fe379 100644 --- a/bb.edn +++ b/bb.edn @@ -1,24 +1,45 @@ {:paths ["scripts"] + :deps {org.babashka/cli {:mvn/version "0.2.23"}} :tasks - {:requires ([tasks :as t]) + {:requires [[babashka.cli :as cli] + [tasks :as t] + publish] - ;; Tasks that take a -d arg support a dry-run. - ;; -d needs to go last of any other args. + publish + {:doc "Usage: bb publish [--dry]" + :task (t/publish! + (cli/parse-opts *command-line-args* {:restrict [:dry]}))} - publish {:doc "Usage: bb publish [-d]" - :task t/publish!} + package-pre-release + {:doc "Usage: bb package-pre-release [--dry]" + :task (t/package-pre-release! + (cli/parse-opts *command-line-args* {:restrict [:branch :dry] + :require [:branch] + :args->opts [:branch]}))} - package-pre-release {:doc "Usage: bb package-pre-release [-d]" - :task t/package-pre-release!} + ci:release-notes + {:doc "Get release notes for " + :task (t/print-release-notes! + (cli/parse-opts *command-line-args* {:require [:version] + :validate {:version + (fn [v] + (re-matches + (re-pattern "v\\d+\\.\\d+\\.\\d+") + v))} + :args->opts [:version]}))} - ci:release-notes {:doc "Get release notes for " - :task t/print-release-notes!} + ci:bump-version-and-push + {:doc "Usage: bb bump-version [--dry]" + :task (t/bump-version! + (cli/parse-opts *command-line-args* {:restrict [:email :user-name :dry] + :require [:email :user-name] + :args->opts [:email :user-name]}))} - ci:bump-version {:doc "Usage: bb bump-version [-d]" - :task t/bump-version!} + run-e2e-tests-ws + {:doc "Run end-to-end tests using working directory" + :task t/run-e2e-tests-from-working-dir!} - run-e2e-tests-ws {:doc "Run end-to-end tests using working directory" - :task t/run-e2e-tests-from-working-dir!} - - run-e2e-tests-vsix {:doc "Run end-to-end tests using " - :task t/run-e2e-tests-with-vsix!}}} + run-e2e-tests-vsix + {:doc "Run end-to-end tests using " + :task (t/run-e2e-tests-with-vsix! (cli/parse-opts *command-line-args* {:require [:vsix] + :args->opts [:vsix]}))}}} diff --git a/scripts/publish.clj b/scripts/publish.clj index 27e9922..4e7c248 100755 --- a/scripts/publish.clj +++ b/scripts/publish.clj @@ -71,7 +71,7 @@ (println "Open to follow the progress of the release:") (println " https://github.com/PEZ/paste-replaced/actions")) -(defn publish [unreleased-changelog-text dry-run?] +(defn publish! [unreleased-changelog-text dry-run?] (let [changelog-text (slurp changelog-filename) extension-version (-> (slurp "package.json") json/parse-string @@ -90,12 +90,11 @@ dry-run?) (tag-and-push! extension-version dry-run?))))) -(defn run [& args] - (let [dry-run? (= "-d" (first args)) - unreleased-changelog-text (get-changelog-text-for-version "Unreleased") +(defn yolo! [{:keys [dry]}] + (let [unreleased-changelog-text (get-changelog-text-for-version "Unreleased") status (git-status)] - (println "dry-run?" dry-run?) + (println "dry-run?" dry) (if (or (seq status) (empty? unreleased-changelog-text)) (do @@ -108,13 +107,5 @@ (let [answer (str (read))] (if-not (= "YES" answer) (println "Aborting publish.") - (publish unreleased-changelog-text dry-run?)))) - (publish unreleased-changelog-text dry-run?)))) - -(when (= *file* (System/getProperty "babashka.file")) - (apply run *command-line-args*)) - -(comment - (run "-d") - :rcf) - + (publish! unreleased-changelog-text dry)))) + (publish! unreleased-changelog-text dry)))) diff --git a/scripts/tasks.clj b/scripts/tasks.clj index 16e8788..ae24983 100644 --- a/scripts/tasks.clj +++ b/scripts/tasks.clj @@ -2,36 +2,34 @@ (:require [babashka.process :as p] [clojure.string :as string] publish - util)) + util + [babashka.cli :as cli])) -(defn publish! [& args] - (apply publish/run args)) +#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} +(defn publish! [args] + (publish/yolo! args)) -(defn print-release-notes! [version] +#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} +(defn print-release-notes! [{:keys [version]}] (let [changelog-text (publish/get-changelog-text-for-version version)] (println changelog-text))) -(defn -bump-version! [user-email user-name dry-run?] +#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} +(defn bump-version! [{:keys [user-email user-name dry]}] (println "Bumping version") - (util/sh dry-run? "git" "config" "--global" "user.email" user-email) - (util/sh dry-run? "git" "config" "--global" "user.name" user-name) - (util/sh dry-run? "npm" "set" "git-tag-version" "false") - (util/sh dry-run? "npm" "version" "patch") - (util/sh dry-run? "git" "add" ".") + (util/sh dry "git" "config" "--global" "user.email" user-email) + (util/sh dry "git" "config" "--global" "user.name" user-name) + (util/sh dry "npm" "set" "git-tag-version" "false") + (util/sh dry "npm" "version" "patch") + (util/sh dry "git" "add" ".") (let [version (-> (util/sh false "node" "-p" "require('./package').version") :out string/trim)] - (util/sh dry-run? "git" "commit" "-m" (str "Bring on version " version "!"))) - (util/sh dry-run? "git" "push" "origin" "HEAD")) + (util/sh dry "git" "commit" "-m" (str "Bring on version " version "!"))) + (util/sh dry "git" "push" "origin" "HEAD")) -(defn bump-version! [& args] - (let [[user-email user-name dry-arg] args] - (-bump-version! user-email user-name (when dry-arg true)))) - -(comment - (bump-version! "pez@pezius.com" "Peter Strömberg" "-d")) - -(defn -package-pre-release! [branch dry-run?] +#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} +(defn package-pre-release! [{:keys [branch dry]}] (let [current-version (-> (util/sh false "node" "-p" "require('./package').version") :out string/trim) commit-id (-> (util/sh false "git" "rev-parse" "--short" "HEAD") @@ -42,22 +40,16 @@ (println "Current version:" current-version) (println "HEAD Commit ID:" commit-id) (println "Packaging pre-release...") - (println (:out (util/sh dry-run? "npm" "version" "--no-git-tag-version" "prerelease" "--preid" pre-id))) - (println (:out (util/sh dry-run? "npx" "vsce" "package" "--pre-release"))) - (println (:out (util/sh dry-run? "npm" "version" "--no-git-tag-version" current-version))))) - -(defn package-pre-release! [& args] - (let [[branch dry-arg] args] - (-package-pre-release! branch (when dry-arg true)))) - -(comment - (package-pre-release! "-d") - :rcf) + (println (:out (util/sh dry "npm" "version" "--no-git-tag-version" "prerelease" "--preid" pre-id))) + (println (:out (util/sh dry "npx" "vsce" "package" "--pre-release"))) + (println (:out (util/sh dry "npm" "version" "--no-git-tag-version" current-version))))) -(defn run-e2e-tests-with-vsix! [vsix] +#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} +(defn run-e2e-tests-with-vsix! [{:keys [vsix]}] (println "Running end-to-end tests using vsix:" vsix) (p/shell "node" "./e2e-test-ws/launch.js" (str "--vsix=" vsix))) +#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} (defn run-e2e-tests-from-working-dir! [] (println "Running end-to-end tests using working directory") (p/shell "node" "./e2e-test-ws/launch.js"))