Skip to content

Commit

Permalink
ci: update build files (#34)
Browse files Browse the repository at this point in the history
* ci: update build files

* Fix format
  • Loading branch information
jsmassa authored Mar 8, 2023
1 parent c5a871d commit 8d6cbf0
Show file tree
Hide file tree
Showing 16 changed files with 296 additions and 274 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ workflows:
only: main
requires:
- tools/unittest
- tools/cljstest
- tools/format
- tools/build
- tools/release:
Expand Down
3 changes: 2 additions & 1 deletion .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{:lint-as {datalog.parser.type/deftrecord clojure.core/defrecord
datalog.parser.impl.util/forv clojure.core/for}}
datalog.parser.impl.util/forv clojure.core/for}
:linters {:clojure-lsp/unused-public-var {:exclude [build]}}}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/classes
/checkouts
profiles.clj
pom.xml
pom.xml.asc
*.jar
*.class
Expand Down
84 changes: 45 additions & 39 deletions build.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
(ns build
(:refer-clojure :exclude [test compile])
(:refer-clojure :exclude [test])
(:require [clojure.tools.build.api :as b]
[borkdude.gh-release-artifact :as gh]
[org.corfield.build :as bb])
(:import (clojure.lang ExceptionInfo)))
[deps-deploy.deps-deploy :as dd])
(:import [clojure.lang ExceptionInfo]))

(def org "replikativ")
(def lib 'io.replikativ/datalog-parser)
(def current-commit (b/git-process {:git-args "rev-parse HEAD"}))
(def version (format "0.2.%s" (b/git-count-revs nil)))
(def current-commit (gh/current-commit))
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (format "target/%s-%s.jar" (name lib) version))
Expand All @@ -17,32 +18,23 @@
(b/delete {:path "target"}))

(defn jar
[opts]
(-> opts
(assoc :class-dir class-dir
:src-pom "./template/pom.xml"
:lib lib
:version version
:basis basis
:jar-file jar-file
:src-dirs ["src"])
bb/jar))

(defn ci "Run the CI pipeline of tests (and build the JAR)." [opts]
(-> opts
(assoc :lib lib :version version)
(bb/clean)
(bb/jar)))

(defn install "Install the JAR locally." [opts]
(-> opts
jar
bb/install))
[_]
(b/write-pom {:class-dir class-dir
:src-pom "./template/pom.xml"
:lib lib
:version version
:basis basis
:src-dirs ["src"]})
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(b/jar {:class-dir class-dir
:jar-file jar-file}))

(defn deploy "Deploy the JAR to Clojars." [opts]
(-> opts
(assoc :lib lib :version version)
(bb/deploy)))
(defn deploy
"Don't forget to set CLOJARS_USERNAME and CLOJARS_PASSWORD env vars."
[_]
(dd/deploy {:installer :remote :artifact jar-file
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}))

(defn fib [a b]
(lazy-seq (cons a (fib b (+ a b)))))
Expand All @@ -51,26 +43,40 @@
(loop [idle-times (take retries (fib 1 2))]
(let [result (exec-fn)]
(if (test-fn result)
(when-let [sleep-ms (first idle-times)]
(println "Returned: " result)
(println "Retrying with remaining back-off times (in s): " idle-times)
(Thread/sleep (* 1000 sleep-ms))
(recur (rest idle-times)))
(do (println "Returned: " result)
(if-let [sleep-ms (first idle-times)]
(do (println "Retrying with remaining back-off times (in s): " idle-times)
(Thread/sleep (* 1000 sleep-ms))
(recur (rest idle-times)))
result))
result))))

(defn try-release []
(try (gh/overwrite-asset {:org "replikativ"
(try (gh/overwrite-asset {:org org
:repo (name lib)
:tag version
:commit current-commit
:file jar-file
:content-type "application/java-archive"})
:content-type "application/java-archive"
:draft false})
(catch ExceptionInfo e
(assoc (ex-data e) :failure? true))))

(defn release
[_]
(-> (retry-with-fib-backoff 10 try-release :failure?)
:url
println))
(println "Trying to release artifact...")
(let [ret (retry-with-fib-backoff 10 try-release :failure?)]
(if (:failure? ret)
(do (println "GitHub release failed!")
(System/exit 1))
(println (:url ret)))))

(defn install
[_]
(clean nil)
(jar nil)
(b/install {:basis (b/create-basis {})
:lib lib
:version version
:jar-file jar-file
:class-dir class-dir}))
20 changes: 11 additions & 9 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
lambdaisland/kaocha {:mvn/version "1.71.1119"}
lambdaisland/kaocha-cljs {:mvn/version "1.4.130"}}
:extra-paths ["perf" "test"]}
:build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.8.2"
:git/sha "0ffdb4c"}
borkdude/gh-release-artifact {:git/url "https://github.com/borkdude/gh-release-artifact"
:sha "a83ee8da47d56a80b6380cbb6b4b9274048067bd"}
babashka/babashka.curl {:mvn/version "0.1.1"}
babashka/fs {:mvn/version "0.1.2"}
cheshire/cheshire {:mvn/version "5.10.2"}}
:ns-default build}}
:paths ["src"]}
:format {:extra-deps {cljfmt/cljfmt {:mvn/version "0.7.0"}}
:main-opts ["-m" "cljfmt.main" "check"]}
:ffix {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
:main-opts ["-m" "cljfmt.main" "fix"]}
:build {:deps {io.github.clojure/tools.build {:mvn/version "0.9.3"}
slipset/deps-deploy {:mvn/version "0.2.0"}
io.github.borkdude/gh-release-artifact {:git/sha "05f8d8659e6805d513c59447ff41dc8497878462"}
babashka/babashka.curl {:mvn/version "0.1.2"}
babashka/fs {:mvn/version "0.1.6"}
cheshire/cheshire {:mvn/version "5.10.2"}}
:ns-default build}}}
2 changes: 1 addition & 1 deletion src/datalog/parser.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
:qlimit (-> qm :limit impl/parse-limit)
:qoffset (-> qm :offset impl/parse-offset)
:qreturnmaps (-> qm (select-keys [:keys :syms :strs])
(impl/parse-return-maps))})]
(impl/parse-return-maps))})]
(impl/assert-valid res q qm)
res))
14 changes: 7 additions & 7 deletions src/datalog/parser/impl.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns datalog.parser.impl
(ns datalog.parser.impl
(:require [clojure.set :as set]
[datalog.parser.type :as t #?@(:cljs [:refer [Not And Or Aggregate SrcVar RulesVar RuleExpr
RuleVars Variable ReturnMaps MappingKey]])]
Expand All @@ -8,7 +8,7 @@
(:refer-clojure :rename {distinct? core-distinct?})
#?(:clj
(:import [datalog.parser.type
Not And Or Aggregate SrcVar RulesVar RuleExpr
Not And Or Aggregate SrcVar RulesVar RuleExpr
RuleVars Variable ReturnMaps MappingKey])))

#?(:clj (set! *warn-on-reflection* true))
Expand Down Expand Up @@ -496,11 +496,11 @@
(let [name->branch (group-by :name (parse-seq parse-rule form))]
(forv [[name branches] name->branch
:let [branches (forv [b branches]
(datalog.parser.type.RuleBranch.
(:vars b) (:clauses b)))]]
(do
(validate-arity name branches)
(datalog.parser.type.Rule. name branches)))))
(datalog.parser.type.RuleBranch.
(:vars b) (:clauses b)))]]
(do
(validate-arity name branches)
(datalog.parser.type.Rule. name branches)))))

(defn query->map [query]
(let [allowed-keys #{:find :with :in :where :limit :offset :keys :syms :strs}]
Expand Down
4 changes: 2 additions & 2 deletions src/datalog/parser/impl/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
(str/starts-with? v "_"))

(defn reverse-ref?
#?@(:clj [^Boolean [attr]]
:cljs [^boolean [attr]])
#?@(:clj [^Boolean [attr]]
:cljs [^boolean [attr]])
(-> attr decompose-ref second reverse-attr?))

(defn- invert-name [s]
Expand Down
8 changes: 4 additions & 4 deletions src/datalog/parser/pull.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@

(defn- expand-map-clause [clause]
(forv [[k v] clause]
{k v}))
{k v}))

(let [wildcarded? (comp not-empty :wildcard)]
(defn- simplify-pattern-clauses [pattern]
(let [groups (group-by pattern-clause-type pattern)
base (cond-> [] (wildcarded? groups) (conj '*))]
(into base
(concat
(:other groups)
(mapcat expand-map-clause (:map groups)))))))
(concat
(:other groups)
(mapcat expand-map-clause (:map groups)))))))

(defn parse-pattern
"Parse an EDN pull pattern into a tree of records using the following
Expand Down
8 changes: 4 additions & 4 deletions src/datalog/parser/type.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
(~'-traversable? [_#] true)
p/ITraversable
(~'-postwalk [this# ~f]
(-> (new ~tagname ~@walked-fields)
(vary-meta merge (meta this#))))
(-> (new ~tagname ~@walked-fields)
(vary-meta merge (meta this#))))
(~'-collect [_# ~pred ~acc]
~(reduce #(list `collect pred %2 %1) acc fields))
~(reduce #(list `collect pred %2 %1) acc fields))
(~'-collect-vars [_# ~acc]
~(reduce #(list `collect-vars %1 %2) acc fields))
~(reduce #(list `collect-vars %1 %2) acc fields))
~@rest))))

;; placeholder = the symbol '_'
Expand Down
20 changes: 9 additions & 11 deletions src/datalog/unparser.cljc
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
(ns datalog.unparser
(:require [datalog.parser :as parser]
#?(:cljs
[datalog.parser.type :refer
[Aggregate And BindColl BindIgnore BindScalar BindTuple Constant
[datalog.parser.type :refer
[Aggregate And BindColl BindIgnore BindScalar BindTuple Constant
DefaultSrc FindColl FindRel FindScalar FindTuple Function Not Or
Pattern Placeholder PlainSymbol Predicate Pull Query Rule
RuleBranch RuleExpr RulesVar RuleVars SrcVar Variable]]))
#?(:clj
(:import [datalog.parser.type
Aggregate And BindColl BindIgnore BindScalar BindTuple Constant
DefaultSrc FindColl FindRel FindScalar FindTuple Function Not Or
Pattern Placeholder PlainSymbol Predicate Pull Query Rule
RuleBranch RuleExpr RulesVar RuleVars SrcVar Variable]]))
#?(:clj
(:import [datalog.parser.type
Aggregate And BindColl BindIgnore BindScalar BindTuple Constant
DefaultSrc FindColl FindRel FindScalar FindTuple Function Not Or
Pattern Placeholder PlainSymbol Predicate Pull Query Rule
RuleBranch RuleExpr RulesVar RuleVars SrcVar Variable])))
RuleBranch RuleExpr RulesVar RuleVars SrcVar Variable])))

#?(:clj (set! *warn-on-reflection* true))

Expand All @@ -24,7 +24,6 @@
[v]
(-unparse v))


;; ===== Missing Pull records

;; PullSpec
Expand All @@ -37,7 +36,6 @@
;; PullMapSpecEntry
;; PullAttrWithOpts


(extend-protocol PUnparse
Aggregate
(-unparse [{:keys [fn args]}]
Expand Down
21 changes: 21 additions & 0 deletions template/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>io.replikativ</groupId>
<artifactId>datalog-parser</artifactId>
<packaging>jar</packaging>
<name>datalog-parser</name>
<version>0.0.0</version>
<description>Generic datalog parser compliant to datomic, datascript and datahike queries.</description>
<licenses>
<license>
<name>Eclipse</name>
<url>http://www.eclipse.org/legal/epl-v10.html</url>
</license>
</licenses>
<scm>
<connection>scm:git:[email protected]:replikativ/datalog-parser.git</connection>
<developerConnection>scm:git:[email protected]/replikativ/datalog-parser.git</developerConnection>
<url>https://github.com/replikativ/datalog-parser</url>
</scm>
</project>
Loading

0 comments on commit 8d6cbf0

Please sign in to comment.