Skip to content

Commit

Permalink
[travis][ci] launch core and extras if merge successful
Browse files Browse the repository at this point in the history
[rakefile] fix repo names.

[travis] can we do without the matrix.

[travis] use uri path to create post object.
  • Loading branch information
truthbk committed Feb 23, 2017
1 parent b74d12f commit 745aafa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
17 changes: 9 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sudo: false
branches:
only:
- master
- jaime/triggerci
- /^\d+\.\d+\.x$/ # release forked patches branch

language: python
Expand All @@ -15,9 +16,6 @@ cache:
- vendor/cache
- $HOME/embedded

matrix:
fast_finish: true

env:
global:
- CONCURRENCY=2
Expand All @@ -26,11 +24,8 @@ env:
- PIP_CACHE=$HOME/.cache/pip
- VOLATILE_DIR=/tmp
- DD_CASHER_DIR=/tmp/casher
- secure: cljGaYMtRkLuW1xjGyF8W0ACrkBwHQTGJUaEoqxtIEJaVjLwcuznny9qzuQvF8YJhjs7g9eRAsZqWGpgRw765rzUB5C4Cp5GpUdTHS/fPINj3AXRzGztL2m6DHBidjEyYaX8dryO4xR0uCULwp4bSI0Rht71VqE90/6z1ehIzBs=
matrix:
- TRAVIS_FLAVOR=default
- TRAVIS_FLAVOR=core_integration
- TRAVIS_FLAVOR=checks_mock
- TRAVIS_FLAVOR=system

# Override travis defaults with empty jobs
before_install: echo "OVERRIDING TRAVIS STEPS"
Expand All @@ -43,9 +38,15 @@ script:
# Needed if no cache exists
- mkdir -p $INTEGRATIONS_DIR
- ls -al $INTEGRATIONS_DIR
- 'rake ci:run'
- 'rake ci:run[default]'
- 'rake ci:run[core_integration]'
- 'rake ci:run[checks_mock]'
- 'rake ci:run[system]'
- ls -al $INTEGRATIONS_DIR

after_success:
- 'rake ci:trigger[integrations-core]'
- 'rake ci:trigger[integrations-extras]'

after_failure:
- echo "Logs from installation process come here / DEBUG LOGS"
Expand Down
29 changes: 29 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env rake
# encoding: utf-8
# 3p
require 'json'
require 'net/http'
require 'rake/clean'
require 'rubocop/rake_task'

Expand Down Expand Up @@ -87,6 +89,33 @@ namespace :ci do
flavors = flavor.split(',')
flavors.each { |f| Rake::Task["ci:#{f}:execute"].invoke }
end

desc 'Trigger remote CI'
task :trigger, :repo do |_, args|
abort 'Task only applies to travis builds.' if !ENV['TRAVIS'] || !ENV['TRAVIS_API_TOKEN']
repo = "DataDog%2F#{args[:repo]}"
url = "https://api.travis-ci.org/repo/#{repo}/requests"
body = { 'request' => { 'branch' => 'master' } }.to_json

uri = URI(url)
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
req = Net::HTTP::Post.new(uri.path)
req['Content-Type'] = 'application/json'
req['Accept'] = 'application/json'
req['Travis-API-Version'] = '3'
req['Authorization'] = "token #{ENV['TRAVIS_API_TOKEN']}"
# The body needs to be a JSON string, use whatever you know to parse Hash to JSON
req.body = body
http.request(req)
end

case res
when Net::HTTPSuccess then
puts "Build Triggered remotely for: #{url}"
else
puts "Error triggering build (error #{res.code}): #{url}"
end
end
end

task default: ['lint', 'ci:run']

0 comments on commit 745aafa

Please sign in to comment.