Skip to content

Commit

Permalink
version-fn versioning support (adds git-rev-count and epoch versionin…
Browse files Browse the repository at this point in the history
…g) (#35)

adds a new standalone+modules task that will create the version from a
VERSION_TEMPLATE + a :version-fn key in the deps.edn (similarly to
clojure.core projects) and then just tag & push, meaning we get clean
master histories without version commits.

The previous versioning scheme didn't change, both can be used
independently on separate repositories.

example of usage: https://github.com/exoscale/mania/pull/19/files
  • Loading branch information
mpenet authored Jul 18, 2024
1 parent c158284 commit 0e63bad
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 48 deletions.
43 changes: 22 additions & 21 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
{:linters
{:clojure-lsp/unused-public-var {:exclude [exoscale.tools.project/add-module
{:clojure-lsp/unused-public-var {:exclude [exoscale.tools.project.api.java/compile
exoscale.tools.project.api/version
exoscale.tools.project.module/clean
exoscale.tools.project.module/compile
exoscale.tools.project.module/deploy
exoscale.tools.project.module/install
exoscale.tools.project.module/jar
exoscale.tools.project.module/release
exoscale.tools.project.module/task
exoscale.tools.project.module/uberjar
exoscale.tools.project.standalone/git-commit-version
exoscale.tools.project.standalone/git-push
exoscale.tools.project.standalone/git-tag-version
exoscale.tools.project.standalone/release
exoscale.tools.project.standalone/version-bump-and-snapshot
exoscale.tools.project.standalone/version-remove-snapshot
exoscale.tools.project.template/data-fn
exoscale.tools.project.template/module-data-fn
exoscale.tools.project.template/template-fn
exoscale.tools.project/add-module
exoscale.tools.project/check
exoscale.tools.project/clean
exoscale.tools.project/deploy
Expand All @@ -25,25 +44,7 @@
exoscale.tools.project/uberjar
exoscale.tools.project/version
exoscale.tools.project/version-bump-and-snapshot
exoscale.tools.project/version-remove-snapshot
exoscale.tools.project.api/version
exoscale.tools.project.api.java/compile
exoscale.tools.project.module/clean
exoscale.tools.project.module/compile
exoscale.tools.project.module/deploy
exoscale.tools.project.module/install
exoscale.tools.project.module/jar
exoscale.tools.project.module/release
exoscale.tools.project.module/task
exoscale.tools.project.module/uberjar
exoscale.tools.project.standalone/git-commit-version
exoscale.tools.project.standalone/git-push
exoscale.tools.project.standalone/git-tag-version
exoscale.tools.project.standalone/release
exoscale.tools.project.standalone/version-bump-and-snapshot
exoscale.tools.project.standalone/version-remove-snapshot
exoscale.tools.project.template/data-fn
exoscale.tools.project.template/module-data-fn
exoscale.tools.project.template/template-fn]}}
exoscale.tools.project/version-git-count-revs
exoscale.tools.project/version-remove-snapshot]}}
:skip-comments true
:output {:exclude-files ["^resources/exoscale"]}}
26 changes: 25 additions & 1 deletion doc/target/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,30 @@ Perform a release of the project. This is merely a [task](../task.md) run
for the `:release/single` task in standalone projects, and for the `:release/modules`
task in multi-module projects.

### Usage
### Usage release+tag task

This is a simple release task that will release the artifact and not commit the
version file (if any provided), and then git tag the release simply. That can be
used with version-fn to create releases based on git-revs-count or timestamp
schemes (see: `exoscale.tools.project.api.version/git-count-revs` &
`exoscale.tools.project.api.version/epoch`).

```bash
clojure -T:project release+tag
```

The default release+tag task is:

``` clojure
[{:run :exoscale.tools.project.standalone/deploy}
{:run :exoscale.tools.project.standalone/git-tag-version}
{:run :exoscale.tools.project.standalone/git-push}]
```


### Usage release task

This task will trigger the update of the VERSION file provided and commit it, then trigger a release

```bash
clojure -T:project release
Expand Down Expand Up @@ -33,4 +56,5 @@ The default release task configuration is:
{:run :exoscale.tools.project.standalone/version-bump-and-snapshot}
{:run :exoscale.tools.project.standalone/git-commit-version}
{:run :exoscale.tools.project.standalone/git-push}]

```
4 changes: 4 additions & 0 deletions src/exoscale/tools/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
[opts]
(task-or-tool opts :release/modules ps/release))

(defn release+tag
[opts]
(task-or-tool opts :release+tag/modules ps/release+tag))

(defn revision-sha
[opts]
(task-or-tool opts :revision-sha ps/revision-sha))
Expand Down
10 changes: 5 additions & 5 deletions src/exoscale/tools/project/api/git.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
(ns exoscale.tools.project.api.git
(:require [clojure.tools.deps.alpha.util.dir :as td]
(:require [clojure.string :as str]
[clojure.tools.deps.alpha.util.dir :as td]
[exoscale.tools.project.api.version :as v]
[exoscale.tools.project.io :as pio]
[clojure.string :as str]))
[exoscale.tools.project.io :as pio]))

(defn commit-version
[opts]
(pio/shell ["git add VERSION"
[{:as opts :exoscale.project/keys [version-file]}]
(pio/shell [(format "git add %s" version-file)
"git commit -m \"Version $VERSION\""]
{:dir td/*the-dir*
:env {"VERSION" (v/get-version opts)}}))
Expand Down
24 changes: 17 additions & 7 deletions src/exoscale/tools/project/api/tasks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@
:revision-sha [{:run :exoscale.tools.project.standalone/revision-sha
:for-all [:exoscale.project/modules]}]

:release/single [{:run :exoscale.tools.project.standalone/version-remove-snapshot}
{:run :exoscale.tools.project.standalone/deploy}
{:run :exoscale.tools.project.standalone/git-commit-version}
{:run :exoscale.tools.project.standalone/git-tag-version}
{:run :exoscale.tools.project.standalone/version-bump-and-snapshot}
{:run :exoscale.tools.project.standalone/git-commit-version}
{:run :exoscale.tools.project.standalone/git-push}]
:release/single [{:run :exoscale.tools.project.standalone/version-remove-snapshot}
{:run :exoscale.tools.project.standalone/deploy}
{:run :exoscale.tools.project.standalone/git-commit-version}
{:run :exoscale.tools.project.standalone/git-tag-version}
{:run :exoscale.tools.project.standalone/version-bump-and-snapshot}
{:run :exoscale.tools.project.standalone/git-commit-version}
{:run :exoscale.tools.project.standalone/git-push}]

:release/modules [{:run :exoscale.tools.project.standalone/version-remove-snapshot}
{:ref :deploy}
Expand All @@ -98,6 +98,16 @@
{:run :exoscale.tools.project.standalone/git-commit-version}
{:run :exoscale.tools.project.standalone/git-push}]

:release+tag/single
[{:run :exoscale.tools.project.standalone/deploy}
{:run :exoscale.tools.project.standalone/git-tag-version}
{:run :exoscale.tools.project.standalone/git-push}]

:release+tag/modules
[{:ref :deploy}
{:run :exoscale.tools.project.standalone/git-tag-version}
{:run :exoscale.tools.project.standalone/git-push}]

:prep-self [{:run :exoscale.tools.project.standalone/prep-self
:for-all [:exoscale.project/modules]
:when :deps/prep-lib}]})
Expand Down
34 changes: 30 additions & 4 deletions src/exoscale/tools/project/api/version.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
(ns exoscale.tools.project.api.version
(:require [exoscale.deps-version :as version]))
(:require [clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.build.api :as b]
[clojure.tools.deps.alpha.util.dir :as td]
[exoscale.deps-version :as version]))

(defn run-version-fn [{:as opts :exoscale.project/keys [version-fn]}]
(when-let [f (requiring-resolve (symbol version-fn))]
(f opts)))

(defn get-version
[{:as _opts :exoscale.project/keys [version-file version]}]
(or version
(some-> version-file version/read-version-file*)))
[{:as opts :exoscale.project/keys [version-file version-fn version]}]
(let [version-from-file (some-> version-file version/read-version-file*)]
(cond
(string? version) version
(string? version-from-file) version-from-file
(qualified-ident? version-fn) (run-version-fn opts))))

(defn remove-snapshot
[{:as _opts
Expand All @@ -21,3 +32,18 @@
(version/update-version {:file version-file
:key version-key
:suffix version-suffix}))

(defn git-count-revs
"To be used via version-fn, returns version as VERSION_TEMPLATE with number of
commits on current branch replacing the GENERATED_VERSION placeholder"
[{:as _opts :exoscale.project/keys [version-template-file]
:or {version-template-file "VERSION_TEMPLATE"}}]
(str/replace (slurp (td/canonicalize (io/file version-template-file)))
"GENERATED_VERSION"
(b/git-count-revs nil)))

(defn epoch
"To be used via version-fn, returns version as VERSION_TEMPLATE with number of
seconds since epoch replacing the GENERATED_VERSION placeholder"
[_opts]
(.getEpochSecond (java.time.Instant/now)))
31 changes: 21 additions & 10 deletions src/exoscale/tools/project/standalone.clj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
(ns exoscale.tools.project.standalone
(:refer-clojure :exclude [test])
(:require [clojure.edn :as edn]
(:require [babashka.fs :as fs]
[clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.spec.alpha :as s]
[clojure.tools.deps.alpha.util.dir :as td]
[clojure.tools.deps.alpha.specs]
[babashka.fs :as fs]
[exoscale.deps-version :as version]
[clojure.tools.deps.alpha.util.dir :as td]
[exoscale.deps-modules :as deps-modules]
[exoscale.deps-version :as version]
[exoscale.lingo :as l]
[exoscale.tools.project.template :as template]
[exoscale.tools.project.api :as api]
[exoscale.tools.project.api.deploy :as deploy]
[exoscale.tools.project.api.git :as git]
[exoscale.tools.project.api.jar :as jar]
[exoscale.tools.project.api.tasks :as tasks]
[exoscale.tools.project.api.version :as v]))
[exoscale.tools.project.api.version :as v]
[exoscale.tools.project.template :as template]))

(def default-opts
#:exoscale.project{:file "deps.edn"
Expand All @@ -30,6 +30,8 @@

(s/def :exoscale.project/lib qualified-ident?)
(s/def :exoscale.project/version string?)
(s/def :exoscale.project/version-file string?)
(s/def :exoscale.project/version-fn qualified-ident?)
(s/def :exoscale.project/target-dir string?)
(s/def :exoscale.project/class-dir string?)
(s/def :exoscale.project/javac-opts (s/coll-of string?))
Expand All @@ -42,6 +44,7 @@
(s/keys :opt [:exoscale.project/lib
:exoscale.project/version
:exoscale.project/version-file
:exoscale.project/version-fn
:exoscale.project/target-dir
:exoscale.project/class-dir
:exoscale.project/javac-opts
Expand All @@ -59,10 +62,11 @@
(catch java.io.FileNotFoundException _fnf)))

(defn assoc-version
[{:as opts :exoscale.project/keys [version-file]}]
(cond-> opts
(some? version-file)
(assoc :exoscale.project/version (version/read-version-file* version-file))))
[{:as opts}]
(let [v (v/get-version opts)]
(cond-> opts
(some? v)
(assoc :exoscale.project/version v))))

(defn- assoc-deps-file
"unless explicit options are given, prepare deps-module configuration"
Expand Down Expand Up @@ -138,6 +142,13 @@
(assoc :id :release/single)
(tasks/task opts)))

(defn release+tag
[opts]
(-> opts
into-opts
(assoc :id :release+tag/single)
(tasks/task opts)))

(def ^{:arglists '([opts])} version-bump-and-snapshot
(comp v/bump-and-snapshot into-opts))

Expand Down

0 comments on commit 0e63bad

Please sign in to comment.