Skip to content

Commit

Permalink
Use babashka-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
PEZ committed Nov 6, 2024
1 parent 834dc52 commit 55f97b5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
run: bb ci:bump-version-and-push "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" "${{ github.actor }}"
53 changes: 37 additions & 16 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -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 <branch> [--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 <branch> [-d]"
:task t/package-pre-release!}
ci:release-notes
{:doc "Get release notes for <version>"
: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 <version>"
:task t/print-release-notes!}
ci:bump-version-and-push
{:doc "Usage: bb bump-version <email> <user-name> [--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 <email> <user-name> [-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 <vsix>"
:task t/run-e2e-tests-with-vsix!}}}
run-e2e-tests-vsix
{:doc "Run end-to-end tests using <vsix>"
:task (t/run-e2e-tests-with-vsix! (cli/parse-opts *command-line-args* {:require [:vsix]
:args->opts [:vsix]}))}}}
21 changes: 6 additions & 15 deletions scripts/publish.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))))
56 changes: 24 additions & 32 deletions scripts/tasks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"))

0 comments on commit 55f97b5

Please sign in to comment.