Skip to content

Commit

Permalink
Add publishing to the clojars
Browse files Browse the repository at this point in the history
  • Loading branch information
just-sultanov committed Nov 1, 2024
1 parent a811cd2 commit b2203a7
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 46 deletions.
37 changes: 18 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: build

on:
push:
branches:
- main
- develop
paths:
- ".github/workflows/**"
- "src/**"
Expand All @@ -15,9 +12,6 @@ on:
- "tests.edn"
- "version"
pull_request:
branches:
- main
- develop
paths:
- ".github/workflows/**"
- "src/**"
Expand All @@ -38,12 +32,6 @@ jobs:
with:
fetch-depth: 0

- name: Setup variables
id: tenet
run: |
TENET_VERSION=$(cat version)
echo "version=${TENET_VERSION}" >> $GITHUB_OUTPUT
- name: Setup clojure tools
uses: DeLaGuardo/setup-clojure@12.5
with:
Expand All @@ -63,6 +51,12 @@ jobs:
with:
node-version: "22.11.0"

- name: Setup variables
id: tenet
run: |
TENET_VERSION=$(bb version)
echo "version=${TENET_VERSION}" >> $GITHUB_OUTPUT
- name: Install deps
run: bb setup

Expand Down Expand Up @@ -99,7 +93,7 @@ jobs:
fail_ci_if_error: false
verbose: true

uberjar:
publish:
if: "!contains(github.event.head_commit.message, 'skip ci')"
needs: test
runs-on: ubuntu-latest
Expand All @@ -109,12 +103,6 @@ jobs:
with:
fetch-depth: 0

- name: Setup variables
id: tenet
run: |
TENET_VERSION=$(cat version)
echo "version=${TENET_VERSION}" >> $GITHUB_OUTPUT
- name: Setup openjdk
uses: actions/setup-java@v4
with:
Expand All @@ -138,6 +126,14 @@ jobs:
key: ubuntu-deps-${{ hashFiles('deps.edn') }}
restore-keys: ubuntu-deps-

- name: Setup variables
id: tenet
run: |
TENET_VERSION=$(bb version)
echo "version=${TENET_VERSION}" >> $GITHUB_OUTPUT
echo 'CLOJARS_USERNAME=${{ secrets.CLOJARS_USERNAME }}' >> $GITHUB_ENV;
echo 'CLOJARS_PASSWORD=${{ secrets.CLOJARS_PASSWORD }}' >> $GITHUB_ENV;
- name: Build jar
run: bb build jar

Expand All @@ -146,3 +142,6 @@ jobs:
with:
path: target/tenet.jar
name: tenet-${{ steps.tenet.outputs.version }}.jar

- name: Publish jar
run: bb deploy
70 changes: 49 additions & 21 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
[clojure.string :as str])

:init (do
(def zone-id (java.time.ZoneId/of "UTC"))
(def formatter java.time.format.DateTimeFormatter/ISO_OFFSET_DATE_TIME)
(def timestamp (.format (java.time.ZonedDateTime/now zone-id) formatter))
(def -zone-id (java.time.ZoneId/of "UTC"))
(def -formatter java.time.format.DateTimeFormatter/ISO_OFFSET_DATE_TIME)
(def -timestamp (.format (java.time.ZonedDateTime/now -zone-id) -formatter))

(defn execute
[cmd]
Expand All @@ -31,30 +31,47 @@
pprint/*print-right-margin* right-margin]
(pprint/pprint x))))

(def organization "lazy-cat-io")
(def repository "tenet")
(def lib "io.lazy-cat/tenet")
(def version (-> "version" (slurp) (str/trim-newline)))
(def branch (execute "git rev-parse --abbrev-ref HEAD"))
(def commit (execute "git rev-parse --short HEAD"))

(def meta
{:organization organization
:repository repository
:branch branch
:commit commit
:version version
:timestamp timestamp}))
(def -organization "lazy-cat-io")
(def -repository "tenet")
(def -lib "io.lazy-cat/tenet")
(def -branch (-> (execute "git rev-parse --abbrev-ref HEAD") (str/lower-case)))
(def -commit (-> (execute "git rev-parse --short HEAD") (str/lower-case)))
(def -git-count-revs (-> (execute "git rev-list HEAD --count")))

(def -deployable?
(contains? #{"main" "develop"} -branch))

(def -version
(let [v (-> "version.tmpl"
(slurp)
(str/trim-newline)
(str/replace "{{ git-count-revs }}" -git-count-revs))]
(case -branch
"main" v
(format "%s-SNAPSHOT" v))))

(def -meta
{:organization -organization
:repository -repository
:branch -branch
:commit -commit
:version -version
:timestamp -timestamp}))

:enter (let [{:keys [doc print-doc?]
:or {print-doc? true}} (current-task)]
(when (and print-doc? doc)
(println (format "▸ [%s v%s] %s" lib version doc))))
(println (format "▸ [%s v%s] %s" -lib -version doc))))

;;
;; Tasks
;;

version {:doc "Show version"
:print-doc? false
:override-builtin true
:task (println -version)}

setup {:doc "Setup dependencies"
:task (shell "npm ci")}

Expand Down Expand Up @@ -90,18 +107,29 @@
-build:meta {:doc "Build metadata"
:task (do
(fs/create-dirs "src/main/resources/io/lazy-cat/tenet")
(->> meta
(->> -meta
(pretty-print)
(with-out-str)
(spit "src/main/resources/io/lazy-cat/tenet/meta.edn")))}

-build:jar {:doc "Build jar"
:depends [clean -build:meta]
:task (shell "clojure -T:build jar")}
:task (shell (format "clojure -T:build jar :version '\"%s\"'" -version))}

build {:doc "Run build"
:print-doc? false
:task (case (some-> *command-line-args* first str/lower-case)
"meta" (run '-build:meta)
"jar" (run '-build:jar)
(run '-build:jar))}}}
(run '-build:jar))}

install {:doc "Install jar"
:depends [-build:jar]
:task (shell "clojure -T:build install")}

deploy {:doc "Deploy jar"
:task (if-not -deployable?
(println "Allowed branches: main, develop")
(do
(run '-build:jar)
(shell "clojure -T:build deploy")))}}}
19 changes: 15 additions & 4 deletions build.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
(ns build
(:require
[clojure.string :as str]
[clojure.tools.build.api :as b]))
[clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as d]))

(def lib 'io.lazy-cat/tenet)
(def version (-> "version" (slurp) (str/trim-newline)))
(def class-dir "target/classes")
(def basis (delay (b/create-basis {:project "deps.edn"})))
(def jar-file "target/tenet.jar")
(def src-dirs ["src/main/clojure" "src/main/resources"])

(defn jar [_]
(defn jar
[{:keys [version]}]
(println "Writing pom.xml...")
(b/write-pom {:class-dir class-dir
:lib lib
Expand All @@ -25,3 +25,14 @@
:jar-file jar-file})
(println "Done..."))

(defn install
[_]
(d/deploy {:installer :local
:artifact jar-file
:pom-file (b/pom-path {:lib lib, :class-dir class-dir})}))

(defn deploy
[_]
(d/deploy {:installer :remote
:artifact jar-file
:pom-file (b/pom-path {:lib lib, :class-dir class-dir})}))
3 changes: 2 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
lambdaisland/kaocha-cloverage {:mvn/version "1.1.89"}
com.lambdaisland/kaocha-cljs {:mvn/version "1.5.154"}}}

:build {:extra-deps {io.github.clojure/tools.build {:git/tag "v0.10.5", :git/sha "2a21b7a"}}
:build {:extra-deps {io.github.clojure/tools.build {:git/tag "v0.10.5", :git/sha "2a21b7a"}
slipset/deps-deploy {:mvn/version "0.2.2"}}
:jvm-opts ["-Dclojure.compiler.direct-linking=true"
"-Dclojure.spec.skip-macros=true"]
:ns-default build}
Expand Down
1 change: 0 additions & 1 deletion version

This file was deleted.

1 change: 1 addition & 0 deletions version.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.{{ git-count-revs }}

0 comments on commit b2203a7

Please sign in to comment.