Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert project to deps.clj, shadow-cljs #50

Merged
merged 5 commits into from
Oct 4, 2024
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
1 change: 1 addition & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:lint-as {clojure.test.check.clojure-test/defspec clj-kondo.lint-as/def-catch-all}}
4 changes: 4 additions & 0 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
((nil
. ((cider-default-cljs-repl . node)
(cider-preferred-build-tool . clojure-cli)
(cider-clojure-cli-aliases . ":dev:test"))))
48 changes: 48 additions & 0 deletions .github/workflows/cljs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CLJS Tests

on:
pull_request:
push:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: zulu
java-version: 17

- uses: DeLaGuardo/setup-clojure@master
with:
cli: latest
bb: latest

- name: Setup Node.js for cljs
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Cache m2
uses: actions/cache@v2
with:
path: ~/.m2
key: m2-${{ hashFiles('deps.edn') }}

- name: Cache gitlibs
uses: actions/cache@v2
with:
path: ~/.gitlibs
key: gitlibs-${{ hashFiles('deps.edn') }}

- name: Install dependencies
run: npm install

- name: ClojureScript tests
run: bb test:cljs
env:
NODE_OPTIONS: --max-old-space-size=8192
31 changes: 31 additions & 0 deletions .github/workflows/kondo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Linter

on:
pull_request:
push:
branches: [master]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install CLJ-Kondo
uses: DeLaGuardo/setup-clojure@master
with:
bb: latest

- name: Cache kondo directory
uses: actions/cache@v2
with:
path: ~/.clj-kondo/.cache
key: ${{ runner.os }}-kondo
restore-keys: ${{ runner.os }}-kondo

- name: Lint dependencies
run: bb lint-deps

- name: Lint project files
run: bb lint --config '{:output {:pattern "::{{level}} file={{filename}},line={{row}},col={{col}}::{{message}}"}}'
43 changes: 43 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release to Clojars

on:
release:
types: [published]

jobs:
release:
runs-on: ubuntu-latest
environment: Clojars Release
steps:
- uses: actions/checkout@v2

- uses: DeLaGuardo/setup-clojure@master
with:
cli: latest

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: zulu
java-version: 17

- name: Cache m2
uses: actions/cache@v2
with:
path: ~/.m2
key: m2-${{ hashFiles('deps.edn') }}

- name: Cache gitlibs
uses: actions/cache@v2
with:
path: ~/.gitlibs
key: gitlibs-${{ hashFiles('deps.edn') }}

- name: Install dependencies
run: clojure -P -M:build

- name: Release
run: clojure -T:build publish
env:
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }}
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_TOKEN }}
15 changes: 11 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jobs:
- name: Setup Clojure tools
uses: DeLaGuardo/setup-clojure@master
with:
lein: latest
cli: latest
bb: latest

- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -27,10 +28,16 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2
key: m2-${{ hashFiles('project.clj') }}
key: m2-${{ hashFiles('deps.edn') }}

- name: Cache gitlibs
uses: actions/cache@v2
with:
path: ~/.gitlibs
key: gitlibs-${{ hashFiles('deps.edn') }}

- name: Prepare dependencies
run: lein deps
run: clojure -P -M:test:runner

- name: Run Clojure tests
run: lein test
run: bb test:clj
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ pom.xml.asc
.hgignore
.hg/
/out
.clj-kondo/
.clj-kondo/.lock
.clj-kondo/inline-configs
.clj-kondo/.cache
.lsp/
!template/pom.xml
public/
node_modules
**.shadow-cljs
39 changes: 39 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## Dev dependencies

- [node.js](https://nodejs.org/en/)
- The [Clojure command line tool](https://clojure.org/guides/install_clojure)
- [Babashka](https://github.com/babashka/babashka#installation)

## Publishing to Clojars

The template for the project's `pom.xml` lives at
[`template/pom.xml`](https://github.com/MastodonC/kixi.stats/blob/main/template/pom.xml).

To create a new release:

- Update the version in [build.clj](https://github.com/MastodonC/kixi.stats/blob/main/build.clj)
- Make a new [Github Release](https://github.com/MastodonC/kixi.stats/releases) with tag `v<the-new-version>`.

Submitting the release will create the new tag and trigger the following
command:

```
bb release
```

The new release will appear on Clojars.

## Linting

Code is linted with [`clj-kondo`](https://github.com/clj-kondo/clj-kondo):

```
bb lint
```

The first time you interact with the project, run the following command to lint
all dependencies and populate the `clj-kondo` cache:

```
bb lint-deps
```
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

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

<div align="center">

[![Build Status][build-status]][build-status-url]
[![License][license]][license-url]
[![cljdoc badge][cljdoc]][cljdoc-url]
[![Clojars Project][clojars]][clojars-url]

</div>

**Available distributions:**

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

## Installation

Add the following dependency:
Install `kixi.stats` into your Clojure project using the appropriate form at its
Clojars page:

```clojure
[kixi/stats "0.5.5"]
[![Clojars Project][clojars]][clojars-url]

Or grab the most recent code using a Git dependency:

```clj
replace $GIT_SHA with the sha you'd like to target!

{kixi/stats
{:git/url "https://github.com/MastodonC/kixi.stats.git"
:git/sha "$GIT_SHA"}}
```

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

Distributed under the Eclipse Public License version 1.0.

[build-status-url]: https://github.com/MastodonC/kixi.stats/actions?query=workflow%3A%22Clojure+CI%22
[build-status]: https://github.com/MastodonC/kixi.stats/workflows/Clojure%20CI/badge.svg?branch=master
[license-url]: LICENSE
[license]: https://img.shields.io/badge/license-EPLv1-brightgreen.svg
[cljdoc-url]: https://cljdoc.org/d/kixi/stats/CURRENT
[cljdoc]: https://cljdoc.org/badge/kixi/stats
[clojars-url]: https://clojars.org/kixi/stats
[clojars]: https://img.shields.io/clojars/v/kixi/stats.svg
28 changes: 28 additions & 0 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{:deps {io.github.clj-kondo/clj-kondo-bb
{:git/sha "178b027e827172da0d63122a754bb4d765a6faeb"}}

:tasks
{test:clj
{:doc "Run CLJ tests."
:task (shell "clojure -X:test:runner")}

test:cljs
{:doc "Run CLJS tests."
:task (shell "npm run test")}

release
{:doc "Release the library to Clojars."
:task (shell "clojure -T:build publish")}

lint-deps
{:requires ([clj-kondo.core :as kondo])
:doc "Lint dependencies."
:task (kondo/run!
{:lint [(with-out-str
(babashka.tasks/clojure "-Spath -A:dev:test"))]
:dependencies true})}

lint
{:doc "Lint source-containing directories with clj-kondo."
:task (exec 'clj-kondo.core/exec)
:exec-args {:lint ["src" "test"]}}}}
90 changes: 90 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
(ns build
"tools.build declarations for the gen.clj library."
(:require [clojure.tools.build.api :as b]))

;; ## Variables

(def lib 'kixi/stats)
(def version "0.5.5")

(defn- ->version
([] version)
([suffix]
(if suffix
(format "%s-%s" version suffix)
version)))

;; source for jar creation.
(def class-dir "target/classes")
(def basis
(b/create-basis
{:project "deps.edn"}))

(defn ->jar-file [version]
(format "target/%s-%s.jar" (name lib) version))

;; ## Tasks

(defn clean [opts]
(println "\nCleaning target...")
(b/delete {:path "target"})
opts)

(defn jar
"Builds a jar containing all library code and

Optionally supply a string via `:version-suffix` to append `-<suffix>` to the
generated version."
[{:keys [version-suffix] :as opts}]
(let [version (->version version-suffix)
jar-file (->jar-file version)]
(b/write-pom {:class-dir class-dir
:lib lib
:version version
:scm
{:tag (str "v" version)
:connection "scm:git:git://github.com/MastodonC/kixi.stats.git"
:developConnection "scm:git:git://github.com/MastodonC/kixi.stats.git"
:url "https://github.com/MastodonC/kixi.stats"}
:basis basis
:src-pom "template/pom.xml"
:src-dirs ["src"]})
(doseq [f ["README.md" "LICENSE" "deps.edn"]]
(b/copy-file {:src f :target (format "%s/%s" class-dir f)}))
(b/copy-dir {:src-dirs ["src"]
:target-dir class-dir})
(b/jar {:class-dir class-dir
:jar-file jar-file})
(println (str "Created " jar-file "."))
(assoc opts
:jar-file jar-file
:built-jar-version version)))

(defn install
"Clean, generate a jar and install the jar into the local Maven repository."
[opts]
(clean opts)
(let [{:keys [built-jar-version jar-file]} (jar opts)]
(b/install {:class-dir class-dir
:lib lib
:version built-jar-version
:basis basis
:jar-file jar-file})
(println (str "Installed " jar-file " to local Maven repository."))
opts))

(defn publish
"Generates a jar with all project sources and resources and publishes it to
Clojars."
[opts]
(clean opts)
(let [{:keys [jar-file]} (jar opts)]
(println (str "Publishing " jar-file " to Clojars!"))
((requiring-resolve 'deps-deploy.deps-deploy/deploy)
(merge {:installer :remote
:sign-releases? false
:artifact jar-file
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}
opts))
(println "Published.")
opts))
Loading
Loading