Skip to content

Commit

Permalink
Move to main branch (replikativ#454)
Browse files Browse the repository at this point in the history
* Switch to GitHub Flow and tools.build

This commit changes the CI to create a release on every
merge to the `main`-branch. The patch-release will always
incremented when released. CircleCI-pipeline creates
a release automatically on GitHub and tags the commit.

This commit also switches to use tools.build and with
that it is possible to run the compilation and jar-builds
from the REPL. There is no need to run maven anymore.

* Documentation and ADR

Co-authored-by: Timo Kramer <fw-git@timokramer.de>
Co-authored-by: Timo Kramer <info@lambdaforge.io>
  • Loading branch information
3 people committed Dec 21, 2021
1 parent 0b48cf7 commit dac52a9
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 1,105 deletions.
107 changes: 73 additions & 34 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
version: 2.1

orbs:
github-cli: circleci/github-cli@1.0
tools: replikativ/clj-tools@0

jobs:
setup:
executor: tools/clojurecli
parameters:
setup_cljs:
type: boolean
default: true
steps:
- restore_cache:
keys:
Expand All @@ -20,80 +26,113 @@ jobs:
keys:
- deps-{{ checksum "deps.edn" }}
- deps-
- run: clojure -e nil
- run:
name: resolve deps
command: clojure -P
- save_cache:
key: deps-{{ checksum "deps.edn" }}
paths:
- /home/circleci/.m2
- restore_cache:
keys:
- pom-{{ checksum "pom.xml" }}
- pom-
- run: sudo apt-get install maven --yes
- run: mvn compile
- save_cache:
key: pom-{{ checksum "pom.xml" }}
- when:
condition: <<parameters.setup_cljs>>
steps:
- restore_cache:
keys:
- npm-{{ checksum "package-lock.json" }}
- npm-
- run: npm ci
- save_cache:
key: npm-{{ checksum "package-lock.json" }}
paths:
- /home/circleci/.npm
- persist_to_workspace:
root: /home/circleci/
paths:
- /home/circleci/.m2
- .m2
- .npm
- replikativ
build:
executor: tools/clojurecli
steps:
- attach_workspace:
at: /home/circleci
- run:
name: clean
command: clojure -Sthreads 1 -T:build clean
- run:
name: compile
command: clojure -Sthreads 1 -T:build compile
- run:
name: jar
command: clojure -Sthreads 1 -T:build jar
- persist_to_workspace:
root: /home/circleci/
paths:
- .m2
- .npm
- replikativ
deploy:
executor: tools/clojurecli
steps:
- attach_workspace:
at: /home/circleci
- run:
name: deploy
command: clojure -Sthreads 1 -T:build deploy
release:
executor: tools/clojurecli
steps:
- attach_workspace:
at: /home/circleci
- run:
name: deploy
command: clojure -Sthreads 1 -T:build release

workflows:
build-test-and-deploy:
jobs:
- setup:
context: dockerhub-deploy
setup_cljs: false
- build:
context: dockerhub-deploy
requires:
- setup
- tools/format:
context: dockerhub-deploy
requires:
- setup
- tools/unittest:
context: dockerhub-deploy
requires:
- setup
- build
- tools/backward-compatibility-test:
context: dockerhub-deploy
requires:
- setup
- build
- tools/integrationtest-postgresql:
context: dockerhub-deploy
requires:
- setup
- tools/build:
jarname: "datahike"
context: dockerhub-deploy
requires:
- setup
- tools/deploy-snapshot:
jarname: "datahike"
- build
- deploy:
context:
- clojars-deploy
- dockerhub-deploy
- clojars-deploy
- github-token
filters:
branches:
only: development
only: main
requires:
- setup
- tools/format
- tools/unittest
- tools/backward-compatibility-test
- tools/integrationtest-postgresql
- tools/build
- tools/deploy-release:
jarname: "datahike"
- release:
context:
- clojars-deploy
- dockerhub-deploy
- github-token
filters:
branches:
only: master
only: main
requires:
- setup
- tools/format
- tools/unittest
- tools/backward-compatibility-test
- tools/integrationtest-postgresql
- tools/build
- deploy
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [ ] Integration tests added
- [ ] Architecture Decision Record added if design changes necessary
- [ ] Formatting checked
- [ ] `CHANGELOG.md` updated

##### Feature
- [ ] Implements an existing feature request. Make sure the feature request has been accepted for implementation before opening a PR.
Expand All @@ -16,6 +17,7 @@
- [ ] Documentation added
- [ ] Architecture Decision Record added
- [ ] Formatting checked
- [ ] `CHANGELOG.md` updated


#### ADDITIONAL INFORMATION
Expand Down
78 changes: 78 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
(ns build
(:require
[borkdude.gh-release-artifact :as gh]
[clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as dd]))

(def lib 'io.replikativ/datahike)
(def version (format "0.4.%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))

(defn clean
[_]
(b/delete {:path "target"}))

(defn compile
[_]
(b/javac {:src-dirs ["java"]
:class-dir class-dir
:basis basis
:javac-opts ["-source" "8" "-target" "8"]}))

(defn jar
[_]
(compile nil)
(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
"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 release
[_]
(-> (gh/overwrite-asset {:org (namespace lib)
:repo (name lib)
:tag version
:commit current-commit
:file jar-file
:content-type "application/java-archive"})
:url
println))

(defn install
[_]
(clean nil)
(jar nil)
(b/install {:basis (b/create-basis {})
:lib lib
:version version
:jar-file jar-file
:class-dir class-dir}))

(comment
(b/pom-path {:lib lib :class-dir class-dir})
(clean nil)
(compile nil)
(jar nil)
(deploy nil)
(release nil)
(install nil)

(name lib)
(namespace lib)
(require '[babashka.fs :as fs])
(fs/file-name (format "target/datahike-%s.jar" version)))
70 changes: 35 additions & 35 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,47 @@
incanter/incanter-charts {:mvn/version "1.9.3"}}}

:test {:extra-paths ["test"]
<<<<<<< HEAD
:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.516"}
lambdaisland/kaocha {:mvn/version "1.0.829"}
lambdaisland/kaocha-cljs {:mvn/version "0.0-71"}
=======
:extra-deps {lambdaisland/kaocha {:mvn/version "1.60.945"}
lambdaisland/kaocha-cljs {:mvn/version "1.0.107"}
>>>>>>> b9d108e9 (update dependency to latest release versions)
io.replikativ/datahike-jdbc {:mvn/version "0.1.2-SNAPSHOT"}}}
:extra-deps {lambdaisland/kaocha {:mvn/version "1.60.945"}
lambdaisland/kaocha-cljs {:mvn/version "1.0.107"}
io.replikativ/datahike-jdbc {:mvn/version "0.1.2-SNAPSHOT"}}}

:repl {:extra-deps {cider/cider-nrepl {:mvn/version "0.27.2"}
nrepl/nrepl {:mvn/version "0.8.3"}
org.clojure/tools.namespace {:mvn/version "1.1.0"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}
:repl {:extra-deps {cider/cider-nrepl {:mvn/version "0.27.2"}
nrepl/nrepl {:mvn/version "0.8.3"}
org.clojure/tools.namespace {:mvn/version "1.1.0"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

:bench-dev {:extra-paths ["benchmark/src"]
:extra-deps {clj-http/clj-http {:mvn/version "3.12.3"}
org.clojure/tools.cli {:mvn/version "1.0.206"}}}
:bench-dev {:extra-paths ["benchmark/src"]
:extra-deps {clj-http/clj-http {:mvn/version "3.12.3"}
org.clojure/tools.cli {:mvn/version "1.0.206"}}}

:benchmark {:main-opts ["-m" "benchmark.core"]
:extra-paths ["benchmark/src"]
:extra-deps {clj-http/clj-http {:mvn/version "3.12.3"}
org.clojure/tools.cli {:mvn/version "1.0.206"}
incanter/incanter-core {:mvn/version "1.9.3"}
incanter/incanter-charts {:mvn/version "1.9.3"}}}
:benchmark {:main-opts ["-m" "benchmark.core"]
:extra-paths ["benchmark/src"]
:extra-deps {clj-http/clj-http {:mvn/version "3.12.3"}
org.clojure/tools.cli {:mvn/version "1.0.206"}
incanter/incanter-core {:mvn/version "1.9.3"}
incanter/incanter-charts {:mvn/version "1.9.3"}}}

:datomic {:extra-deps {com.datomic/datomic-free {:mvn/version "0.9.5703"}}}
:datomic {:extra-deps {com.datomic/datomic-free {:mvn/version "0.9.5703"}}}

:deploy {:extra-deps {slipset/deps-deploy {:mvn/version "0.2.0"}}
:main-opts ["-m" "deps-deploy.deps-deploy" "deploy" "replikativ-datahike.jar"]}
:deploy {:extra-deps {slipset/deps-deploy {:mvn/version "0.2.0"}}
:main-opts ["-m" "deps-deploy.deps-deploy" "deploy" "replikativ-datahike.jar"]}

:build {:extra-deps {seancorfield/depstar {:mvn/version "2.0.216"}}
:main-opts ["-m" "hf.depstar.jar" "replikativ-datahike.jar"]}
:install {:extra-deps {slipset/deps-deploy {:mvn/version "0.2.0"}}
:exec-fn deps-deploy.deps-deploy/deploy
:exec-args {:installer :local
:artifact "replikativ-datahike.jar"}}

:install {:extra-deps {slipset/deps-deploy {:mvn/version "0.2.0"}}
:exec-fn deps-deploy.deps-deploy/deploy
:exec-args {:installer :local
:artifact "replikativ-datahike.jar"}}
:format {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
:main-opts ["-m" "cljfmt.main" "check"]}

:format {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
:main-opts ["-m" "cljfmt.main" "check"]}
:ffix {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
:main-opts ["-m" "cljfmt.main" "fix"]}

:ffix {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
:main-opts ["-m" "cljfmt.main" "fix"]}}}}
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.6.6" :git/sha "4d41c26"}
slipset/deps-deploy {:mvn/version "0.2.0"}
borkdude/gh-release-artifact {:git/url "https://github.com/borkdude/gh-release-artifact"
:sha "2f8898d84126a4e922c490f8614211a8b0cf67cd"}
babashka/babashka.curl {:mvn/version "0.1.1"}
babashka/fs {:mvn/version "0.1.2"}
cheshire/cheshire {:mvn/version "5.10.1"}}
:ns-default build}}}
40 changes: 40 additions & 0 deletions doc/adl/adr-004-github-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Github Flow

## Context

[GitHub Flow](https://githubflow.github.io/)

We want to release more often. Therefore we are considering the GitHub Flow as an alternative to
our current Gitflow. Everytime a merge-request gets merged a new release should be created after
running the pipeline. That means features and bugfixes are propagated faster. Apart from that
the flow is just simpler and sufficient for our and our users' needs.

[Discussion](https://github.com/replikativ/datahike/discussions/447)

## Options

[4 branching workflows for Git](https://medium.com/@patrickporto/4-branching-workflows-for-git-30d0aaee7bf)

## Status

**Proposed**

## Decision

We are switching to the GitHub Flow with [PR #445](https://github.com/replikativ/datahike/pull/445).

## Consequences

When the PR is merged into the newly created `main`-branch we are from then on only branching off
of main for feature- and bugfix-branches. `main` needs to be the new default branch where everyone
is landing on by default. Everytime a PR is merged there will be a new release on GitHub with the
patch-level set to the overall commit-count. To make a new minor or major release the number
needs to be adjusted manually in the build.clj-file.

This change needs to be announced properly so that everyone working on Datahike knows about this
new way of working. In the future all replikativ-libraries will be switched so everyone needs to
know that there will not be any long-living-branches any more.

Another consequence to consider is that CircleCI then has permission to write to our GitHub-repo.
Since it is necessary to write to the git-repo when tagging a commit CircleCI needs the full
write access. It already has the ability to release a jar to Clojars.
Loading

0 comments on commit dac52a9

Please sign in to comment.