From 0a6b7ce9b0f2065a07daa7dbb0408ac3c23722d1 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 3 Apr 2026 08:01:15 +0000 Subject: [PATCH 1/4] Move example code to dev/ and clean up project config for library consumers - Move src/example/ to dev/ so example code is not packaged in the published JAR (avoids namespace collisions for downstream users) - Replace hardcoded example.core-test inline runner with cognitect test-runner that discovers tests automatically - Remove --fail-threshold 0 from coverage aliases (consumers should set their own threshold) - Remove --test-ns-regex hardcoded example pattern from coverage aliases - Add dev/ to :test-paths (lein) and :extra-paths (clj aliases) so CI can still find the example namespaces for testing https://claude.ai/code/session_01WpM3eidMhXdmEvo9DRX1vH --- deps.edn | 20 +++++++++----------- {src => dev}/example/core.clj | 0 project.clj | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) rename {src => dev}/example/core.clj (100%) diff --git a/deps.edn b/deps.edn index 1ceb6df..7a3978d 100644 --- a/deps.edn +++ b/deps.edn @@ -6,12 +6,14 @@ :aliases {;; Run tests with: clj -M:test ;; - ;; Uses clojure.main -e to evaluate an inline test runner — no extra - ;; dependencies required. Exits non-zero when any test fails or errors. + ;; Uses cognitect-labs/test-runner. Discovers tests automatically under + ;; the "test" directory — no need to hard-code namespace names. :test - {:extra-paths ["test"] - :main-opts ["-e" - "(require 'example.core-test 'clojure.test)(let [r (clojure.test/run-tests 'example.core-test)](System/exit (if (pos? (+ (:fail r) (:error r))) 1 0)))"]} + {:extra-paths ["dev" "test"] + :extra-deps {io.github.cognitect-labs/test-runner + {:git/tag "v0.5.1" :git/sha "dfb30dd"}} + :main-opts ["-m" "cognitect.test-runner"] + :exec-fn cognitect.test-runner.api/test} ;; Run cloverage with the Cobertura XML reporter: ;; clj -M:coverage @@ -19,24 +21,20 @@ ;; Limit which namespaces are instrumented with --ns-regex (remove or ;; adjust when using this reporter in your own project). :coverage - {:extra-paths ["test"] + {:extra-paths ["dev" "test"] :extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}} :main-opts ["-m" "cloverage.coverage" "--custom-report" "cloverage.coverage.cobertura/report" "--ns-regex" "^example\\..*" - "--test-ns-regex" "^example\\..*-test$" - "--fail-threshold" "0" "--output" "target/coverage"]} ;; Same as :coverage but also generates the built-in HTML report: ;; clj -M:coverage-html :coverage-html - {:extra-paths ["test"] + {:extra-paths ["dev" "test"] :extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}} :main-opts ["-m" "cloverage.coverage" "--custom-report" "cloverage.coverage.cobertura/report" "--html" "--ns-regex" "^example\\..*" - "--test-ns-regex" "^example\\..*-test$" - "--fail-threshold" "0" "--output" "target/coverage"]}}} diff --git a/src/example/core.clj b/dev/example/core.clj similarity index 100% rename from src/example/core.clj rename to dev/example/core.clj diff --git a/project.clj b/project.clj index 97c3601..d1d68e2 100644 --- a/project.clj +++ b/project.clj @@ -11,7 +11,7 @@ :username :env/clojars_username :password :env/clojars_password :sign-releases false}]] - ;; Run coverage only on the example namespace to demonstrate the reporter. - ;; Remove or adjust :ns-regex when using this reporter in your own project. + :source-paths ["src"] + :test-paths ["dev" "test"] :cloverage {:ns-regex [#"^example\..*"] :output "target/coverage"}) From e0dd2164a030e3202c6f988c78b5e2e291041a79 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 3 Apr 2026 08:11:20 +0000 Subject: [PATCH 2/4] Fix CI: simplify test alias, use dev profile for lein source-paths - Revert cognitect test-runner (git dep may cause resolution issues in CI) back to inline clojure.test runner - Move dev/ from top-level :test-paths to :profiles {:dev {:source-paths}} in project.clj so cloverage can discover example namespaces as sources - Add comments noting dev/ layout for downstream users https://claude.ai/code/session_01WpM3eidMhXdmEvo9DRX1vH --- deps.edn | 14 ++++++-------- project.clj | 5 ++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/deps.edn b/deps.edn index 7a3978d..964cc17 100644 --- a/deps.edn +++ b/deps.edn @@ -6,20 +6,18 @@ :aliases {;; Run tests with: clj -M:test ;; - ;; Uses cognitect-labs/test-runner. Discovers tests automatically under - ;; the "test" directory — no need to hard-code namespace names. + ;; The example namespace lives under dev/ so it is NOT packaged in the + ;; published JAR. Adjust the require and run-tests call for your own project. :test {:extra-paths ["dev" "test"] - :extra-deps {io.github.cognitect-labs/test-runner - {:git/tag "v0.5.1" :git/sha "dfb30dd"}} - :main-opts ["-m" "cognitect.test-runner"] - :exec-fn cognitect.test-runner.api/test} + :main-opts ["-e" + "(require 'example.core-test 'clojure.test)(let [r (clojure.test/run-tests 'example.core-test)](System/exit (if (pos? (+ (:fail r) (:error r))) 1 0)))"]} ;; Run cloverage with the Cobertura XML reporter: ;; clj -M:coverage ;; - ;; Limit which namespaces are instrumented with --ns-regex (remove or - ;; adjust when using this reporter in your own project). + ;; The example namespace lives under dev/ and is only used for + ;; demonstration. Adjust --ns-regex for your own project. :coverage {:extra-paths ["dev" "test"] :extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}} diff --git a/project.clj b/project.clj index d1d68e2..369d703 100644 --- a/project.clj +++ b/project.clj @@ -6,12 +6,11 @@ :dependencies [[org.clojure/clojure "1.10.0"] [org.clojure/data.xml "0.2.0-alpha10"] [cloverage "1.2.4"]] - :profiles {:dev {:plugins [[lein-cloverage "1.2.4"]]}} + :profiles {:dev {:source-paths ["dev"] + :plugins [[lein-cloverage "1.2.4"]]}} :deploy-repositories [["clojars" {:url "https://clojars.org/repo" :username :env/clojars_username :password :env/clojars_password :sign-releases false}]] - :source-paths ["src"] - :test-paths ["dev" "test"] :cloverage {:ns-regex [#"^example\..*"] :output "target/coverage"}) From 09cf671e2d799e7bc47ba207fb9fd501965d6d5a Mon Sep 17 00:00:00 2001 From: tooooolong Date: Fri, 3 Apr 2026 17:25:12 +0800 Subject: [PATCH 3/4] Fix clj coverage test namespace discovery --- deps.edn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deps.edn b/deps.edn index 964cc17..56e1d5e 100644 --- a/deps.edn +++ b/deps.edn @@ -24,6 +24,7 @@ :main-opts ["-m" "cloverage.coverage" "--custom-report" "cloverage.coverage.cobertura/report" "--ns-regex" "^example\\..*" + "--test-ns-regex" "^example\\..*-test$" "--output" "target/coverage"]} ;; Same as :coverage but also generates the built-in HTML report: @@ -35,4 +36,5 @@ "--custom-report" "cloverage.coverage.cobertura/report" "--html" "--ns-regex" "^example\\..*" + "--test-ns-regex" "^example\\..*-test$" "--output" "target/coverage"]}}} From 34cb42aee2d67ddd0e6eeb06843f2979f6be7025 Mon Sep 17 00:00:00 2001 From: tooooolong Date: Fri, 3 Apr 2026 17:51:50 +0800 Subject: [PATCH 4/4] Update release workflow for Clojars deploy token --- .github/workflows/release.yml | 36 ++++++++++++++++++++++++++++++++--- README.md | 21 ++++++++++++++++---- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59f55ce..846eba2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,10 @@ jobs: runs-on: ubuntu-latest permissions: contents: read + env: + CLOJARS_USERNAME: tooooolong + CLOJARS_PASSWORD: ${{ secrets.CLOJARS_DEPLOY_TOKEN }} + CLOJARS_TOKEN_SCOPE: org.clojars.tooooolong/* steps: - uses: actions/checkout@v4 @@ -62,8 +66,34 @@ jobs: - name: Verify version in project.clj run: head -1 project.clj + - name: Verify project coordinates match token scope + run: | + python3 - <<'PYEOF' + import os + import re + import sys + + text = open("project.clj").read() + match = re.search(r'defproject\s+([^\s"]+)\s+"([^"]+)"', text) + if not match: + print("Unable to parse defproject coordinates from project.clj", file=sys.stderr) + sys.exit(1) + + coordinates = match.group(1) + scope = os.environ["CLOJARS_TOKEN_SCOPE"] + scope_prefix = scope[:-1] if scope.endswith("*") else scope + + print("Release coordinates:", coordinates) + print("Configured token scope:", scope) + + if not coordinates.startswith(scope_prefix): + print( + "CLOJARS_DEPLOY_TOKEN scope does not allow deploying these coordinates. " + "Mint a token for the current project coordinates or migrate the published coordinates first.", + file=sys.stderr, + ) + sys.exit(1) + PYEOF + - name: Deploy to Clojars - env: - CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }} - CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }} run: lein deploy clojars diff --git a/README.md b/README.md index 70957d6..5cfd53a 100644 --- a/README.md +++ b/README.md @@ -258,12 +258,24 @@ deploys to [Clojars](https://clojars.org) automatically when you push a `v*` tag ### Prerequisites -Add two repository secrets in **Settings → Secrets and variables → Actions**: +Add this repository secret in **Settings → Secrets and variables → Actions**: | Secret | Value | |--------|-------| -| `CLOJARS_USERNAME` | Your Clojars username | -| `CLOJARS_PASSWORD` | A Clojars [deploy token](https://clojars.org/tokens) (not your password) | +| `CLOJARS_DEPLOY_TOKEN` | A Clojars [deploy token](https://clojars.org/tokens) for the publishing account | + +The workflow uses the fixed Clojars username `tooooolong`; the token replaces the +password when deploying. + +The release workflow also checks that the token scope matches the project +coordinates in `project.clj` before running `lein deploy`. + +This repository still publishes the coordinates `tooooolong/clojure-cobertura-coverage`. +If your token is scoped only to `org.clojars.tooooolong/*`, Clojars will reject the +deploy until you either: + +1. mint a token whose scope includes `tooooolong/clojure-cobertura-coverage`, or +2. deliberately migrate the published coordinates to `org.clojars.tooooolong/...` ### Steps to release @@ -280,7 +292,8 @@ git push origin v0.2.0 The workflow will: 1. Extract the version from the tag (`v0.2.0` → `0.2.0`) 2. Patch `project.clj` with that version in the ephemeral CI workspace -3. Run `lein deploy clojars` +3. Verify the configured token scope can publish the current coordinates +4. Run `lein deploy clojars` The `project.clj` in the repository always stays at the **development version** (`0.1.0`). Bump it manually before tagging if you want the version shown in editor tooling to match.