Kouhei Sutou
null+****@clear*****
Sun Sep 14 17:38:20 JST 2014
Kouhei Sutou 2014-06-05 12:50:01 +0900 (Thu, 05 Jun 2014) New Revision: 17eadddf50fc9094819fce434fa214c7115a1b46 https://github.com/groonga/heroku-groonga-builder/commit/17eadddf50fc9094819fce434fa214c7115a1b46 Message: Use Octokit Modified files: Gemfile Gemfile.lock Rakefile Modified: Gemfile (+1 -0) =================================================================== --- Gemfile 2014-05-29 18:10:12 +0900 (c58b030) +++ Gemfile 2014-06-05 12:50:01 +0900 (f5749a0) @@ -1,4 +1,5 @@ source "https://rubygems.org/" gem "rake" +gem "octokit" gem "puma" Modified: Gemfile.lock (+10 -0) =================================================================== --- Gemfile.lock 2014-05-29 18:10:12 +0900 (f99cee0) +++ Gemfile.lock 2014-06-05 12:50:01 +0900 (9c6cdc6) @@ -1,14 +1,24 @@ GEM remote: https://rubygems.org/ specs: + addressable (2.3.6) + faraday (0.9.0) + multipart-post (>= 1.2, < 3) + multipart-post (2.0.0) + octokit (3.1.0) + sawyer (~> 0.5.3) puma (2.8.2) rack (>= 1.1, < 2.0) rack (1.5.2) rake (10.3.2) + sawyer (0.5.4) + addressable (~> 2.3.5) + faraday (~> 0.8, < 0.10) PLATFORMS ruby DEPENDENCIES + octokit puma rake Modified: Rakefile (+52 -29) =================================================================== --- Rakefile 2014-05-29 18:10:12 +0900 (1efc4d5) +++ Rakefile 2014-06-05 12:50:01 +0900 (87fa7dc) @@ -1,35 +1,47 @@ +require "octokit" + task :default => :build -task :go do - go_version = "1.2.2" - go_archive_name = "go#{go_version}.linux-amd64.tar.gz" - sh("curl", "-O", "https://storage.googleapis.com/golang/#{go_archive_name}") - sh("tar", "xf", go_archive_name) +def github_token + ENV["GITHUB_TOKEN"] +end - go_root = File.join(Dir.pwd, "go") - ENV["GOROOT"] = go_root - go_path = File.join(Dir.pwd, "work", "go") - mkdir_p(go_path) - ENV["GOPATH"] = go_path +def groonga_version + ENV["GROONGA_VERSION"] || "4.0.2" +end - paths = [ - File.join(go_path, "bin"), - File.join(go_root, "bin"), - ENV["PATH"], - ] - ENV["PATH"] = paths.join(File::PATH_SEPARATOR) +def groonga_tag_name + "v#{groonga_version}" end -task :github_release => :go do - sh("go", "get", "github.com/aktau/github-release") +def github_groonga_repository + "groonga/groonga" end -task :build => :github_release do - if ENV["GITHUB_TOKEN"].nil? - raise "must set GITHUB_TOKEN environment variable" +def create_client + Octokit::Client.new(:access_token => github_token) +end + +def find_release + client = create_client + releases = client.releases(github_groonga_repository) + releases.find do |release| + release.tag_name == groonga_tag_name end +end + +def release_exist? + not find_release.nil? +end + +def ensure_create_release + return if release_exist? - groonga_version = ENV["GROONGA_VERSION"] || "4.0.2" + client = create_client + client.create_release(github_groonga_repository, groonga_tag_name) +end + +def build_groonga base_name = "groonga-#{groonga_version}" archive_name = "#{base_name}.tar.gz" sh("curl", "-O", "http://packages.groonga.org/source/groonga/#{archive_name}") @@ -53,11 +65,22 @@ task :build => :github_release do built_archive_name = "heroku-#{base_name}.tar.xz" sh("tar", "cJf", built_archive_name, "vendor/groonga") - sh("github-release", - "upload", - "--user", "groonga", - "--repo", "groonga", - "--tag", "v#{groonga_version}", - "--name", built_archive_name, - "--file", built_archive_name) + build_archive_name +end + +def upload_archive(archive_name) + release = find_release + + client = create_client + client.upload_asset(release.url, archive_name) +end + +task :build do + if github_token.nil? + raise "must set GITHUB_TOKEN environment variable" + end + + ensure_create_release + archive_name = build_groonga + release_archive(archive_name) end -------------- next part -------------- HTML����������������������������... Descargar