Giter Club home page Giter Club logo

git-sync-tools's Introduction

git-sync-tools

Scripts used to help to synchronize git repositories when following some naming convention on branches

The main tools sync-git-submodules-branches allows to automate the managment of branches of a git repository thats integrates the content of several other repositories via submodules.

Rationnale

In some large projects, the code is split in several repositories. The developpers have to aggregate several repositories in order to build the full aplication and run system or integration tests.

Best practice in team development recommand to use branches in order to prepare contribution and validate them before being merged.

However using these practices together isn't trivial when changes impact more than one repository:

CI servers (Gitlab CI, Github Actions, Jenkins) can easily be configured to build the integration of all repositories on a single branch or building all branches of a single repository but not tall branches of all repositories. Thus the system tests cannot easily be acheived on the aggregate for each of the development branches.

This tools aims to enable CI build (and test) for branches even if the code is distributed accross several repositories thanks to a simple name-based workflow.

This makes possible checking that API/framework changes are taken into account by the components using it.

Typical example:

  • Repo-A
  • Repo-B
  • Repo-C
  • Integration-Repo

Repo-A, Repo-B and Repo-C contain the source that need to be aggregated

Integration-Repo is a git repo with 3 submodules (one submodule for each of the Repo-x) defined in it master branch.

The goal of the script is to:

  • automatically, use the latest commit of each of the master branch of the all Repo-x in the submodule ofmaster branch of Integration-Repo
  • if one of the Repo-x define a branch (for example named foo), then create a branch in Integration-Repo with the same name (foo), in the branch, add a submodule for each of the Repo-x pointing either to the branch with this name or to the master branch.
  • cleanup any unused branches from Integration-Repo if none of the Repo-x defines such branch
  • automatically, use the latest commit of each of the indicated branches of all submodules of all branches of Integration-Repo

Compiling

cd git-sync
mvn clean install

(in case of error with gpg, make sure to enable your local gpg-agent with your personal key. For example using a command such as echo "test" | gpg --clearsign)

maven workflow

Usage

Fisrt define the sub modules in the master branch of the integration repository. (use git submodule add <URL of Repo-A>)

Add a pom.xml in the repository (in a subfolder, eg. "scripts") with a content similar to:

<?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>org.eclipse.gemoc-studio</groupId>
  <artifactId>sync-submodules</artifactId>
  <version>1.0-SNAPSHOT</version>

  <description>Project in charge of synchronizing branches of submodules for integration build</description>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <gituser.name>${env.GITUSER_NAME}</gituser.name>
    <gituser.password>${env.GITUSER_PASSWORD}</gituser.password>
    <gituser.email></gituser.email>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.gemoc.git-sync-tools</groupId>
        <artifactId>sync-git-submodules-branches-plugin</artifactId>
        <version>1.0.1</version>
        <configuration>
        	<parentGitURL>[email protected]:myorganisation/integration-repo.git</parentGitURL> <!-- replace here with the git url of your Integration-Repo --> 
        	<userOrToken>${gituser.name}</userOrToken>
        	<password>${gituser.password}</password>
        	<committerName>${gituser.name}</committerName>
        	<committerEmail>${gituser.email}</committerEmail>
        	<inactivityThreshold>90</inactivityThreshold> <!-- number of days without commit to consider a branch inactive-->
        </configuration>
        <executions>
          <execution>
            <id>synch</id>
            <phase>validate</phase>
            <goals>
              <goal>synch</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>    

then configure a CI to either:

  • periodically launch this script (via a mvn clean verify) the script must be launched with the following variable (use hidden variable as this is credentials) allowing to commit in the Integration-Repo (I strongly suggest using a bot account instead of your own account)
    • GITUSER_NAME
    • GITUSER_PASSWORD
  • or configure each of the Repo-x to trigger a build (using for ex webhooks)

The root of the Integration-Repo can then contains a CI specific configuration file (Jenkinsfile, .gitlab-ci.yml, or github actions) to build the entire application with a checkout of all the sources from all the component repositories.

Tips: the integration repository is cloned into the target folder of the maven project. Doing a mvn verify will try to reuse the existing repository in order to save network bandwidth. In case of trouble, do a mvn clean verify to force a clone.

Example scenario

From the following repositories where the development of a feature implies some changes in 3 repositories out ot 4: scenario-step1

Applying the tool (if all feature branches are active in the component repositories) will result in the following repositories. It creates 1 branches in the Integration repository where all submodules points either to the corresponding branch or the main branch of the component repository.

It also takes care to update the submodules to point to the head of all considered branches. The CI is able to build the latest version of these 2 branches (main and feature1)

scenario-step2

After some time, the feature1 branch becomes inactive (because its content is integrated in main or the development is suspended), and 2 new features are developed (each of them implying different repositories)

The tool removes the feature1 branch from the integration repository and creates 2 new branches. The CI is able to build the latest version of these 3 branches (main, feature2, and feature3).

scenario-step3

## GEMOC use case

In this use case, the sync-git-submodules-branches tool is used in 2 places in order to have multibranch build pipeline enabled for both the official maintainers (ie. Eclipse commiters) and the GEMOC community. Thus enabling circle of trust where community can still enjoy the use of continuous integration for their own development branches (prototype_feature) even if they aren't part of the eclipse organization. And Eclipse organization member can use the CI on their own branches (official_feature) (for example for validating pull requests coming from user not using a CI)

scenario-step3

git-sync-tools's People

Contributors

dependabot[bot] avatar dvojtise avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

dvojtise

git-sync-tools's Issues

Improve commit message when updating branch in order to give hint of the underlying commit

Currently when updating the submodules in the integration repository the commit message look similar to

Updating submodule gemoc-studio-modeldebugging to track head of branch master

Even if this information is useful, it would be nicer to have commit message that also reuse the last commit message from the branch it follows. This would make the CI build more friendly as it shows the last commit message.

add filter for inactiveBranches

if branches on a submodule is inactive for a long period, it should not be considered by the tool when deciding if the branch must exist in the main integration repository

If none of the submodules is active for the given branch, this branch should be removed from the integration.

Allow to exclude branches being synchronized using name filter

It would be useful that the pom.xml can define name filters allowing to include/exclude the branches in submodules that need to be added to the main multi-module repository.

This avoids having a swarm of jobs on projects having a lot of "stale" branches.

Publish a 0.0.1 version on maven central

It would be more convenient to publish the jar on a widely available repository such as maven central instead of maven.inria.fr

(this would trim the pom.xml definition)

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.