From: MATSUOKA K. <nul...@cl...> - 2016-06-01 04:01:19
|
MATSUOKA Kohei 2016-06-01 12:55:47 +0900 (Wed, 01 Jun 2016) New Revision: d0d7dce18bd21ff6da44570bef1114a44e3c4bff https://github.com/tdiary/tdiary-core/commit/d0d7dce18bd21ff6da44570bef1114a44e3c4bff Message: change package:release destination from tdiary.org to github.com usage: `$ GITHUB_ACCESS_TOKEN={your_token} bundle exec rake package:release` see: https://help.github.com/articles/creating-an-access-token-for-command-line-use/ Modified files: Gemfile Gemfile.lock lib/tdiary/tasks/release.rake Modified: Gemfile (+1 -0) =================================================================== --- Gemfile 2016-05-25 11:37:04 +0900 (2d33008) +++ Gemfile 2016-06-01 12:55:47 +0900 (9b75db4) @@ -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] Modified: Gemfile.lock (+10 -1) =================================================================== --- Gemfile.lock 2016-05-25 11:37:04 +0900 (78b5671) +++ Gemfile.lock 2016-06-01 12:55:47 +0900 (65fe5a1) @@ -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 Modified: lib/tdiary/tasks/release.rake (+55 -1) =================================================================== --- lib/tdiary/tasks/release.rake 2016-05-25 11:37:04 +0900 (1d565f5) +++ lib/tdiary/tasks/release.rake 2016-06-01 12:55:47 +0900 (507f9f1) @@ -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 |