Created
March 25, 2012 18:21
-
-
Save stepheneb/2198834 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
| $ bundle exec scripts/upload-dist.rb | |
| opening connection to api.github.com... | |
| opened | |
| <- "POST /repos/concord-consortium/lab/downloads HTTP/1.1\r\nAuthorization: Basic c3RlcGhlbmViOm4wMGRsZQ==\r\nConnection: close\r\nHost: api.github.com\r\nContent-Length: 147\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n" | |
| <- "{\"name\":\"lab-dist-2012-03-24-e5ce60c.tar.gz\",\"size\":9433478,\"description\":\"Latest release of Lab distribution\",\"content_type\":\"application/x-gzip\"}" | |
| -> "HTTP/1.1 201 Created\r\n" | |
| -> "Server: nginx/1.0.13\r\n" | |
| -> "Date: Sun, 25 Mar 2012 18:19:18 GMT\r\n" | |
| -> "Content-Type: application/json; charset=utf-8\r\n" | |
| -> "Connection: close\r\n" | |
| -> "Status: 201 Created\r\n" | |
| -> "X-RateLimit-Limit: 5000\r\n" | |
| -> "ETag: \"ec3c3910b50314e8ae2bde089a1ff014\"\r\n" | |
| -> "Location: https://api.github.com/repos/concord-consortium/lab/downloads/209316\r\n" | |
| -> "X-RateLimit-Remaining: 4998\r\n" | |
| -> "Content-Length: 1252\r\n" | |
| -> "\r\n" | |
| reading 1252 bytes... | |
| -> "{\"accesskeyid\":\"1DWESVTPGHQVTX38V182\",\"redirect\":false,\"html_url\":\"https://github.com/downloads/concord-consortium/lab/lab-dist-2012-03-24-e5ce60c.tar.gz\",\"url\":\"https://api.github.com/repos/concord-consortium/lab/downloads/209316\",\"mime_type\":\"application/x-gzip\",\"signature\":\"Z8eBvEEq80ccbT4wbOkv7I3vgh4=\",\"content_type\":\"application/x-gzip\",\"expirationdate\":\"2112-03-25T18:19:18.000Z\",\"acl\":\"public-read\",\"download_count\":0,\"created_at\":\"2012-03-25T18:19:18Z\",\"prefix\":\"downloads/concord-consortium/lab\",\"bucket\":\"github\",\"policy\":\"ewogICAgJ2V4cGlyYXRpb24nOiAnMjExMi0wMy0yNVQxODoxOToxOC4wMDBaJywKICAgICdjb25kaXRpb25zJzogWwogICAgICAgIHsnYnVja2V0JzogJ2dpdGh1Yid9LAogICAgICAgIHsna2V5JzogJ2Rvd25sb2Fkcy9jb25jb3JkLWNvbnNvcnRpdW0vbGFiL2xhYi1kaXN0LTIwMTItMDMtMjQtZTVjZTYwYy50YXIuZ3onfSwKICAgICAgICB7J2FjbCc6ICdwdWJsaWMtcmVhZCd9LAogICAgICAgIHsnc3VjY2Vzc19hY3Rpb25fc3RhdHVzJzogJzIwMSd9LAogICAgICAgIFsnc3RhcnRzLXdpdGgnLCAnJEZpbGVuYW1lJywgJyddLAogICAgICAgIFsnc3RhcnRzLXdpdGgnLCAnJENvbnRlbnQtVHlwZScsICcnXQogICAgXQp9\",\"size\":9433088,\"description\":\"Latest release of Lab distribution\",\"name\":\"lab-dist-2012-03-24-e5ce60c.tar.gz\",\"path\":\"downloads/concord-consortium/lab/lab-dist-2012-03-24-e5ce60c.tar.gz\",\"s3_url\":\"https://github.s3.amazonaws.com/\",\"id\":209316}" | |
| read 1252 bytes | |
| Conn close | |
| {"accesskeyid"=>"1DWESVTPGHQVTX38V182", | |
| "redirect"=>false, | |
| "html_url"=> | |
| "https://github.com/downloads/concord-consortium/lab/lab-dist-2012-03-24-e5ce60c.tar.gz", | |
| "url"=>"https://api.github.com/repos/concord-consortium/lab/downloads/209316", | |
| "mime_type"=>"application/x-gzip", | |
| "signature"=>"Z8eBvEEq80ccbT4wbOkv7I3vgh4=", | |
| "content_type"=>"application/x-gzip", | |
| "expirationdate"=>"2112-03-25T18:19:18.000Z", | |
| "acl"=>"public-read", | |
| "download_count"=>0, | |
| "created_at"=>"2012-03-25T18:19:18Z", | |
| "prefix"=>"downloads/concord-consortium/lab", | |
| "bucket"=>"github", | |
| "policy"=> | |
| "ewogICAgJ2V4cGlyYXRpb24nOiAnMjExMi0wMy0yNVQxODoxOToxOC4wMDBaJywKICAgICdjb25kaXRpb25zJzogWwogICAgICAgIHsnYnVja2V0JzogJ2dpdGh1Yid9LAogICAgICAgIHsna2V5JzogJ2Rvd25sb2Fkcy9jb25jb3JkLWNvbnNvcnRpdW0vbGFiL2xhYi1kaXN0LTIwMTItMDMtMjQtZTVjZTYwYy50YXIuZ3onfSwKICAgICAgICB7J2FjbCc6ICdwdWJsaWMtcmVhZCd9LAogICAgICAgIHsnc3VjY2Vzc19hY3Rpb25fc3RhdHVzJzogJzIwMSd9LAogICAgICAgIFsnc3RhcnRzLXdpdGgnLCAnJEZpbGVuYW1lJywgJyddLAogICAgICAgIFsnc3RhcnRzLXdpdGgnLCAnJENvbnRlbnQtVHlwZScsICcnXQogICAgXQp9", | |
| "size"=>9433088, | |
| "description"=>"Latest release of Lab distribution", | |
| "name"=>"lab-dist-2012-03-24-e5ce60c.tar.gz", | |
| "path"=>"downloads/concord-consortium/lab/lab-dist-2012-03-24-e5ce60c.tar.gz", | |
| "s3_url"=>"https://github.s3.amazonaws.com/", | |
| "id"=>209316} | |
| scripts/upload-dist.rb:59:in `file': wrong number of arguments (1 for 2..3) (ArgumentError) | |
| from scripts/upload-dist.rb:59:in `<main>' |
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 'httparty' | |
| require 'yaml' | |
| require 'multi_json' | |
| require 'pp' | |
| require 'net/http/post/multipart' | |
| PROJECT_ROOT = File.expand_path('../..', __FILE__) | |
| CONFIG_PATH = File.join(PROJECT_ROOT, 'config') | |
| begin | |
| CONFIG = YAML.load_file(File.join(CONFIG_PATH, 'config.yml')) | |
| rescue Errno::ENOENT | |
| msg = <<-HEREDOC | |
| *** missing config/config.yml | |
| cp config/config_sample.yml config/config.yml | |
| and edit appropriately ... | |
| HEREDOC | |
| raise msg | |
| end | |
| class Github | |
| include HTTParty | |
| base_uri 'https://api.github.com/repos/concord-consortium/lab' | |
| format :json | |
| basic_auth CONFIG[:username], CONFIG[:password] | |
| debug_output | |
| end | |
| tag = `git log -1 --date=short --format=%cd-%h gh-pages`.strip | |
| name = "lab-dist-#{tag}.tar.gz" | |
| if File.exist?("uploads/#{name}") || system("git archive gh-pages | gzip >uploads/#{name}") | |
| options = { | |
| "name" => name, | |
| "size" => File.stat("uploads/#{name}").size, | |
| "description" => "Latest release of Lab distribution", | |
| "content_type" => "application/x-gzip" | |
| } | |
| response = Github.post('/downloads', :body => MultiJson.encode(options)) | |
| pp response | |
| url = URI.parse(response['s3_url']) | |
| File.open("#{PROJECT_ROOT}/uploads/#{name}") do |archive| | |
| req = Net::HTTP::Post::Multipart.new url.path, | |
| 'key' => response['path'], | |
| 'acl' => response['acl'], | |
| 'success_action_status' => 201, | |
| 'Filename' => response['name'], | |
| 'AWSAccessKeyId' => response['accesskeyid'], | |
| 'Policy' => response['policy'], | |
| 'Signature' => response['signature'], | |
| 'Content-Type' => response['mime_type'], | |
| "file" => UploadIO.new(archive, response['mime_type']) | |
| res = Net::HTTP.start(url.host, url.port) do |http| | |
| http.request(req) | |
| end | |
| end | |
| # curl = Curl::Easy.new(response['s3_url']) | |
| # curl.multipart_form_post = true | |
| # curl.http_post( | |
| # Curl::PostField.content('key', "response['path']"), | |
| # Curl::PostField.content('acl', "response['acl']"), | |
| # Curl::PostField.content('success_action_status', "201"), | |
| # Curl::PostField.content('Filename', "response['name']"), | |
| # Curl::PostField.content('AWSAccessKeyId', "response['accesskeyid']"), | |
| # Curl::PostField.content('Policy', "response['policy']"), | |
| # Curl::PostField.content('Signature', "response['signature']"), | |
| # Curl::PostField.content('Content-Type', "response['mime_type']"), | |
| # Curl::PostField.file("#{PROJECT_ROOT}/uploads/#{name}")) | |
| # response = Github.delete("/downloads/209058") | |
| # response = Github.delete("/downloads/#{response['id']}") | |
| # pp response | |
| else | |
| puts "error saving git archive: uploads/#{name}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment