Skip to content
Browse files

Merge pull request #573 from tdiary/release_to_github

change package:release destination from tdiary.org to github.com
  • Loading branch information...
2 parents 4603e34 + d0d7dce commit 1de2a7088b20246e7a9e571037964d0b3e9d17d7 @tdtds tdtds committed Jun 1, 2016
Showing with 66 additions and 2 deletions.
  1. +1 −0 Gemfile
  2. +10 −1 Gemfile.lock
  3. +55 −1 lib/tdiary/tasks/release.rake
View
1 Gemfile
@@ -15,6 +15,7 @@ group :development do
gem 'pit', require: false
gem 'racksh', require: false
gem 'redcarpet'
+ gem 'octokit'
group :test do
gem 'pry-byebug', platforms: [:ruby_20, :ruby_21]
View
11 Gemfile.lock
@@ -26,6 +26,8 @@ GEM
unf (>= 0.0.5, < 1.0.0)
emot (0.0.4)
thor
+ faraday (0.9.2)
+ multipart-post (>= 1.2, < 3)
fastimage (2.0.0)
addressable (~> 2)
ffi (1.9.10)
@@ -46,9 +48,12 @@ GEM
mime-types (2.99.1)
mini_portile2 (2.0.0)
multi_json (1.11.3)
+ multipart-post (2.0.0)
netrc (0.11.0)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
+ octokit (4.3.0)
+ sawyer (~> 0.7.0, >= 0.5.3)
phantomjs (2.1.1.0)
pit (0.0.7)
power_assert (0.2.7)
@@ -85,6 +90,9 @@ GEM
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubyzip (1.2.0)
+ sawyer (0.7.0)
+ addressable (>= 2.3.5, < 2.5)
+ faraday (~> 0.8, < 0.10)
selenium-webdriver (2.53.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
@@ -125,6 +133,7 @@ DEPENDENCIES
jasmine
launchy
mail
+ octokit
pit
pry-byebug
rack
@@ -140,4 +149,4 @@ DEPENDENCIES
test-unit
BUNDLED WITH
- 1.11.2
+ 1.12.1
View
56 lib/tdiary/tasks/release.rake
@@ -1,6 +1,7 @@
#
# Ralefile for releasing tDiary.
#
+require 'octokit'
STABLE = `git tag | sort -r | head -1`.chomp
REPOS = %w(tdiary-core tdiary-theme tdiary-blogkit tdiary-contrib)
@@ -85,6 +86,54 @@ def make_full_package(version = nil)
end
end
+#
+# https://developer.github.com/v3/repos/releases/#create-a-release
+#
+def create_github_release(version)
+ name = "tDiary #{version.sub(/v/, '')}"
+ puts "creating github release #{version}, #{name}"
+ begin
+ Octokit.create_release('tdiary/tdiary-core', version, name: name)
+ rescue Octokit::ClientError => e
+ STDERR.puts e
+ end
+end
+
+#
+# https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name
+#
+def find_or_create_github_release(version)
+ begin
+ release = Octokit.release_for_tag('tdiary/tdiary-core', version)
+ rescue Octokit::NotFound
+ release = create_github_release(version)
+ end
+ release
+end
+
+#
+# https://developer.github.com/v3/repos/releases/#upload-a-release-asset
+#
+def upload_github_asset(release, file)
+ puts "updating file to github: #{file}"
+ begin
+ Octokit.upload_asset(release.url, file)
+ rescue Octokit::ClientError => e
+ STDERR.puts e
+ end
+end
+
+#
+# https://developer.github.com/v3/#authentication
+#
+def login_github
+ unless ENV['GITHUB_ACCESS_TOKEN']
+ raise "Missing $GITHUB_ACCESS_TOKEN environment.\nSee: https://help.github.com/articles/creating-an-access-token-for-command-line-use/"
+ end
+ Octokit.configure {|c| c.access_token = ENV['GITHUB_ACCESS_TOKEN'] }
+ Octokit.auto_paginate = true
+end
+
namespace :package do
desc 'fetching all files from GitHub.'
task :fetch do
@@ -93,10 +142,15 @@ namespace :package do
desc 'releasing all files'
task :release do
+ login_github
Dir.chdir("tmp") do
TARBALLS = Dir["*.tar.gz"] if TARBALLS.empty?
TARBALLS.each do |tgz|
- sh "scp -P 443 #{tgz} www.tdiary.org:#{DEST_DIR}"
+ # TODO: v5.0.0.20160501 形式のバージョンに対応させる
+ version = tgz.match(/v?\d\.\d\.\d/).to_a[0]
+ next unless version
+ release = find_or_create_github_release(version)
+ upload_github_asset(release, tgz)
end
end
end

0 comments on commit 1de2a70

Please sign in to comment.
Something went wrong with that request. Please try again.