-
-
Save sescobb27/112f4c66d4e280ac27c993d4d6c5e062 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'json' | |
def create_deployment(sha) | |
uri = URI('https://api.github.com/repos/envoy/garaje/deployments') | |
req = Net::HTTP::Post.new(uri.path, { | |
'Content-Type' => 'application/json', | |
'Authorization' => "token #{ENV['GITHOUT_OAUTH_TOKEN']}" | |
}) | |
req.body = { | |
ref: sha, | |
environment: 'staging', | |
auto_merge: false, | |
required_contexts: [] | |
}.to_json | |
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| | |
http.request(req) | |
end | |
puts res.body | |
JSON.parse(res.body) | |
end | |
def update_deployment_status(deployment, payload) | |
uri = URI("https://api.github.com/repos/envoy/garaje/deployments/#{deployment['id']}/statuses") | |
req = Net::HTTP::Post.new(uri.path, { | |
'Content-Type' => 'application/json', | |
'Authorization' => "token #{ENV['OAUTH_TOKEN']}" | |
}) | |
req.body = payload.to_json | |
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| | |
http.request(req) | |
end | |
end | |
commit_sha = `git rev-parse --short HEAD`.chomp | |
deployment = create_deployment(commit_sha) | |
puts "Deploying ..." | |
update_deployment_status(deployment, state: 'pending') | |
if system('PATH=$PATH:$(npm bin) ember deploy staging') | |
url = "https://dashboard.envoy.christmas/index.html:#{commit_sha}" | |
update_deployment_status(deployment, { | |
state: 'success', | |
target_url: url | |
}) | |
puts "Deployed to #{url}" | |
else | |
update_deployment_status(deployment, state: 'failure') | |
puts "Deployed failed" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment