8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/capistrano_circleci/capistrano.rb', line 8
def self.load_into(configuration)
configuration.load do
before "deploy", "circleci:build_check"
namespace :circleci do
desc <<-DESC
Check the latest Circle CI Build
DESC
task :build_check, :except => { :no_release => true } do
branch = fetch(:branch, "master")
circleci_api_token = fetch(:circleci_api_token, '')
application = fetch(:application, '')
organization = fetch(:organization, '')
response = RestClient.get "https://circleci.com/api/v1/project/#{organization}/#{application}/tree/#{branch}?circle-token=#{circleci_api_token}&limit=1&offset=0"
ci_status = JSON.parse(response.body).first['status']
if ci_status =~ /^(success|fixed)$/
logger.info "Circle status is successful : #{ci_status}"
else
logger.info "Circle status must be successful before you can deploy - current status : #{ci_status}"
exit
end
end
end
end
end
|