Skip to content

Commit cf01ea2

Browse files
Convert project to deps.clj, shadow-cljs (#50)
* Convert project to deps.clj, shadow-cljs (#47) * Make precision proportional to input magnitude since platforms differ --------- Co-authored-by: Sam Ritchie <[email protected]>
1 parent e40ea37 commit cf01ea2

29 files changed

+2569
-226
lines changed

.clj-kondo/config.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{:lint-as {clojure.test.check.clojure-test/defspec clj-kondo.lint-as/def-catch-all}}

.dir-locals.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
((nil
2+
. ((cider-default-cljs-repl . node)
3+
(cider-preferred-build-tool . clojure-cli)
4+
(cider-clojure-cli-aliases . ":dev:test"))))

.github/workflows/cljs.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CLJS Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Setup Java
15+
uses: actions/setup-java@v2
16+
with:
17+
distribution: zulu
18+
java-version: 17
19+
20+
- uses: DeLaGuardo/setup-clojure@master
21+
with:
22+
cli: latest
23+
bb: latest
24+
25+
- name: Setup Node.js for cljs
26+
uses: actions/setup-node@v2
27+
with:
28+
node-version: '16'
29+
30+
- name: Cache m2
31+
uses: actions/cache@v2
32+
with:
33+
path: ~/.m2
34+
key: m2-${{ hashFiles('deps.edn') }}
35+
36+
- name: Cache gitlibs
37+
uses: actions/cache@v2
38+
with:
39+
path: ~/.gitlibs
40+
key: gitlibs-${{ hashFiles('deps.edn') }}
41+
42+
- name: Install dependencies
43+
run: npm install
44+
45+
- name: ClojureScript tests
46+
run: bb test:cljs
47+
env:
48+
NODE_OPTIONS: --max-old-space-size=8192

.github/workflows/kondo.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Linter
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master]
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Install CLJ-Kondo
16+
uses: DeLaGuardo/setup-clojure@master
17+
with:
18+
bb: latest
19+
20+
- name: Cache kondo directory
21+
uses: actions/cache@v2
22+
with:
23+
path: ~/.clj-kondo/.cache
24+
key: ${{ runner.os }}-kondo
25+
restore-keys: ${{ runner.os }}-kondo
26+
27+
- name: Lint dependencies
28+
run: bb lint-deps
29+
30+
- name: Lint project files
31+
run: bb lint --config '{:output {:pattern "::{{level}} file={{filename}},line={{row}},col={{col}}::{{message}}"}}'

.github/workflows/release.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Release to Clojars
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
environment: Clojars Release
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- uses: DeLaGuardo/setup-clojure@master
15+
with:
16+
cli: latest
17+
18+
- name: Set up JDK 17
19+
uses: actions/setup-java@v2
20+
with:
21+
distribution: zulu
22+
java-version: 17
23+
24+
- name: Cache m2
25+
uses: actions/cache@v2
26+
with:
27+
path: ~/.m2
28+
key: m2-${{ hashFiles('deps.edn') }}
29+
30+
- name: Cache gitlibs
31+
uses: actions/cache@v2
32+
with:
33+
path: ~/.gitlibs
34+
key: gitlibs-${{ hashFiles('deps.edn') }}
35+
36+
- name: Install dependencies
37+
run: clojure -P -M:build
38+
39+
- name: Release
40+
run: clojure -T:build publish
41+
env:
42+
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }}
43+
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_TOKEN }}

.github/workflows/tests.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ jobs:
1818
- name: Setup Clojure tools
1919
uses: DeLaGuardo/setup-clojure@master
2020
with:
21-
lein: latest
21+
cli: latest
22+
bb: latest
2223

2324
- name: Checkout repository
2425
uses: actions/checkout@v2
@@ -27,10 +28,16 @@ jobs:
2728
uses: actions/cache@v2
2829
with:
2930
path: ~/.m2
30-
key: m2-${{ hashFiles('project.clj') }}
31+
key: m2-${{ hashFiles('deps.edn') }}
32+
33+
- name: Cache gitlibs
34+
uses: actions/cache@v2
35+
with:
36+
path: ~/.gitlibs
37+
key: gitlibs-${{ hashFiles('deps.edn') }}
3138

3239
- name: Prepare dependencies
33-
run: lein deps
40+
run: clojure -P -M:test:runner
3441

3542
- name: Run Clojure tests
36-
run: lein test
43+
run: bb test:clj

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ pom.xml.asc
1010
.hgignore
1111
.hg/
1212
/out
13-
.clj-kondo/
13+
.clj-kondo/.lock
14+
.clj-kondo/inline-configs
15+
.clj-kondo/.cache
1416
.lsp/
17+
!template/pom.xml
18+
public/
19+
node_modules
20+
**.shadow-cljs

DEVELOPING.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Dev dependencies
2+
3+
- [node.js](https://nodejs.org/en/)
4+
- The [Clojure command line tool](https://clojure.org/guides/install_clojure)
5+
- [Babashka](https://github.com/babashka/babashka#installation)
6+
7+
## Publishing to Clojars
8+
9+
The template for the project's `pom.xml` lives at
10+
[`template/pom.xml`](https://github.com/MastodonC/kixi.stats/blob/main/template/pom.xml).
11+
12+
To create a new release:
13+
14+
- Update the version in [build.clj](https://github.com/MastodonC/kixi.stats/blob/main/build.clj)
15+
- Make a new [Github Release](https://github.com/MastodonC/kixi.stats/releases) with tag `v<the-new-version>`.
16+
17+
Submitting the release will create the new tag and trigger the following
18+
command:
19+
20+
```
21+
bb release
22+
```
23+
24+
The new release will appear on Clojars.
25+
26+
## Linting
27+
28+
Code is linted with [`clj-kondo`](https://github.com/clj-kondo/clj-kondo):
29+
30+
```
31+
bb lint
32+
```
33+
34+
The first time you interact with the project, run the following command to lint
35+
all dependencies and populate the `clj-kondo` cache:
36+
37+
```
38+
bb lint-deps
39+
```

README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
A Clojure/ClojureScript library of statistical sampling and transducing functions.
44

5+
<div align="center">
6+
7+
[![Build Status][build-status]][build-status-url]
8+
[![License][license]][license-url]
9+
[![cljdoc badge][cljdoc]][cljdoc-url]
10+
[![Clojars Project][clojars]][clojars-url]
11+
12+
</div>
13+
514
**Available distributions:**
615

716
* Bernoulli
@@ -74,10 +83,19 @@ Examples of `kixi.stats` usage can be seen between 10:20-16:00 of this video on
7483

7584
## Installation
7685

77-
Add the following dependency:
86+
Install `kixi.stats` into your Clojure project using the appropriate form at its
87+
Clojars page:
7888

79-
```clojure
80-
[kixi/stats "0.5.5"]
89+
[![Clojars Project][clojars]][clojars-url]
90+
91+
Or grab the most recent code using a Git dependency:
92+
93+
```clj
94+
replace $GIT_SHA with the sha you'd like to target!
95+
96+
{kixi/stats
97+
{:git/url "https://github.com/MastodonC/kixi.stats.git"
98+
:git/sha "$GIT_SHA"}}
8199
```
82100

83101
## Usage
@@ -299,3 +317,12 @@ Pseudorandom number generation is provided by [test.check](https://github.com/cl
299317
Copyright © 2024 Mastodon C Ltd
300318

301319
Distributed under the Eclipse Public License version 1.0.
320+
321+
[build-status-url]: https://github.com/MastodonC/kixi.stats/actions?query=workflow%3A%22Clojure+CI%22
322+
[build-status]: https://github.com/MastodonC/kixi.stats/workflows/Clojure%20CI/badge.svg?branch=master
323+
[license-url]: LICENSE
324+
[license]: https://img.shields.io/badge/license-EPLv1-brightgreen.svg
325+
[cljdoc-url]: https://cljdoc.org/d/kixi/stats/CURRENT
326+
[cljdoc]: https://cljdoc.org/badge/kixi/stats
327+
[clojars-url]: https://clojars.org/kixi/stats
328+
[clojars]: https://img.shields.io/clojars/v/kixi/stats.svg

bb.edn

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{:deps {io.github.clj-kondo/clj-kondo-bb
2+
{:git/sha "178b027e827172da0d63122a754bb4d765a6faeb"}}
3+
4+
:tasks
5+
{test:clj
6+
{:doc "Run CLJ tests."
7+
:task (shell "clojure -X:test:runner")}
8+
9+
test:cljs
10+
{:doc "Run CLJS tests."
11+
:task (shell "npm run test")}
12+
13+
release
14+
{:doc "Release the library to Clojars."
15+
:task (shell "clojure -T:build publish")}
16+
17+
lint-deps
18+
{:requires ([clj-kondo.core :as kondo])
19+
:doc "Lint dependencies."
20+
:task (kondo/run!
21+
{:lint [(with-out-str
22+
(babashka.tasks/clojure "-Spath -A:dev:test"))]
23+
:dependencies true})}
24+
25+
lint
26+
{:doc "Lint source-containing directories with clj-kondo."
27+
:task (exec 'clj-kondo.core/exec)
28+
:exec-args {:lint ["src" "test"]}}}}

build.clj

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
(ns build
2+
"tools.build declarations for the gen.clj library."
3+
(:require [clojure.tools.build.api :as b]))
4+
5+
;; ## Variables
6+
7+
(def lib 'kixi/stats)
8+
(def version "0.5.5")
9+
10+
(defn- ->version
11+
([] version)
12+
([suffix]
13+
(if suffix
14+
(format "%s-%s" version suffix)
15+
version)))
16+
17+
;; source for jar creation.
18+
(def class-dir "target/classes")
19+
(def basis
20+
(b/create-basis
21+
{:project "deps.edn"}))
22+
23+
(defn ->jar-file [version]
24+
(format "target/%s-%s.jar" (name lib) version))
25+
26+
;; ## Tasks
27+
28+
(defn clean [opts]
29+
(println "\nCleaning target...")
30+
(b/delete {:path "target"})
31+
opts)
32+
33+
(defn jar
34+
"Builds a jar containing all library code and
35+
36+
Optionally supply a string via `:version-suffix` to append `-<suffix>` to the
37+
generated version."
38+
[{:keys [version-suffix] :as opts}]
39+
(let [version (->version version-suffix)
40+
jar-file (->jar-file version)]
41+
(b/write-pom {:class-dir class-dir
42+
:lib lib
43+
:version version
44+
:scm
45+
{:tag (str "v" version)
46+
:connection "scm:git:git://github.com/MastodonC/kixi.stats.git"
47+
:developConnection "scm:git:git://github.com/MastodonC/kixi.stats.git"
48+
:url "https://github.com/MastodonC/kixi.stats"}
49+
:basis basis
50+
:src-pom "template/pom.xml"
51+
:src-dirs ["src"]})
52+
(doseq [f ["README.md" "LICENSE" "deps.edn"]]
53+
(b/copy-file {:src f :target (format "%s/%s" class-dir f)}))
54+
(b/copy-dir {:src-dirs ["src"]
55+
:target-dir class-dir})
56+
(b/jar {:class-dir class-dir
57+
:jar-file jar-file})
58+
(println (str "Created " jar-file "."))
59+
(assoc opts
60+
:jar-file jar-file
61+
:built-jar-version version)))
62+
63+
(defn install
64+
"Clean, generate a jar and install the jar into the local Maven repository."
65+
[opts]
66+
(clean opts)
67+
(let [{:keys [built-jar-version jar-file]} (jar opts)]
68+
(b/install {:class-dir class-dir
69+
:lib lib
70+
:version built-jar-version
71+
:basis basis
72+
:jar-file jar-file})
73+
(println (str "Installed " jar-file " to local Maven repository."))
74+
opts))
75+
76+
(defn publish
77+
"Generates a jar with all project sources and resources and publishes it to
78+
Clojars."
79+
[opts]
80+
(clean opts)
81+
(let [{:keys [jar-file]} (jar opts)]
82+
(println (str "Publishing " jar-file " to Clojars!"))
83+
((requiring-resolve 'deps-deploy.deps-deploy/deploy)
84+
(merge {:installer :remote
85+
:sign-releases? false
86+
:artifact jar-file
87+
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}
88+
opts))
89+
(println "Published.")
90+
opts))

0 commit comments

Comments
 (0)