10

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?

Endle_Zhenbo
  • 538
  • 4
  • 23
  • 2
    I'm not sure that I understand. Normally with submodules, your main project would depend on _a particular revision_ of the submodule. An update in the submodule repo _shouldn't_ trigger a build in the primary repo until the primary repo's dependency is updated to a newer revision, which would cause a rebuild of the main repo anyway. Am I missing something? – ChrisGPT was on strike Jan 10 '16 at 16:16
  • @Chris thanks. I know it's better to depend on a revision. But in this case, project B is developing really fast, leaving no revision for me to depend, and I need to keep the pace with master branch. This situation is not common, but really exists. – Endle_Zhenbo Jan 10 '16 at 16:49
  • So you have a submodule tracking a branch (i.e. created using the `-b` flag) and you want to kick off a new build for the primary repository any time the submodule branch is updated? – ChrisGPT was on strike Jan 10 '16 at 17:02
  • @Chris yes, that's what I want. Sorry for my expression – Endle_Zhenbo Jan 10 '16 at 17:13

3 Answers3

8

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
3

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

  1. I set up project Monitor, which has two submodules, project A and B
  2. 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
  1. 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
  2. Run ruby trigger.rb
  3. Fork project B to B', write another script to make sure that all the commits are synchronized to project B'
  4. Go to project settings page, create a new webhook, whose url is http://7e9ea9dc.ngrok.io/payload for project A and B'
  5. 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.

Endle_Zhenbo
  • 538
  • 4
  • 23
0

I have used gitlab-ci to trigger a parent pipeline when a submodule is updated. Please check here