Navigation Menu

Skip to content

Commit

Permalink
Use Octokit
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 5, 2014
1 parent c39b5d7 commit 17eaddd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 29 deletions.
1 change: 1 addition & 0 deletions Gemfile
@@ -1,4 +1,5 @@
source "https://rubygems.org/"

gem "rake"
gem "octokit"
gem "puma"
10 changes: 10 additions & 0 deletions Gemfile.lock
@@ -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
81 changes: 52 additions & 29 deletions Rakefile
@@ -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}")
Expand All @@ -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

0 comments on commit 17eaddd

Please sign in to comment.