forked from jgraichen/redmine_dashboard
/
Rakefile
158 lines (138 loc) · 4.25 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#
# Dashboard tasks
#
task :default => :spec
desc 'Run specs.'
task :spec, [ :opts ] => [ :setup ] do |t, args|
args.with_defaults :opts => 'plugins/redmine_dashboard/spec'
Dir.chdir path do
exec 'bash', '-lc', "bundle exec rspec -I '#{path}/plugins/redmine_dashboard/spec' #{args[:opts].to_s.gsub("'", "\'")}"
end
end
desc 'Setup project environment.'
task :setup => [ 'redmine:setup' ] do
# just for delegation
end
#
# Redmine tasks
#
BASE = Dir.getwd
def version; ENV["REDMINE_VERSION"] || "2.3.2" end
def archive; "#{version}.tar.gz" end
def exec(*attrs)
puts "+ #{attrs.join(' ')}"
unless system(*attrs)
raise StandardError.new "Command failed: #{attrs.join(' ')}"
end
end
def unless_done(name, version = 1, &block)
donefile = "#{path}/.rdb-done-#{name}.#{version}"
envs = []
if File.exists? donefile
envs = IO.read(donefile).split("\n").map{|s|s.strip}
end
unless envs.include? RUBY_DESCRIPTION
yield
exec "echo '#{RUBY_DESCRIPTION}' >> #{donefile}"
end
end
def tmpdir; "#{BASE}/tmp" end
def archives_path; "#{tmpdir}/archives" end
def redmines_path; "#{tmpdir}/redmines" end
def databases_path; "#{tmpdir}/databases" end
def bundle_path; "#{tmpdir}/bundle" end
def database_path; "#{databases_path}/#{version}" end
def archive_path; "#{archives_path}/#{archive}" end
def path; "#{redmines_path}/#{version}" end
def bx(*attrs); exec *(['bundle', 'exec'] + attrs) end
def bxrake(*attrs); bx *(['rake'] + attrs) end
def mkpath(*paths); exec *(['mkdir', '-p'] + paths) end
def jruby?; Object.const_defined?(:JRUBY_VERSION) end
namespace :redmine do
desc 'Install redmine to tmp dir.'
task :install => [ :download ] do
unless_done('install', 2) do
Dir.chdir path do
# database config
mkpath database_path
File.open("#{path}/config/database.yml", 'w') do |file|
file.write <<-DATABASE
common: &common
pool: 5
timeout: 5000
DATABASE
file.write jruby? ? " adapter: jdbcpostgresql\n" : " adapter: postgresql\n"
file.write " username: postgres\n" if ENV['TRAVIS']
file.write <<-DATABASE
test:
<<: *common
database: rdb_test_#{version.gsub(/\W+/, '_')}
production:
<<: *common
database: rdb_#{version.gsub(/\W+/, '_')}
development:
<<: *common
database: rdb_dev_#{version.gsub(/\W+/, '_')}
DATABASE
end
exec 'cat', "#{path}/config/database.yml" if ENV['TRAVIS']
# symlink plugin
exec 'rm', "#{path}/plugins/redmine_dashboard" if File.exists? "#{path}/plugins/redmine_dashboard"
exec 'ln', '-s', BASE, "#{path}/plugins/"
# symlink assets for development mode
mkpath "#{path}/public/plugin_assets"
exec 'rm', "#{path}/public/plugin_assets/redmine_dashboard_linked" if File.exists? "#{path}/public/plugin_assets/redmine_dashboard_linked"
exec 'ln', '-s', "#{BASE}/assets", "#{path}/public/plugin_assets/redmine_dashboard_linked"
Rake::Task['redmine:update'].invoke
end
puts
end
end
task :update do
Dir.chdir path do
# modify redmine Gemfile
exec 'sed', '-i', '-e', "s/.*gem [\"']capybara[\"'].*//g", "#{path}/Gemfile"
# install dependencies
exec 'bundle', 'install', '--path', bundle_path
end
end
desc 'Setup and initialize redmine.'
task :setup => [ :install ] do
unless_done('setup', 1) do
Dir.chdir path do
bxrake 'generate_secret_token'
bxrake 'db:create:all'
bxrake 'db:migrate'
bxrake 'db:migrate', 'RAILS_ENV=test'
bxrake 'redmine:plugins:migrate'
bxrake 'redmine:load_default_data', 'REDMINE_LANG=en'
end
puts
end
end
task :download do
unless File.exists? "#{path}/Gemfile"
unless File.exists? archive_path
mkpath archives_path
Dir.chdir archives_path do
exec 'wget', "https://github.com/edavis10/redmine/archive/#{archive}"
end
end
if File.exists? archive_path
mkpath path
exec 'tar', '-C', path, '-xz', '--strip=1', '-f', archive_path
end
end
end
desc 'Remove installed redmine'
task :remove do
exec 'rm', '-rf', path
end
desc 'Run local redmine development server'
task :server => [ :setup ] do
Dir.chdir path do
bx 'rails', 'server'
end
puts
end
end