How can a commit in git submodule trigger a build in continuous integration?
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 likehttp://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.
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.