Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/commit_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install java
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'
Expand All @@ -29,9 +29,9 @@ jobs:
# See https://github.com/DeLaGuardo/setup-clojure/commits/main/
uses: DeLaGuardo/setup-clojure@3fe9b3ae632c6758d0b7757b0838606ef4287b08 #v13.2
with:
cli: 1.12.1.1550
bb: 1.12.207
clj-kondo: 2025.07.28
cli: 1.12.2.1565
bb: 1.12.208
clj-kondo: 2025.09.19
zprint: 1.3.0
- name: Lint
run: bb lint -v
Expand All @@ -51,7 +51,7 @@ jobs:
run: git diff
- name: Pushed code should already be formatted
# See https://github.com/CatChen/check-git-status-action
uses: CatChen/check-git-status-action@7ff019ee29f2307dca95397ae225037aa88eb4c7 #v1.4.4
uses: CatChen/check-git-status-action@d75bdbea704869e2a3b01111b4a82c49e9bd348d #v1.4.4
with:
fail-if-not-clean: true
request-changes-if-not-clean: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy_clojar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
# This step checks out a copy of your repository.
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- uses: jlesquembre/clojars-publish-action@89a4eb7bdbe1270621e6643250afce152701699e # v0.3
env:
Expand Down
16 changes: 9 additions & 7 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
:paths ["src"]
:tasks
{:requires [[auto-build.os.exit-codes] [auto-build.os.exiting :refer [exit]]]
bp {:doc "Before push"
bp {:doc "To fail fast before git pushing a version"
:requires [[auto-build.echo :refer [level1-header]] [auto-build.tasks.deps :as td]]
:task (binding [exit (fn [exit-code & _] (when-not (zero? exit-code) exit-code))]
(-> (or (run 'format)
(run 'lint)
(td/task level1-header ".")
(binding [*command-line-args* (conj *command-line-args* "all")]
(run 'clj-test))
auto-build.os.exit-codes/ok)
Expand All @@ -19,7 +21,7 @@
[".cpcache" ".shadow-cljs"]
(current-task))
exit)}
clj-test {:doc "Test with clj"
clj-test {:doc "Run clojure test"
:requires [[auto-build.tasks.clj-test :as build-clj-test]
[auto-build.echo :refer [level1-header]]]
:task (-> (build-clj-test/clj-test level1-header
Expand All @@ -28,31 +30,31 @@
(current-task)
["test-bb" "test-unit"])
exit)}
deploy {:doc "Deploy"
deploy {:doc "Add tags to the main branch to create a new version"
:requires [[auto-build.tasks.deploy :as task-deploy]
[auto-build.echo :refer [level1-header]]]
:task (-> (task-deploy/deploy level1-header "." "main" (current-task))
exit)}
deps {:doc "Update deps"
deps {:doc "Update dependencies (clojure ones)"
:task (shell "clj -M:antq")}
docs {:doc "Docs"
:requires [[auto-build.tasks.docs :as build-docs] [auto-build.echo :refer [level1-header]]]
:task (->
(build-docs/docs level1-header "." (current-task) "gh-pages" ":codox:for-clj-repl")
exit)}
format {:doc "Format"
format {:doc "Format source code"
:requires [[auto-build.tasks.formatting :as task-format]
[auto-build.echo :refer [level1-header]]]
:task (-> (task-format/format level1-header "." (current-task))
exit)}
gha {:doc "For github action tests"
gha {:doc "To be run by github action"
:task (shell "bb clj-test test-unit test-bb -v")}
heph-info {:doc "Hephaistox project info"
:requires [[auto-build.tasks.heph-info :as heph-info]
[auto-build.echo :refer [level1-header]]]
:task (-> (heph-info/heph-info level1-header (current-task) ".")
exit)}
lint {:doc "Lint"
lint {:doc "Lint source code"
:requires [[auto-build.tasks.lint :as task-lint] [auto-build.echo :refer [level1-header]]]
:task (-> (task-lint/lint level1-header ["src" "test" "env/unit/test"] "." (current-task))
exit)}
Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
:exec-fn codox.main/generate-docs
:extra-deps {codox/codox {:mvn/version "0.10.8"}}}
:for-clj-repl {:doc "Dependencies necessary to use bb in clojure"
:extra-deps {babashka/fs {:mvn/version "0.5.26"}
:extra-deps {babashka/fs {:mvn/version "0.5.27"}
babashka/process {:mvn/version "0.6.23"}}}
:test-bb {:extra-paths ["test/src" "test/resources"]
:main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/src"]}
:test-unit {:extra-paths ["env/unit/test/" "env/unit/resources"]
:main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "env/unit/test/"]}}
:deps {nrepl/nrepl {:mvn/version "1.3.1"}
:deps {nrepl/nrepl {:mvn/version "1.4.0"}
org.clojure/tools.cli {:mvn/version "1.1.230"}}
:paths ["src"]}
16 changes: 8 additions & 8 deletions env/unit/test/auto_build/os/edn_utils_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
(is (str/includes? (with-out-str (sut/read-edn {:errorln println
:exception-msg #(println (ex-message %))}
"non-existing-file"))
"No such file or directory)\n")
"Impossible to load file")
"For a non existing file")
(is (str/includes? (with-out-str (sut/read-edn {:errorln println
:exception-msg #(println (ex-message %))}
(io/resource "invalid_content.edn")))
"is not a valid edn.\nMap literal must contain an even number of forms\n")
"is not a valid edn.")
"For a content which is not a valid edn")
(is (= ""
(with-out-str (sut/read-edn {:errorln println
Expand Down Expand Up @@ -93,10 +93,10 @@
(sut/write-edn {} "foo")
with-out-str))
"What a successful file writing is printing if no printer is provided")
(is (= "File nil could not be written\nCannot open <nil> as a Writer.\n"
(-> nil
(sut/write-edn {:errorln println
:exception-msg (comp println ex-message)}
"foo")
with-out-str))
(is (str/includes? (-> nil
(sut/write-edn {:errorln println
:exception-msg (comp println ex-message)}
"foo")
with-out-str)
"File nil could not be written")
"What a failing file writing is printing")))
26 changes: 12 additions & 14 deletions env/unit/test/auto_build/os/file_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,12 @@
(io/resource "valid_content.edn"))
with-out-str))
"What a valid file is printing")
(is
(=
"Impossible to load file non-existing-file.edn\nnon-existing-file.edn (No such file or directory)\n"
(-> (sut/read-file {:errorln println
:exception-msg (comp println ex-message)}
"non-existing-file.edn")
with-out-str))
"What an invalid file is printing")))
(is (str/includes? (-> (sut/read-file {:errorln println
:exception-msg (comp println ex-message)}
"non-existing-file.edn")
with-out-str)
"Impossible to load file non-existing-file.edn\n")
"What an invalid file is printing")))

(deftest write-file-test
(testing "Returned data"
Expand Down Expand Up @@ -203,12 +201,12 @@
(sut/write-file {} "foo")
with-out-str))
"What a successful file writing is printing if no printer is provided")
(is (= "File nil could not be written\nCannot open <nil> as a Writer.\n"
(-> nil
(sut/write-file {:errorln println
:exception-msg (comp println ex-message)}
"foo")
with-out-str))
(is (str/includes? (-> nil
(sut/write-file {:errorln println
:exception-msg (comp println ex-message)}
"foo")
with-out-str)
"File nil could not be written\n")
"What a failing file writing is printing")))

;; ********************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/auto_build/os/edn_utils/impl/reader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
((if (fn? uri-str) uri-str identity))
build-filename/absolutize)
"is not a valid edn.")
(when exception-msg (exception-msg e)))
(when exception-msg (exception-msg (.getMessage e))))
{:exception e
:status :edn-failed}))))))
4 changes: 2 additions & 2 deletions src/auto_build/os/file.clj
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Returns:
(when (fn? errorln)
(errorln "Impossible to load file"
((if (fn? uri-str) uri-str identity) filepath)))
(when exception-msg (exception-msg e))
(when exception-msg (exception-msg (.getMessage e)))
{:exception e
:status :file-loading-fail})))))

Expand Down Expand Up @@ -198,7 +198,7 @@ Returns:
(catch Exception e
(when (fn? errorln)
(errorln "File" ((if (fn? uri-str) uri-str identity) filepath) "could not be written"))
(when (fn? exception-msg) (exception-msg e))
(when (fn? exception-msg) (exception-msg (.getMessage e)))
{:exception e
:status :file-writing-fail}))))

Expand Down
34 changes: 34 additions & 0 deletions src/auto_build/project/bb.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(ns auto-build.project.bb
"Utilities for `bb.edn` files."
(:refer-clojure :exclude [read])
(:require
[auto-build.os.edn-utils :as build-edn-utils]
[auto-build.os.filename :as build-filename]))

(defn bb-edn-filename
"A `bb.edn` fullname based on the `app-dir` - the directory containing the application"
[app-dir]
(build-filename/create-file-path app-dir "bb.edn"))

(defn read
"Returns a map with:
* `:filepath`
* `:afilepath` absolute path to the file
* `:raw-content` if file can be read
* `:invalid?` is boolean
* `:exception` if something wrong happened
* `:edn` if the translation is successful"
[printers app-dir]
(->> app-dir
bb-edn-filename
(build-edn-utils/read-edn printers)))

(comment
(bb-edn-filename ".")
;
(read {:errorln println
:uri-str #(format "`%s`" %)
:exception-msg #(println "Error: " %)}
".")
;
)
86 changes: 86 additions & 0 deletions src/auto_build/project/cfg_mgt.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
(ns auto-build.project.cfg-mgt
"Configuration management utilities"
(:require
[auto-build.os.cmd :refer [as-string]]
[babashka.fs :as fs]
[clojure.string :as str]))

(defn is-git-repo?
"Returns `true` if `dir` is a directory containing a git repo"
[dir]
(every? true? ((juxt fs/exists? fs/directory?) (fs/file dir ".git"))))

(defn git-data
"Returns a map of `git` informations from the repo in `dir`:
- `:git-statuts`
- `:actual-branch`
- `actual-sha`"
[dir]
(let [pstatus (-> ["git" "status" "-s"]
(as-string dir))
status (:out-stream pstatus)]
(when (and (fs/exists? dir) (fs/directory? dir) (is-git-repo? dir))
{:git-status status
:app-dir dir
:actual-branch (-> ["git" "rev-parse" "--abbrev-ref" "HEAD"]
(as-string dir)
:out-stream
first)
:actual-sha (-> ["git" "rev-parse" "HEAD"]
(as-string dir)
:out-stream
first)})))

(comment
(git-data "auto_build")
(-> ["git" "status" "-s"]
(as-string "landing")
:out-stream)
(println "In dir" "landing"
"These are the status:" (-> ["git" "status" "-s"]
(as-string "landing")
:out-stream))
;
)

(defn local-repos
"List of project directories containing repos.

A local repo is a subdirectory, that contains a `.git` folder."
[dir]
(->> (fs/list-dir dir)
(filter fs/directory?)
(map #(let [dir (-> %
fs/components
last
str)]
dir))
(filter is-git-repo?)))


(comment
(local-repos ".")
;
)

;; ********************************************************************************
;;
;; ********************************************************************************

(defn extract-project
"Extract the project from the project symbol."
[app-symbol]
(->> app-symbol
(re-find #"(.*)/(.*)")
last))

(defn project-dir
"Extract the project directory from the project symbol."
[app-name]
(str/replace app-name #"-" "_"))

(comment
(extract-project "com.github.hephaistox/auto-web")
(project-dir "auto-web")
;;
)
Loading
Loading