GithubHelp home page GithubHelp logo

otto-de / leinsync Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 2.0 309 KB

Plugin to synchronize the shared codebase between clojure projects

License: Apache License 2.0

Clojure 99.85% Shell 0.15%
synchronizing-contents dependency-manager test-automation git microservice repo-sync reposync namespace

leinsync's Introduction

Introduction

Build Status Coverage Status Dependencies Status Downloads

Clojars Project

Our system consists of a set of micro services written in clojure. Although we have codes shared between these clojure projects, we have consciously decided against shared libraries. By doing in this way, we gained a greater flexibility to adjust/change them. At the beginning, we synchronized those shared code by hand, which was of course not very comfortable. This is the reason why we wrote this plugin syncto make this task automatically.

sync plugin has been successfully tested with the Leiningen version 2.8.1. If you have any issue dealing with Leiningen, please upgrade your project with the Leiningen version greater or equal to 2.8.1.

Sync Plugin

sync is a Leiningen plugin to synchronize shared codebase between clojure projects.

sync makes a strong assumption about the file structure of the shared projects which are created by Leiningen, like this:

container-folder/
+-- project-1
    +-- src
    ¦   +-- package.1
    ¦   +---- name.space.1
    ¦   +---- name.space.2
    +-- test
    ¦   +-- name.space-test.1
    ¦   +-- name.space-test.2
    +-- project.clj
+-- project-2
    +-- src
    ¦   +-- package.1
    ¦   +---- name.space.1
    ¦   +---- name.space.2
    +-- test
    ¦   +-- name.space-test.1
    ¦   +-- name.space-test.2
    +-- project.clj
+-- project-3
    +-- src
    ¦   +-- package.1
    ¦   +---- name.space.1
    ¦   +---- name.space.2
    +-- test
    ¦   +-- name.space-test.1
    ¦   +-- name.space-test.2
    +-- project.clj

For example, if some code change is made on the name.space.1 of the project-1, we want to apply this change later on all others projects containing name.space.1.

container-folder/
+-- project-1
    +-- src
    ¦   +-- name.space.1 ---------+
    ¦   +-- name.space.2          |
    +-- project.clj               |
+-- project-2                     |
    +-- src                       |
    ¦   +-- name.space.1 <--sync--+        
    +-- project.clj               |
+-- project-3                     |
    +-- src                       |
    ¦   +-- name.space.1 <--sync--+
    ¦   +-- name.space.3       
    +-- project.clj

Usage

To specify which projects should be synchronized, a search string must be passed as argument to sync. A search string can be a string concatnation of projects or a java's regex. For example:

  • lein sync [options] "project-1,project-2,project-3"
  • lein sync [options] "project-.*"
  • lein sync "(.*)[^(shouldNotMatch)]$"

Options:

  • --interactive : Activate the interactive mode to choose projects
  • --deps : List all profile/global deps on projects.
  • --list : List resources to be synchronized.
  • --include-namespace : Synchronize only the passed namespaces.
  • --include-resource : Synchronize only the passed resources.
  • --include-package : Synchronize only the passed packages.
  • --notest : Synchronize shared code base without executing tests on target projects.
  • --test : Executing tests on target projects.
  • --reset : Reset all uncommitted changes in all target projects.
  • --status : Check status on target projects.
  • --commit : Commit change on target projects.
  • --pull : Pull rebase on target projects.
  • --push : Push on target projects.

Define :sync configuration in the project.clj of each target project. It has the following options:

  • :test-cmd specifies which leiningen tasks will be executed to test target projects after synchronizing.
  • :namespaces specifies the namespaces to be synchronized between shared projects.
  • :packages specifies the packages to be synchronized between shared projects.
  • :resources specifies the resources to be synchronized between shared projects.

A namespace/resource/package will be synchronized between 2 projects if and only if they are defined in the both project.clj.

Example

Breaking change: since the version 0.9.47the selector names :sync instead of :ns-sync. The :sync configuration can be specified like that:

:sync { :test-cmd    [["./lein.sh" "profile-1" "test"] 
                      ["./lein.sh" "profile-2" "test"]]
        :namespaces  ["name.space.1" "name.space.2"]
        :packages    ["package.path.1" "package.path.2"]
        :resources   ["resource.1"   "resource.2"]}

In order to synchronize namespaces and resources between projects, run in the current source project:

$ cd container-folder/project-1
$ lein sync "project-2,project-3"
*********************** UPDATE NAMESPACES ***********************
*
* Update name.space.1 to the project project-2
* Update name.space.1 to the project project-3

*********************** UPDATE RESOURCES ***********************
*
* Update "resources.1 to the project project-2
* Update "resources.1 to the project project-3

 ****** Executing tests of project-2        ******

... Executing  ./lein.sh profile-1 test
... Executing  ./lein.sh profile-2 test


 ****** Executing tests of project-3        ******

... Executing  ./lein.sh profile-1 test
... Executing  ./lein.sh profile-2 test

| :project | :result | :./lein.sh clean | :./lein.sh test | 
|----------+---------+------------------+-----------------|
|project-2 | :passed |          :passed |         :passed |
|----------------------------------------------------------
|project-3 | :passed |          :passed |         :passed |
|---------------------------------------------------------|


* Tests are passed on project(s): project-2,project-3


To see changes : lein sync project-2,project-3 --status
To commit      : lein sync project-2,project-3 --commit
To push        : lein sync project-2,project-3 --push

sync will update the predefined namespaces/resources from project-1 to project-2 and project-3. It updates only the namespace, which has been defined in both source project and target project. If a namespace is only defined in the source or target project, it will be ignored. Afterwards sync will execute tests, which are defined in :test-cmd on project-2 project-3 and project-4, to make sure that the update did not break anything.

leinsync's People

Contributors

gitter-badger avatar minhtuannguyen avatar robertron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

leinsync's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.