Skip to content

Commit

Permalink
Add upload_latest rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
pangratz committed Jun 9, 2012
1 parent 7d2f845 commit bceb024
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -7,4 +7,6 @@ dist/
.DS_Store .DS_Store
.project .project


.github-upload-token

tests/ember-data-tests.js tests/ember-data-tests.js
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -6,3 +6,5 @@ before_script:
- "sh -e /etc/init.d/xvfb start" - "sh -e /etc/init.d/xvfb start"
- "rake clean" - "rake clean"
script: "rake test[all]" script: "rake test[all]"
notifications:
webhooks: http://emberjs-master-builds.herokuapp.com/upload/data
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -7,7 +7,8 @@ gem "uglifier", "~> 1.0.3"


group :development do group :development do
gem "rack" gem "rack"
gem "github-upload" gem "rest-client"
gem "github_api"
gem "ember-docs", :git => "https://github.com/emberjs/docs-generator.git" gem "ember-docs", :git => "https://github.com/emberjs/docs-generator.git"
gem "kicker" gem "kicker"
end end
52 changes: 29 additions & 23 deletions Gemfile.lock
@@ -1,22 +1,22 @@
GIT GIT
remote: https://github.com/emberjs/docs-generator.git remote: https://github.com/emberjs/docs-generator.git
revision: cfbb82496c1c342ff6da49fc46559dd8fddf8b55 revision: cfbc2a3aabc08de305224b290ad8f37f3ef5f847
specs: specs:
ember-docs (0.1) ember-docs (0.1)
rack rack
thor thor


GIT GIT
remote: https://github.com/livingsocial/rake-pipeline.git remote: https://github.com/livingsocial/rake-pipeline.git
revision: b70ca6cad7655e58d13031f3e24df7dfc74f9030 revision: 543f4322fe70facee9572d29ddabf7f090dad68a
specs: specs:
rake-pipeline (0.6.0) rake-pipeline (0.6.0)
rake (~> 0.9.0) rake (~> 0.9.0)
thor thor


GIT GIT
remote: https://github.com/wycats/rake-pipeline-web-filters.git remote: https://github.com/wycats/rake-pipeline-web-filters.git
revision: ba0b8a00356b4c854930a8e849b5629d51ffd70f revision: 81a22fb0808dfdeab8ed92d5d8c898ad198b9938
specs: specs:
rake-pipeline-web-filters (0.6.0) rake-pipeline-web-filters (0.6.0)
rack rack
Expand All @@ -26,30 +26,35 @@ GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
colored (1.2) colored (1.2)
confparser (0.0.2.1) execjs (1.4.0)
execjs (1.3.0)
multi_json (~> 1.0) multi_json (~> 1.0)
faster_xml_simple (0.5.0) faraday (0.8.1)
libxml-ruby (>= 0.3.8.4) multipart-post (~> 1.1)
github-upload (0.0.2) github_api (0.5.4)
confparser faraday (~> 0.8.0)
net-github-upload (>= 0.0.6) hashie (~> 1.2.0)
httpclient (2.2.4) multi_json (~> 1.3)
json (1.6.6) nokogiri (~> 1.5.2)
oauth2 (~> 0.7)
hashie (1.2.0)
httpauth (0.1)
kicker (2.5.0) kicker (2.5.0)
rb-fsevent rb-fsevent
libxml-ruby (2.3.2) mime-types (1.18)
multi_json (1.2.0) multi_json (1.3.6)
net-github-upload (0.0.8) multipart-post (1.1.5)
faster_xml_simple nokogiri (1.5.3)
httpclient oauth2 (0.7.1)
json faraday (~> 0.8)
nokogiri (>= 1.4.0) httpauth (~> 0.1)
nokogiri (1.5.2) multi_json (~> 1.0)
rack (~> 1.4)
rack (1.4.1) rack (1.4.1)
rake (0.9.2.2) rake (0.9.2.2)
rb-fsevent (0.9.0) rb-fsevent (0.9.1)
thor (0.14.6) rest-client (1.6.7)
mime-types (>= 1.16)
thor (0.15.2)
uglifier (1.0.4) uglifier (1.0.4)
execjs (>= 0.3.0) execjs (>= 0.3.0)
multi_json (>= 1.0.2) multi_json (>= 1.0.2)
Expand All @@ -60,9 +65,10 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
colored colored
ember-docs! ember-docs!
github-upload github_api
kicker kicker
rack rack
rake-pipeline! rake-pipeline!
rake-pipeline-web-filters! rake-pipeline-web-filters!
rest-client
uglifier (~> 1.0.3) uglifier (~> 1.0.3)
43 changes: 43 additions & 0 deletions Rakefile
Expand Up @@ -10,6 +10,40 @@ def pipeline
Rake::Pipeline::Project.new("Assetfile") Rake::Pipeline::Project.new("Assetfile")
end end


def setup_uploader
require './lib/github_uploader'

# get the github user name
login = `git config github.user`.chomp

# get repo from git config's origin url
origin = `git config remote.origin.url`.chomp # url to origin
# extract USERNAME/REPO_NAME
# sample urls: https://github.com/emberjs/ember.js.git
# git://github.com/emberjs/ember.js.git
# git@github.com:emberjs/ember.js.git
# git@github.com:emberjs/ember.js

repoUrl = origin.match(/github\.com[\/:]((.+?)\/(.+?))(\.git)?$/)
username = repoUrl[2] # username part of origin url
repo = repoUrl[3] # repository name part of origin url

token = ENV["GH_OAUTH_TOKEN"]
uploader = GithubUploader.new(login, username, repo, token)
uploader.authorize

uploader
end

def upload_file(uploader, filename, description, file)
print "Uploading #{filename}..."
if uploader.upload_file(filename, description, file)
puts "Success"
else
puts "Failure"
end
end

desc "Strip trailing whitespace for JavaScript files in packages" desc "Strip trailing whitespace for JavaScript files in packages"
task :strip_whitespace do task :strip_whitespace do
Dir["packages/**/*.js"].each do |name| Dir["packages/**/*.js"].each do |name|
Expand All @@ -34,6 +68,15 @@ task :clean do
puts "Done" puts "Done"
end end


desc "Upload latest Ember Data build to GitHub repository"
task :upload_latest => :dist do
uploader = setup_uploader

# Upload minified first, so non-minified shows up on top
upload_file(uploader, 'ember-data-latest.min.js', "Ember Data Master (minified)", "dist/ember-data.min.js")
upload_file(uploader, 'ember-data-latest.js', "Ember Data Master", "dist/ember-data.js")
end

desc "Run tests with phantomjs" desc "Run tests with phantomjs"
task :test, [:suite] => :dist do |t, args| task :test, [:suite] => :dist do |t, args|
unless system("which phantomjs > /dev/null 2>&1") unless system("which phantomjs > /dev/null 2>&1")
Expand Down
86 changes: 86 additions & 0 deletions lib/github_uploader.rb
@@ -0,0 +1,86 @@
require "rest-client"
require "github_api"

class GithubUploader

def initialize(login, username, repo, token=nil, root=Dir.pwd)
@login = login
@username = username
@repo = repo
@root = root
@token = token || check_token
end

def authorized?
!!@token
end

def token_path
File.expand_path(".github-upload-token", @root)
end

def check_token
File.exist?(token_path) ? File.open(token_path, "rb").read : nil
end

def authorize
return if authorized?

puts "There is no file named .github-upload-token in this folder. This file holds the OAuth token needed to communicate with GitHub."
puts "You will be asked to enter your GitHub password so a new OAuth token will be created."
print "GitHub Password: "
system "stty -echo" # disable echoing of entered chars so password is not shown on console
pw = STDIN.gets.chomp
system "stty echo" # enable echoing of entered chars
puts ""

# check if the user already granted access for Ember.js Uploader by checking the available authorizations
response = RestClient.get "https://#{@login}:#{pw}@api.github.com/authorizations"
JSON.parse(response.to_str).each do |auth|
if auth["note"] == "Ember.js Uploader"
# user already granted access, so we reuse the existing token
@token = auth["token"]
end
end

## we need to create a new token
unless @token
payload = {
:scopes => ["public_repo"],
:note => "Ember.js Uploader",
:note_url => "https://github.com/#{@username}/#{@repo}"
}
response = RestClient.post "https://#{@login}:#{pw}@api.github.com/authorizations", payload.to_json, :content_type => :json
@token = JSON.parse(response.to_str)["token"]
end

# finally save the token into .github-upload-token
File.open(".github-upload-token", 'w') {|f| f.write(@token)}
end

def upload_file(filename, description, file)
return false unless authorized?

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

# remvove previous download with the same name
gh.repos.downloads.list @username, @repo do |download|
if filename == download.name
gh.repos.downloads.delete @username, @repo, download.id
break
end
end

# step 1
hash = gh.repos.downloads.create @username, @repo,
"name" => filename,
"size" => File.size(file),
"description" => description

# step 2
gh.repos.downloads.upload hash, file

return true
end

end

0 comments on commit bceb024

Please sign in to comment.