Skip to content

Commit 4871f18

Browse files
committed
internal build: migrate to tools.build
Respond to depstar being deprecated in favour of tools.build. Our new build.clj is responsible for: - building jar - local m2 repo installs (switched from deps-deploy to tools.build) - deploys to clojars (still using deps-deploy, no equivalent in tools.build yet) - generating artifact version - returning last built artifact version Our pom.xml has become anemic and now acts as a template to tools.build when building pom.xml for artifacts. Because our git commited pom.xml no longer contains deps, I no longer have to suppress antq reporting on Clojure 1.9.0 being outdated in pom.xml from our bb outdated task. We had already been using a version suffix of canary for local install of rewrite-clj created and used by test-libs bb task. We now use a version suffix of cljdoc-preview for cljdoc-preview bb task for locally installed rewrite-clj. These suffixes are good signals for me to recognize the source of these rewrite-clj test versions in my m2 repo.
1 parent 8bdb642 commit 4871f18

File tree

13 files changed

+181
-207
lines changed

13 files changed

+181
-207
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
run: bb ci-release commit
6969

7070
- name: Make GitHub Actions aware of target version tag
71-
run: echo "::set-output name=tag::v$(cat ./target/target-version.txt)"
71+
run: echo "::set-output name=tag::v$(clojure -T:build built-version)"
7272
id: target-version
7373

7474
- name: Create GitHub release (step 4 of 4)

CHANGELOG.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ For a list of breaking changes see link:#v1-breaking[breaking changes].
1616

1717
=== Unreleased
1818

19+
* internal rewrite-clj developer facing:
20+
** Migrate from `depstar` to `tools.build`
21+
1922
=== v1.0.682-alpha
2023

2124
* update clojure tools.reader dependency to v1.3.6

bb.edn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
:deps {org.clojure/data.zip {:mvn/version "1.0.0"}
44
io.aviso/pretty {:mvn/version "1.1"}
55
dev.nubank/docopt {:mvn/version "0.6.1-fix7"}
6-
com.github.liquidz/antq {:mvn/version "1.0.1"}
76
doric/doric {:mvn/version "0.9.0"}
87
version-clj/version-clj {:mvn/version "2.0.2"}
98
lread/status-line {:git/url "https://github.com/lread/status-line.git"

build.clj

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
(ns build
2+
(:require [clojure.edn :as edn]
3+
[clojure.java.io :as io]
4+
[clojure.tools.build.api :as b]
5+
[deps-deploy.deps-deploy :as dd]))
6+
7+
(def lib 'rewrite-clj/rewrite-clj)
8+
(def version (let [version-template (-> "version.edn" slurp edn/read-string)
9+
patch (b/git-count-revs nil)]
10+
(str (:major version-template) "."
11+
(:minor version-template) "."
12+
patch
13+
(cond->> (:qualifier version-template)
14+
true (str "-")))))
15+
(def class-dir "target/classes")
16+
(def basis (b/create-basis {:project "deps.edn"}))
17+
(def jar-file (format "target/%s.jar" (name lib)))
18+
(def built-jar-version-file "target/built-jar-version.txt")
19+
20+
(defn jar
21+
"Build library jar file.
22+
Also writes built version to target/built-jar-version.txt for easy peasy pickup by any interested downstream operation.
23+
24+
We use the optional :version-suffix to distinguish local installs from production releases.
25+
For example, when testing 3rd party libs against rewrite-clj master we use the suffix: canary. "
26+
[{:keys [version-suffix]}]
27+
(b/delete {:path class-dir})
28+
(b/delete {:path jar-file})
29+
(let [version (if version-suffix (format "%s-%s" version version-suffix)
30+
version)]
31+
(b/write-pom {:class-dir class-dir
32+
:lib lib
33+
:version version
34+
:scm {:tag (format "v%s" version)}
35+
:basis basis
36+
:src-dirs ["src"]})
37+
(b/copy-dir {:src-dirs ["src" "resources"]
38+
:target-dir class-dir})
39+
(b/jar {:class-dir class-dir
40+
:jar-file jar-file})
41+
(spit built-jar-version-file version)))
42+
43+
(defn- built-version* []
44+
(when (not (.exists (io/file built-jar-version-file)))
45+
(throw (ex-info (str "Built jar version file not found: " built-jar-version-file) {})))
46+
(slurp built-jar-version-file))
47+
48+
(defn built-version
49+
;; NOTE: Used by release script and github workflow
50+
"Spit out version of jar built (with no trailing newline).
51+
A separate task because I don't know what build.tools might spit to stdout."
52+
[_]
53+
(print (built-version*))
54+
(flush))
55+
56+
(defn install
57+
"Install built jar to local maven repo"
58+
[_]
59+
(b/install {:class-dir class-dir
60+
:lib lib
61+
:version (built-version*)
62+
:basis basis
63+
:jar-file jar-file}))
64+
65+
(defn deploy
66+
"Deploy built jar to clojars"
67+
[_]
68+
(dd/deploy {:installer :remote
69+
:artifact jar-file
70+
:pom-file (b/pom-path lib :class-dir class-dir)}))
71+
72+
(defn project-lib
73+
"Returns project groupid/artifactid"
74+
[_]
75+
(println lib))

deps.edn

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,9 @@
106106
;;
107107
;; Deployment
108108
;;
109-
:jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.297"}}
110-
:exec-fn hf.depstar/jar
111-
:exec-args {:jar "target/rewrite-clj.jar"
112-
:paths-only true
113-
:verbose true
114-
:jar-type :thin}}
115-
116-
:deploy {:replace-deps {slipset/deps-deploy {:mvn/version "0.1.5"}}
117-
:exec-fn deps-deploy.deps-deploy/deploy}
118-
119-
;; usage: :deploy:remote - for Clojars
120-
:remote {:exec-args {:installer :remote
121-
:artifact "target/rewrite-clj.jar"}}
122-
123-
;; usage: :deploy:local - for local maven repo
124-
:local {:exec-args {:installer :local
125-
:artifact "target/rewrite-clj.jar"}}
109+
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.5.0" :git/sha "7d77952"}
110+
io.github.slipset/deps-deploy {:sha "3d20d0ee86c35c431e4fcf5b0830a3785e8116c0"}}
111+
:ns-default build}
126112

127113
;;
128114
;; Maintenance support
@@ -131,6 +117,5 @@
131117
org.slf4j/slf4j-simple {:mvn/version "1.7.32"} ;; to rid ourselves of logger warnings
132118
}
133119
:main-opts ["-m" "antq.core"
134-
"--reporter=edn"
135120
"--exclude=lambdaisland/[email protected]" ;; https://github.com/lambdaisland/kaocha/issues/208
136121
]}}}

doc/02-developer-guide.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,11 @@ To see what new dependencies are available, run:
278278
bb outdated
279279
----
280280

281-
We use https://github.com/liquidz/antq[antq] which also checks `pom.xml`.
282-
If you see an outdated dependency reported for `pom.xml` after updating `deps.edn`, run the following:
281+
This task uses:
283282

284-
----
285-
clojure -Spom
286-
----
287-
288-
This script also checks for outdated Node.js dependencies.
289-
Note that checks are only done against installed `./node_modules`, so you may want to run `npm install` first.
283+
* https://github.com/liquidz/antq[antq] for Clojure.
284+
* npm for JavaScript.
285+
It only checks against installed `./node_modules`, so you may want to run `npm install` first.
290286

291287
[#linting]
292288
== Linting
@@ -363,6 +359,10 @@ bb cljdoc-preview ingest
363359
----
364360

365361
The ingest command automatically publishes rewrite-clj to your local maven repository (cljdoc only works with published jars).
362+
363+
The locally published version will include a `-cljdoc-preview` suffix.
364+
I find this distinction helps to reduce confusion around locally vs remotely installed artifacts.
365+
366366
You'll have to remember to git commit and git push your changes before ingesting.
367367

368368
Repeat these steps any time you want to preview changes.

doc/04-maintainer-guide.adoc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ The released workflow is handled by our https://github.com/clj-commons/rewrite-c
1212

1313
The release workflow:
1414

15-
. Calculates a version using our versioning scheme and applies it to:
16-
.. `deps.edn` usage example in the user guide
17-
.. "unreleased" and "unreleased breaking changes" headings in the change log
18-
.. ``pom.xml``'s `version` and `scm`->`tag`
19-
. Create a thin jar
15+
. Create a thin jar using our version scheme
16+
. Apply jar version to following docs:
17+
.. user guide docs `deps.edn` usage example
18+
.. change log "unreleased" and "unreleased breaking changes" headings
2019
. Deploy the jar to clojars
21-
. Commit and push updates made to `CHANGELOG.adoc`, `pom.xml` and `01-user-guide.adoc` back to the project
20+
. Commit and push updates made to `CHANGELOG.adoc` and `01-user-guide.adoc` back to the project
2221
. Create and push a release tag back to the project repo
2322
. Inform cljdoc of the new release
2423

@@ -48,9 +47,9 @@ If you so wish, you can also locally run all steps up to, but not including, dep
4847

4948
[source,shell]
5049
----
51-
bb release prep
50+
bb ci-release prep
5251
----
53-
Be aware though that you will NOT want to check in changes `prep` makes to `CHANGELOG.adoc`, `pom.xml` and `01-user-guide.adoc`.
52+
Be aware though that you will NOT want to check in changes `prep` makes to `CHANGELOG.adoc` and `01-user-guide.adoc`.
5453

5554
=== Invoking
5655

pom.xml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<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">
33
<modelVersion>4.0.0</modelVersion>
4-
<groupId>rewrite-clj</groupId>
5-
<artifactId>rewrite-clj</artifactId>
6-
<version>1.0.682-alpha</version>
74
<name>rewrite-clj</name>
8-
<description>A library that reads and writes Clojure, ClojureScript and EDN from Clojure and ClojureScript in a whitespace and comment preserving way.</description>
5+
<description>Rewrite Clojure code and edn2</description>
96
<url>https://github.com/clj-commons/rewrite-clj</url>
107
<scm>
118
<url>https://github.com/clj-commons/rewrite-clj</url>
129
<connection>scm:git:[email protected]:clj-commons/rewrite-clj.git</connection>
1310
<developerConnection>scm:git:[email protected]:clj-commons/rewrite-clj.git</developerConnection>
14-
<tag>v1.0.682-alpha</tag>
1511
</scm>
16-
<dependencies>
17-
<dependency>
18-
<groupId>org.clojure</groupId>
19-
<artifactId>clojure</artifactId>
20-
<version>1.9.0</version>
21-
</dependency>
22-
<dependency>
23-
<groupId>org.clojure</groupId>
24-
<artifactId>tools.reader</artifactId>
25-
<version>1.3.6</version>
26-
</dependency>
27-
</dependencies>
2812
<properties>
2913
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3014
</properties>
31-
<build>
32-
<sourceDirectory>src</sourceDirectory>
33-
<resources>
34-
<resource>
35-
<directory>src</directory>
36-
</resource>
37-
</resources>
38-
</build>
3915
<repositories>
4016
<repository>
4117
<id>clojars</id>

script/ci_release.clj

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,18 @@
1010
[helper.fs :as fs]
1111
[helper.main :as main]
1212
[helper.shell :as shell]
13-
[lread.status-line :as status]
14-
[release.version :as version]))
13+
[lread.status-line :as status]))
1514

1615
(defn clean! []
1716
(doseq [dir ["target" ".cpcache"]]
1817
(fs/delete-file-recursively dir true)))
1918

2019
(defn- last-release-tag []
21-
(-> (shell/command {:out :string}
20+
(-> (shell/command {:out :string}
2221
"git describe --abbrev=0 --match v[0-9]*")
2322
:out
2423
string/trim))
2524

26-
(defn- calculate-version []
27-
(status/line :head "Calculating release version")
28-
(let [version (version/calc)]
29-
(status/line :detail (str "version: " version))
30-
version))
31-
3225
(defn- update-file! [fname match-replacements]
3326
(let [old-content (slurp fname)
3427
new-content (reduce (fn [in [desc match replacement]]
@@ -105,14 +98,17 @@
10598
#"(?im)(=+) +unreleased breaking changes *$"
10699
(str "$1 v" version)]))))
107100

108-
(defn- create-jar! [version]
109-
(status/line :head (str "Creating jar for version " version))
110-
(status/line :detail "Reflecting deps in deps.edn to pom.xml")
111-
(shell/command "clojure -Spom")
112-
(status/line :detail "Updating pom.xml version and creating thin jar")
113-
(shell/command "clojure -X:jar :version" (pr-str version))
101+
(defn- create-jar! []
102+
(status/line :head "Creating jar for release")
103+
(shell/command "clojure -T:build jar")
114104
nil)
115105

106+
(defn- built-version []
107+
(-> (shell/command {:out :string}
108+
"clojure -T:build built-version")
109+
:out
110+
string/trim))
111+
116112
(defn- assert-on-ci
117113
"Little blocker to save myself from myself when testing."
118114
[action]
@@ -124,15 +120,15 @@
124120
[]
125121
(status/line :head "Deploying jar to clojars")
126122
(assert-on-ci "deploy a jar")
127-
(shell/command "clojure -X:deploy:remote")
123+
(shell/command "clojure -T:build deploy")
128124
nil)
129125

130126
(defn- commit-changes! [version]
131127
(let [tag-version (str "v" version)]
132128
(status/line :head (str "Committing and pushing changes made for " tag-version))
133129
(assert-on-ci "commit changes")
134130
(status/line :detail "Adding changes")
135-
(shell/command "git add doc/01-user-guide.adoc CHANGELOG.adoc pom.xml")
131+
(shell/command "git add doc/01-user-guide.adoc CHANGELOG.adoc")
136132
(status/line :detail "Committing")
137133
(shell/command "git commit -m" (str "Release job: updates for version " tag-version))
138134
(status/line :detail "Version tagging")
@@ -155,7 +151,7 @@
155151
(when (not (zero? exit-code))
156152
(status/line :warn (str "Informing cljdoc did not seem to work, exited with " exit-code)))))
157153

158-
(def args-usage "Valid args: (prep|deploy-remote|commit|validate|version|--help)
154+
(def args-usage "Valid args: (prep|deploy-remote|commit|validate|--help)
159155
160156
Commands:
161157
prep Update user guide, changelog and create jar
@@ -168,48 +164,36 @@ To restrict the exposure of our CLOJARS secrets during deploy workflow
168164
169165
Additional commands:
170166
validate Verify that change log is good for release
171-
version Calculate and report version
172167
173168
Options
174169
--help Show this help")
175170

176171
(defn -main [& args]
177172
(when-let [opts (main/doc-arg-opt args-usage args)]
178-
(let [target-version-filename "target/target-version.txt"]
179-
(cond
180-
(get opts "prep")
181-
(do (clean!)
182-
(let [changelog-status (validate-changelog)
183-
target-version (calculate-version)
184-
last-version (last-release-tag)]
185-
(status/line :detail (str "Last version released: " (or last-version "<none>")))
186-
(status/line :detail (str "Target version: " target-version))
187-
(io/make-parents target-version-filename)
188-
(spit target-version-filename target-version)
189-
(update-user-guide! target-version)
190-
(update-changelog! target-version last-version changelog-status)
191-
(create-jar! target-version)))
192-
193-
(get opts "deploy-remote")
194-
(deploy-jar!)
195-
196-
(get opts "commit")
197-
(if (not (.exists (io/file target-version-filename)))
198-
(status/die 1
199-
"Target version file not found: %s\nWas prep step run?"
200-
target-version-filename)
201-
(let [target-version (slurp target-version-filename)]
202-
(commit-changes! target-version)
203-
(inform-cljdoc! target-version)))
204-
205-
(get opts "validate")
206-
(do (validate-changelog)
207-
nil)
208-
209-
(get opts "version")
210-
(do (calculate-version)
211-
nil)))))
173+
(cond
174+
(get opts "prep")
175+
(do (clean!)
176+
(let [changelog-status (validate-changelog)
177+
last-version (last-release-tag)]
178+
(status/line :detail (str "Last version released: " (or last-version "<none>")))
179+
(io/make-parents "target")
180+
(create-jar!)
181+
(let [version (built-version)]
182+
(status/line :detail (str "Built version: " version))
183+
(update-user-guide! version)
184+
(update-changelog! version last-version changelog-status))))
185+
186+
(get opts "deploy-remote")
187+
(deploy-jar!)
188+
189+
(get opts "commit")
190+
(let [version (built-version)]
191+
(commit-changes! version)
192+
(inform-cljdoc! version))
193+
194+
(get opts "validate")
195+
(do (validate-changelog)
196+
nil))))
212197

213198
(main/when-invoked-as-script
214199
(apply -main *command-line-args*))
215-

0 commit comments

Comments
 (0)