Add support for downloading ember HEAD into your project for testing #4

Closed
keithpitt opened this Issue Jan 13, 2012 · 15 comments

Projects

None yet

7 participants

@keithpitt
Member

It'd be nice to be able to do something like:

rake ember:get:head

Or something, that will download the latest version of ember from github, and put it into your project. We'll also need a mechanism for not using the bundled version of ember, and one that you have in your own project. I think if you put a file in vendor/javascripts that has the same name as something in the gems, it will use that one instead. Will need to test.

@keithpitt
Member

I have some really smelly code in:

https://github.com/emberjs/ember-rails/blob/ember-generator/lib/generators/ember_rails/install/install_generator.rb

if anyone wants to have a look at it. It works...but I rushed it to see how hard it would be.

@fpauser
Contributor
fpauser commented Jan 25, 2012

Could'nt this lead to problems: Handlebars-templates which are precompiled using the included ember.js-version which may differ from the actually served ember.js-version (after rails g ember_rails:install)?

@keithpitt
Member

Absolutely. I had the exact same thought today after I wrote. I need to put some conditional logic in there to read the one defined in Rails.root (as long as the user doesn't move it). This code is still a work in progress. Feel free to fork and have a play :D

@joliss
Contributor
joliss commented Apr 20, 2012

Using submodules might help for this. You could then just go into the submodule and git checkout master. I wrote a blog post about this technique.

You can then have a rake task to copy the assets, like so: https://github.com/jfirebaugh/konacha/blob/09cbbef95f/Rakefile#L8

@tchak
Member
tchak commented Apr 21, 2012

I am not a big fan of trying to pull git and build ember. We should use http://cloud.github.com/downloads/emberjs/ember.js/ember-latest.js wich in it turn should be build automaticly on each commit to master. I was talking about it with @wagenet
I am going to change install generator to use this technique. As for handlebars pre-compilation it is already taken care of here. https://github.com/emberjs/ember-rails/blob/master/lib/ember/handlebars/source.rb#L12

@joliss
Contributor
joliss commented Apr 22, 2012

On Sat, Apr 21, 2012 at 11:47, Paul Chavard
reply@reply.github.com
wrote:

I am not a big fan of trying to pull git and build ember.

Would you mind sharing why? (I'm not trying to bike-shed here, I'm
genuinely curious.)

@wagenet
Member
wagenet commented Apr 22, 2012

@joliss I'm not exactly sure why @tchak is opposed, but if we do get it set up such that ember-latest.js is really always the latest then it seems like it's not necessary to pull it down as a submodule.

@tchak
Member
tchak commented Apr 22, 2012

@joliss @wagenet well it is not like I am opposed, I juste think fetching ember-latest.js is easier and less error prone. But if you guys think it worth the effort I will clean up the existing generator and close the issues

@pangratz
Member

I thought about this and came up with the following idea:

What a about an app deployed at Heroku which gets informed via a POST call when a build has been passed. The notification is possible via Webhook notifications in Travis CI. If a POST is made to the app's specific url, it clones the ember.js repository and executes the rake upload_latest task.

require 'sinatra'
require 'json'

class TravisCiHook < Sinatra::Base

  POST '/' do
    # looks like https://gist.github.com/1225015
    data = JSON.parse request.body.read
    if (data['status_message'] == 'Passed')
       `rm -rf tmp`
       `git clone git@github.com:emberjs/ember.js.git tmp`
       Dir.chdir "tmp" do
         `gem install bundler && bundle install && bundle update && rake upload_latest`
       end
    end
  end

end

What do you think?

@pangratz
Member

Now that I think about it, I'm wondering if it is possible to "write" to the file system on Heroku - even if its temporary 😔

@joliss
Contributor
joliss commented Apr 23, 2012

@tchak @wagenet As a Rails developer, I find it very helpful when I can hack the Ember JS live in my app. It makes it much easier to contribute. So that's why I like submodules I guess. And I think pulling ember-latest.js without versioning will cause trouble when something goes wrong (no bisecting, etc.).

But anyways. I'll let you make the call.

@pangratz
Member

New idea: use rake test[all] && rake upload_to_URL as test command on Travis CI. The upload_to_URL task depends on the dist task, so we have the latest build of Ember.js in the dist folder. Afterwards it justs POST's the ember-latest.js and ember-latest.min.js to an Heroku app. This app receives the latests build of Ember and then uploads it to GitHub ...

So the rake task looks like:

desc "Upload latest Ember.js build to URL"
task :upload_to_url do
  require 'rest_client'

  url = 'http://emberjsuploader.herokuapp.com/'

  RestClient.post url, :name => 'ember-latest.js', :description => 'Ember.js Master', :file => File.new('dist/ember.js')
  RestClient.post url, :name => 'ember-latest.min.js', :description => 'Ember.js Master (minified)', :file => File.new('dist/ember.min.js')
end

and the Heroku app deployed on http://emberjsuploader.herokuapp.com/:

require 'sinatra'
require 'json'
require 'github_api'

post '/' do
  filename = params['name']
  file = "tmp/#{filename}"
  description = params['description']

  puts "credentials: #{username} #{repo} #{token}"
  puts "uploading file #{filename} (#{file}) with description #{description}"

  File.open(file, "w") do |f|
    f.write(params['file'][:tempfile].read)
  end

  size = File.size(file)
  puts "file size: #{size}"


  username  = ENV['GH_USER']
  repo = ENV['GH_REPO']
  token = ENV['GH_OAUTH_TOKEN']

  gh = Github.new :user => username, :repo => repo, :oauth_token => token

  # remvove previous download with the same name
  gh.repos.downloads do |download|
    if filename == download.name
      puts "found a file #{download.name} which is the same as #{filename}"
      gh.repos.delete_download username, repo, download.id
      break
    end
  end

  hash = gh.repos.create_download username, repo,
    "name" => filename,
    "size" => size,
    "description" => description,
    "content_type" => "application/json"

  gh.repos.upload hash, file
end
@joliss
Contributor
joliss commented Apr 26, 2012

I just ended up needing the submodule thing, so I implemented it and opened a pull request, #45. You can get onto master with

cd ember.js
git checkout master
git pull
cd ..
rake # rebuild assets in vendor/

@tchak, @pangratz, is this solution OK with you guys?

@joliss
Contributor
joliss commented Apr 26, 2012

I just ended up needing the submodule thing

To elaborate, I wanted to edit the ember code that's running in my app to try and debug some things. Having submodules in ember-rails allowed me to hack on the actual Ember sources and rebuild them into my app live.

@joliss
Contributor
joliss commented Apr 29, 2012

@pangratz By the way I still think, whether we end up using submodules or not, that we should have ember-latest.js built like you suggested (emberjs/ember.js#747). It's pretty convenient for people who want to include it directly, and it's useful for jsfiddles too.

@joliss joliss added a commit to joliss/ember-rails that referenced this issue May 28, 2012
@joliss joliss Add Ember.js and Ember Data through submodules, and add an :assets ra…
…ke task. Fixes #4, #22. Closes #23
feb98bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment