-
-
Notifications
You must be signed in to change notification settings - Fork 488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deploy from travis #1051
Deploy from travis #1051
Conversation
This would only deploy after the build succeeded right, is that what we want? |
Yep. |
I actually appreciate that we can get a preview right now even if the tests are failing (usually for silly reasons, like failing spell check). I suppose I can live without it... but have you considered running the deploy (preview) in parallel with the tests? |
That's a fair ask. Updated the config to deploy review apps without
depending on the tests & to have that done in parallel.
*Regards,*
Siva
…On Tue, Sep 10, 2019 at 9:23 AM Godfrey Chan ***@***.***> wrote:
I actually appreciate that we can get a preview right now even if the
tests are failing (usually for silly reasons, like failing spell check). I
suppose I can live without it... but have you considered running the deploy
(preview) in parallel with the tests?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1051?email_source=notifications&email_token=AAETPVJOIVW4XKYRYG7JNELQI4K35A5CNFSM4IUV73DKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6JXMVI#issuecomment-529757781>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAETPVIDJ4C24DOKJ6HGFHTQI4K35ANCNFSM4IUV73DA>
.
|
It seems like we will also lose the "Deploy preview ready!" link from the commit status, which would be a shame. (Unless I am wrong and the We have a similar setup at work (we also push the deploys from Travis, though not to Netlify). I wrote a script (in Ruby) to add the deploy preview link manually using the GitHub commit status API, which you can probably just use (if we don't mind relying on the system Ruby on Travis, which should work fine) or port to Node: begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile do
source "https://rubygems.org"
gem "activesupport"
gem "jwt"
end
require "active_support/all"
require "json"
require "net/http"
require "openssl"
require "open3"
def get_token(http)
private_pem = File.read("???.private-key.pem")
private_key = OpenSSL::PKey::RSA.new(private_pem)
payload = {
# issued at time
iat: Time.now.to_i,
# JWT expiration time
exp: 1.minute.from_now.to_i,
# Integration's GitHub identifier
iss: ???
}
jwt = JWT.encode(payload, private_key, "RS256")
response = http.post(
"/installations/???/access_tokens",
"",
"Accept" => "application/vnd.github.machine-man-preview+json",
"Authorization" => "Bearer #{jwt}",
"Content-Type" => "text/plain"
)
if response.code != "201"
raise "Failed to create token: #{response.body}"
else
JSON.parse(response.body)["token"]
end
end
def pending!(http, token, message)
create_commit_status(
http, token,
context: "Deploy",
state: "pending",
description: message,
target_url: ENV["TRAVIS_BUILD_WEB_URL"]
)
end
def error!(http, token, message)
create_commit_status(
http, token,
context: "Deploy",
state: "error",
description: message,
target_url: ENV["TRAVIS_BUILD_WEB_URL"]
)
end
def success!(http, token, message, url)
create_commit_status(
http, token,
context: "Deploy",
state: "success",
description: message,
target_url: url
)
end
def deploy!(http, token)
pending!(http, token, "Building...")
output, status = Open3.capture2("yarn deploy")
$stdout.print output
if status.success?
url = ???
success!(http, token, "Preview available", url)
else
error!(http, token, "Error!")
end
end
def create_commit_status(http, token, options)
response = http.post(
"/repos/ember-learn/guides-source/statuses/#{ENV['TRAVIS_COMMIT']}",
JSON.generate(options),
"Accept" => "application/vnd.github.machine-man-preview+json",
"Authorization" => "token #{token}",
"Content-Type" => "application/json"
)
if response.code != "201"
raise "Failed to create commit status: #{response.body}"
end
end
Net::HTTP.start("api.github.com", 443, use_ssl: true) do |http|
token = get_token(http)
if ARGV[0] == "--pending"
pending!(http, token, ARGV[1])
else
deploy!(http, token)
end
end This is how it looks: The "Details" link take you right to the deployed app once its finish, or the Travis build responsible for pushing it while it's pending. Unfortunately, it's slightly involved to setup cause you can only use the status API as an app. But once you have the app setup and generated the key-pairs, the script should Just Work™. There may also be a GitHub Action somewhere that does exactly this. I don't think this is a blocker though, but it would be good to add the link back to help contributors find their preview. Otherwise, if you have to dig through the build logs to find the URL, I think the utility of the previews are reduced significantly – most people probably won't even know that there are previews for their pull requests. |
Thanks for the script. ATM our deploys to master are failing which is the main issue this PR is trying to address. We're aware of the functionalities we're loosing by doing this, so I'll open an issue which includes your script and will detail what needs to be done to be on parity with what we used to have. |
We have around 4k files to upload during the deploy step. Netlify cli doesn't show any progress as it uploads files, so travis times out & we end up with a broken deploy again. Will close this PR in favor of a github app that can handle all these issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you everyone who helped with this! It is critical for the upcoming 3.13 release, scheduled for this week!
With this PR we get deploys to master on merges and preview apps for PRs if they're successful. We'll have to look at the travis deploy step logs to get the url for now.
I've reorganized the build steps so that we save a few mins in each build.