-
Notifications
You must be signed in to change notification settings - Fork 87
/
Rakefile
100 lines (82 loc) · 3.21 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
$LOAD_PATH << '.'
require 'scripts/package/run'
require 'scripts/plugin/build'
require 'scripts/plugin/release_plugin'
require 'scripts/release/run'
require 'scripts/release/check_released_version'
require 'scripts/package/update_plugins_version'
require 'rubygems/version.rb'
require 'yaml'
PACKAGE_FILE = File.join(__dir__, 'mbox-package.yml')
BUILD_DIR = File.expand_path(File.join(__dir__, '../build'))
PACKAGE_DIR = File.expand_path(File.join(__dir__, '../package'))
HOMEBREW_DIR = File.expand_path(File.join(__dir__, '../brew'))
if ENV['GITHUB_TOKEN']
GITHUB_TOKEN = ENV['GITHUB_TOKEN']
else
GITHUB_TOKEN_FILE = File.join(__dir__, 'github.token')
GITHUB_TOKEN = File.read(GITHUB_TOKEN_FILE).strip
end
raise "GITHUB_TOKEN is missing".red if GITHUB_TOKEN.nil?
task default: %w[package]
task :bump, [:version] do |task, args|
package_info = YAML.load_file(PACKAGE_FILE)
version = ''
if !args[:version].nil? && !args[:version].strip.empty?
LOG.info "Bump version #{package_info["version"].yellow} -> #{args[:version].to_s.green}." do
version = args[:version]
end
else
version = Gem::Version.new(package_info["version"])
version = version.bump.to_s + ".0"
LOG.info "Bump version #{package_info["version"].yellow} -> #{version.to_s.green}."
end
raise "#{version} is not a valid semver version string.".red unless version =~ /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
package_info["version"] = version
File.write(PACKAGE_FILE, YAML.dump(package_info))
"git add mbox-package.yml".exec(__dir__)
"git commit -m 'bump v#{package_info["version"]}'".exec(__dir__)
"git push origin".exec(__dir__)
end
task :check_released_version, [:github_token] do |task, args|
github_token = get_github_token(args)
check_released_version(github_token, PACKAGE_FILE)
end
task :bump_plugin, [:github_token] do |task, args|
github_token = get_github_token(args)
update_plugins_version(github_token, PACKAGE_FILE)
end
task :build_plugin do |task, args|
FileUtils.rm_rf(BUILD_DIR)
FileUtils.mkdir(BUILD_DIR) unless File.exists?(BUILD_DIR)
build(BUILD_DIR, PACKAGE_FILE)
end
task :release_plugin, [:github_token] do |task, args|
github_token = get_github_token(args)
release_all_plugin(github_token, PACKAGE_FILE, BUILD_DIR)
end
task :package, [:suffix, :github_token] do |task, args|
github_token = get_github_token(args)
if args[:suffix].nil? || args[:suffix].empty?
package(github_token, PACKAGE_DIR, PACKAGE_FILE)
else
package(github_token, PACKAGE_DIR, PACKAGE_FILE, args[:suffix])
end
end
task :release, [:branch, :github_token] do |task, args|
github_token = get_github_token(args)
branch = args[:branch].sub('refs/head/', '')
release(github_token, PACKAGE_DIR, branch)
end
task :release_homebrew, [:tag] do |task, args|
github_token = get_github_token(args)
release_homebrew(github_token, args[:tag].sub('refs/tags/', ''), HOMEBREW_DIR, PACKAGE_FILE)
end
def get_github_token(args)
token = args[:github_token] || GITHUB_TOKEN
if !token.nil? && !token.empty?
token
else
raise "Github Token is Needed.".red
end
end