How can a commit in git submodule trigger a build in continuous integration?

I'm working on project A, and A is depending on a fast-developing project B(its master branch).

Therefore, B is a submodule of A, everytime I build A, B is also re-built. Besides, everytime B has a new commit, I need to build B, then re-built A.(Luckily, the projects are small enough, so the compiling time isn't important).

Now, here's the point. I want to trigger a new build in Travis CI or other continuous integration services, when there is a new commit in project A or B.

I just tried Github & Travis CI. A commit in project B would not trigger a build in project A. Is there a simple way to run such a continuous integration?


A commit in project B would not trigger a build in project A

That is expected, considering B has no idea A exists.

You would need to record the new state of B (new gitlink , special entry in the index) of project A by doing:

cd /path/to/projectA
git submodule update --remote
git add .
git commit -m "Record new B SHA1 gitlink"
git push

git submodule update --remote will update submodule B to the latest commit of the branch recorded in A .gitmodules file for B.
See "git submodule tracking latest" and "Git submodules: Specify a branch/tag"

Then a new Travis build would be triggered for A.

If you want to automate the sequence described above, you would need a webhook (GitHub) (or BitBucket) for projectB, and a local listener which, on a push event on repo B, would trigger the commands mentioned before in a local repo of project A.


Based on @VonC 's question, I solved this problem. Ref https://developer.github.com/webhooks/configuring/

  • I set up project Monitor, which has two submodules, project A and B
  • Create file trigger.rb in project Monitor
  • require 'sinatra'

    post '/payload' do
      system("git submodule update --remote")
      system("git add .")
      system("git commit -m Record_new_change")
      system("git push")
      puts "Finished handling"
    end
    
  • Download ngrok, run it on a VPS or a long running commpuer with ./ngrok http 4567 . You may got a link like http://7e9ea9dc.ngrok.io
  • Run ruby trigger.rb
  • Fork project B to B', write another script to make sure that all the commits are synchronized to project B'
  • Go to project settings page, create a new webhook, whose url is http://7e9ea9dc.ngrok.io/payload for project A and B'
  • Add project Monitor to Travis CI
  • In this way, the development for A and B is untouched, and the new builds can be triggered automatically.

    链接地址: http://www.djcxy.com/p/92280.html

    上一篇: 嵌套的GIT Repository错误方法将其删除?

    下一篇: git子模块中的提交如何在持续集成中触发构建?