Skip to content

Commit

Permalink
Clean build
Browse files Browse the repository at this point in the history
itest
  • Loading branch information
caumond committed Jan 6, 2025
1 parent 1797de6 commit 3da29a4
Show file tree
Hide file tree
Showing 32 changed files with 601 additions and 388 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/commit_validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Commit validation
on:
push:
branches: '**'
# Don't want to validate on tag push, only commits --> https://stackoverflow.com/questions/64708371/how-to-run-github-workflow-on-every-commit-of-a-push
jobs:
clojure:
strategy:
matrix:
os: [ubuntu-latest] # , windows-latest There is a path issue
# macOS-latest is removed to save github costs
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '22'
- name: Install clojure tools
uses: DeLaGuardo/[email protected]
with:
cli: 1.12.0.1479 # Clojure CLI based on tools.deps
bb: 1.12.195 # Babashka
clj-kondo: 2024.11.14 # Clj-kondo
zprint: 1.2.9 # zprint
- name: Install fdfind
run: sudo apt-get install -y fd-find
- name: Setup zprint
run: echo "{:search-config? true}" >> ~/.zprintrc
- name: Cache clojure dependencies
uses: actions/cache@v4
with:
path: /home/runner/.m2/repository
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
restore-keys: cljdeps-
- name: Tests code alias + linter + forbidden words
run: bb wf-4 -iawlp
- name: Test code
run: bb test test-bb test-unit
- name: Write git diff - show what has been changed by zprint
run: git diff
- name: Pushed code should already be formatted
uses: CatChen/check-git-status-action@v1
with:
fail-if-not-clean: true
request-changes-if-not-clean: false
push-if-not-clean: false
19 changes: 19 additions & 0 deletions .github/workflows/deploy_clojar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Tag - Deployment to clojars
# See https://github.com/jlesquembre/clojars-publish-action
on:
push:
tags:
- "*"

jobs:
clojars:
runs-on: ubuntu-latest

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

- uses: jlesquembre/[email protected]
env:
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }}
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }}
38 changes: 0 additions & 38 deletions .github/workflows/validation_delaguardo.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/validation_docker.old

This file was deleted.

43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
# automaton-build
Automaton build library streamlines the creation, development, testing, and publishing of the projects.

<img src="docs/img/automaton_duck.png" width=130 alt="automaton picture">
Automaton build library streamlines the creation, development, testing, and publishing of the automaton projects.

<img src="docs/img/automaton_duck.png" width=130 alt="automaton duck picture">

> If every tool, when ordered, or even of its own accord, could do the work that befits it, just as the creations of Daedalus moved of themselves, or the tripods of Hephaestus went of their own accord to their sacred work, if the shuttle would weave and the plectrum touch the lyre without a hand to guide them, master-craftsmen would have no need of assistants and masters no need of slaves ~ Aristotle, Politics 1253b
## Motivation
While working with multiple projects in the organization, many things are repetitive, like running repl, formatting and linting the code, versioning, CICD etc. This library aims to simplify and automate this work.

To meet monorepo objectives, it should be possible to quickly create a project and maintain its modifications through time.

At the same moment, it is really complicated and most often dangerous to decide for once how all projects should look like.

So, all factorized code is stored in the `automaton-build` project.

## Design decision

See [design decision page](docs/design_decision.md)

## Quick start
To integrate automaton-build into your project

To integrate `automaton-build` into your project:

1. Create `bb.edn` file at the root of your project with the following content:

``` clojure
{:deps {org.clojars.hephaistox/automaton-build #:mvn{:version "1.0.2"}}
:tasks {-base-deps {:doc "Dependencies for a task using bb"
:extra-deps {org.clojure/tools.cli {:mvn/version "1.1.230"}}}
:tasks {-base-deps {:doc "Dependencies for a task using bb"}
:requires [[automaton-build.tasks.common :as tasks-common]]}}
```

Which will:
* Add this library (automaton-build) dependency to enable its features.
* Add the `-base-deps` task. Which will be used to declare whatever is common to all tasks. It starts with `-` so it is not shown in the task list.
* Add the `automaton-build` library dependency to enable its features.
* Add the `-base-deps` task to declare whatever is common to all tasks. It starts with `-` so it is not shown in the task list.
* Add the `requires` that enables `tasks-common` namespace for all tasks so you don't have to repeat it.

2. Add your custom tasks or use pre-defined ones from the `automaton-build.tasks` directory.
Expand All @@ -29,27 +41,16 @@ Example task for starting REPL:
```clojure
repl {:depends [-base-deps]
:requires [[automaton-build.tasks.2 :as tasks-2]]
:extra-deps {djblue/portal {:mvn/version "0.52.2"}}
:extra-deps {}
:doc "Launch repl"
:enter (tasks-common/enter tasks-2/cli-opts (current-task))
:task (tasks-2/start-repl [:common-test :env-development-repl :build])}
```

## Tasks configuration
Some tasks may require additional configuration. Set up a `project.edn` file in your project root to customize task behavior.
For an example refer to the forbidden-words report task [automaton-build.tasks.tasks.3](src/bb/automaton_build/tasks/3.clj) and [project.edn file](project.edn)

## Compatibility of dependencies
To use external dependency (`:extra-deps` alias), dependency needs to compile to the GraalVM or be included in Babashka.
[For a list of compatible libraries see the Babashka documentation](https://github.com/babashka/babashka/blob/master/doc/projects.md)

In case the library is not supported, but has CLI capabilities, you can include it as an alias in the project `deps.edn` and just call cmd with "clojure -M/X:alias".
[Example of it can be found in documentation task that uses codox library](src/bb/automaton_build/tasks/doc.clj)

## See documentation
This library is heavily based on the usage of [babashka tasks](https://book.babashka.org/#_tasks_api).
Some tasks may require additional configuration. Set up a `project.edn` file in your project root to customize task behavior. For an example refer to the forbidden-words report task [automaton-build.tasks.tasks.3](src/bb/automaton_build/tasks/3.clj) and [project.edn file](project.edn)

If you're interested in more detail about the approach we took while developing this library look at [design decisions document](docs/design_decision.md)

[For detailed API documentation click here](https://hephaistox.github.io/automaton-build/latest).

Expand Down
43 changes: 30 additions & 13 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
{:deps {cheshire/cheshire {:mvn/version "5.13.0"}
djblue/portal {:mvn/version "0.58.2"}
io.github.clojure/tools.build {:mvn/version "0.10.5"}
metosin/malli {:mvn/version "0.16.1"}
org.clojure/tools.cli {:mvn/version "1.1.230"}}
:paths ["src/clj" "src/bb" "test_la/clj"]
:paths ["src/clj" "src/bb"]
:tasks
{-base-deps {:doc "Dependencies for a task using bb"
:extra-deps {org.clojure/tools.cli {:mvn/version "1.1.230"}}}
{-base-deps {:doc "Dependencies for a task using bb"}
:requires [[automaton-build.tasks.common :as tasks-common]]
lconnect
{:doc
"Repl in case automaton-build is failing. Using -f or --force cli arguments to force start if some part are failing"
:task (try (-> (babahska-process/shell "clojure"
"-M:common-test:env-development-repl:build"
*command-line-args*)
System/exit)
(catch Exception e
(println "Repl failed also - error during repl startup" (ex-message e))))}
deploy {:doc "Publish this project"
:requires [[automaton-build.tasks.deploy-app :refer [run]]]
:task (run)}
docs {:depends [-base-deps]
:doc "Publish documentation."
:enter (tasks-common/enter-with-arguments tasks-docs/cli-opts-common-def
(current-task)
tasks-docs/arguments)
:requires [[automaton-build.tasks.docs :as tasks-docs]]
:task (tasks-docs/run-app "**{.png,.gif,.jpg,.svg}" "gh-pages-dont-change")}
lconnect {:doc "Repl in case automaton-build is failing."
:task (-> (try (-> (shell "clojure" "-M:env-development-repl")
:exit)
(catch Exception e
(println "Repl failed also - error during repl startup\n *"
(pr-str e))
-1))
System/exit)}
test {:doc "Dev test bb code in jvm"
:requires [[automaton-build.tasks.test :as test]]
:task (-> (test/run "clj-test-runner"
#{{:description "bb tests in jvm"
:alias :test-bb}
{:description "unit tests - assembly tests at unit level"
:alias :test-unit}
{:description "test local development environmnet itself"
:alias :test-dev}})
System/exit)}
wf-4 {:depends [-base-deps]
:doc "Full test and formatting."
:enter (tasks-common/enter wf-4/cli-opts (current-task))
Expand Down
49 changes: 14 additions & 35 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{:aliases
{:antq {:deps {com.github.liquidz/antq {:mvn/version "2.11.1250"}}
:main-opts ["-m" "antq.core"]}
{:clj-test-runner {:exec-fn cognitect.test-runner.api/test
:extra-deps {com.cognitect/test-runner
{:git/url "https://github.com/cognitect-labs/test-runner"
:sha "3f288f1f16d167723ad87cc35b1dfee3c1681e10"}}
:jvm-opts ["-Dheph-conf=env/test_config.edn,env/common_config.edn"]}
:codox
{:exec-args
{:description "`automaton-build` is a library to ease project cicd: build, test, deployemnt..."
Expand All @@ -11,45 +14,21 @@
:source-uri "https://github.com/hephaistox/automaton-build/blob/{version}/{filepath}#L{line}"}
:exec-fn codox.main/generate-docs
:extra-deps {codox/codox {:mvn/version "0.10.8"}}}
:common-test
{:exec-fn cognitect.test-runner.api/test
:extra-deps {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner"
:sha "3f288f1f16d167723ad87cc35b1dfee3c1681e10"}
org.clojure/tools.namespace {:mvn/version "1.5.0"}
org.clojure/tools.reader {:mvn/version "1.5.0"}}
:extra-paths ["test/unit/bb" "test/unit/resources" "test/la/bb"]
:jvm-opts ["-Dheph-conf=env/test/config.edn,env/common_config.edn" "-Dhephaistox-in-test=true"]
:main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/unit" "-d" "test/la"]}
:deploy {:exec-args {:installer :remote}
:exec-fn deps-deploy.deps-deploy/deploy
:extra-deps {slipset/deps-deploy {:exclusions [org.slf4j/slf4j-nop]
:mvn/version "0.2.2"}}}
:env-development-repl
{:extra-deps {djblue/portal {:mvn/version "0.58.2"}
org.clojure/core.async {:mvn/version "1.6.681"}}
:extra-paths ["env/development/resources" "env/development/src/clj" "env/development/src/cljc"]
:jvm-opts ["-Dheph-conf=env/development/config.edn,env/common_config.edn"]
:main-opts ["-m" "automaton-build.repl.entry-point"]}
:env-development-test
{:exec-fn cognitect.test-runner.api/test
:extra-deps {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner"
:sha "3f288f1f16d167723ad87cc35b1dfee3c1681e10"}
org.clojure/tools.namespace {:mvn/version "1.5.0"}
org.clojure/tools.reader {:mvn/version "1.5.0"}}
:extra-paths ["test/dev/bb" "test/dev/clj" "test/dev/resources"]
:jvm-opts ["-Dhephaistox-in-test=true"]
:main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/dev"]}}
:repl {:extra-paths ["env/development/src/bb"]
:jvm-opts ["-Dheph-conf=env/development/config.edn,env/common_config.edn"]
:main-opts ["-m" "automaton-build.repl.entry-point"]}
:test-bb {:extra-paths ["test/bb"]
:main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/bb"]}
:test-dev {:extra-paths ["test/dev/bb" "test/dev/resources"]
:main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/dev"]}
:test-unit {:extra-paths ["test/unit/bb" "test/unit/resources"]
:main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/unit"]}}
:deps {babashka/fs {:mvn/version "0.5.22"}
babashka/process {:mvn/version "0.5.22"}
cheshire/cheshire {:mvn/version "5.13.0"}
clj-htmltopdf/clj-htmltopdf {:mvn/version "0.2.1"}
codox/codox {:mvn/version "0.10.8"}
dev.weavejester/medley {:mvn/version "1.8.1"}
djblue/portal {:mvn/version "0.58.2"}
hiccup/hiccup {:mvn/version "2.0.0-RC3"}
io.github.clojure/tools.build {:mvn/version "0.10.5"}
markdown-clj/markdown-clj {:mvn/version "1.12.2"}
metosin/malli {:mvn/version "0.16.1"}
zprint/zprint {:mvn/version "1.2.9"}}
:ns-default automaton-build.core
:paths ["src/bb"]}
3 changes: 1 addition & 2 deletions env/development/config.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
{:dev {:clj-nrepl-port 8010
:portal-port 8351}
{:dev {:clj-nrepl-port 8010}
:env :development}
12 changes: 12 additions & 0 deletions env/development/src/bb/automaton_build/repl/entry_point.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns automaton-build.repl.entry-point
"Entry point for repl"
(:require
[nrepl.server :refer [start-server]]))

(defn -main
"Entry point"
[& _args]
(let [port 1234]
(println "Automaton build development mode")
(println "Start repl on port" port)
(start-server :port port)))
2 changes: 0 additions & 2 deletions env/test/file_found.edn

This file was deleted.

Empty file removed env/test/src/.keep
Empty file.
File renamed without changes.
31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<groupId>org.clojars.hephaistox</groupId>
<artifactId>automaton-build</artifactId>
<version>LATEST</version>
<name>automan-build</name>
<description>Hephaistox common tasks for project manipulation</description>
<url>https://github.com/hephaistox/automaton-build</url>

<licenses>
<license>
<name>CC BY-NC 4.0</name>
<url>https://creativecommons.org/licenses/by-nc/4.0/deed.en</url>
</license>
</licenses>

<developers>
<developer>
<name>Hephaistox</name>
</developer>
</developers>

<scm>
<url>https://github.com/hephaistox/automaton-build</url>
<developerConnection>scm:git:ssh://[email protected]:hephaistox/automaton-build.git</developerConnection>
<tag>HEAD</tag>
</scm>

</project>
9 changes: 1 addition & 8 deletions project.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,4 @@
:code {:forbidden-words ["TODO" "DONE" "NOTE" "FIXME" "tap>" "automaton-core" "automaton-web"]}
:deps {:excluded-libs
[{:doc "0.16.3 has deprecated warnings, fix is already in main merged but not released yet"
:name "metosin/malli"}]}
:publication {:base-branch "main"
:clojars true
:excluded-aliases
[:antq :codox :env-development-repl :env-development-test :common-test :deploy]
:la-branch "la"
:pom-xml-license {:name "CC BY-NC 4.0"
:url "https://creativecommons.org/licenses/by-nc/4.0/deed.en"}}}
:name "metosin/malli"}]}}
Empty file removed resources/.keep
Empty file.
1 change: 0 additions & 1 deletion specific_task_registry.edn

This file was deleted.

2 changes: 1 addition & 1 deletion src/bb/automaton_build/code/formatter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
(defn format-clj-cmd
"Command formatting all clj files in the directory and subdirectories where it is executed."
[]
["fd" "-e" "clj" "-e" "cljc" "-e" "cljs" "-e" "edn" "-x" "zprint" "-w"])
["fdfind" "-e" "clj" "-e" "cljc" "-e" "cljs" "-e" "edn" "-x" "zprint" "-w"])
Loading

0 comments on commit 3da29a4

Please sign in to comment.