-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
142 lines (116 loc) · 3.55 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
# frozen_string_literal: true
REDMINE_URL = 'http://localhost:3000'
MAILHOG_URL = 'http://localhost:8025'
desc "SSH into a service. Defaults to 'redmine'."
task :ssh do
rails_env = ENV.fetch('RAILS_ENV', 'development')
service = ENV.fetch('SERVICE', 'redmine')
sh "docker compose exec -e RAILS_ENV=#{rails_env} #{service} bash"
end
desc 'Execute a Rails command'
task :rails do |_t, args|
sh "docker compose exec redmine rails #{args.extras.join(' ')}"
end
desc 'Launch MySQL'
task :mysql do |_t, args|
args.with_defaults(
user: 'root',
pass: 'root',
rails_env: ENV.fetch('RAILS_ENV', 'development')
)
sh "docker compose exec mysql mysql -u#{args.user} -p#{args.pass} redmine_#{args.rails_env}"
end
desc 'Reset the database.'
task :reset do
rails_env = ENV.fetch('RAILS_ENV') do
abort('Env var RAILS_ENV cannot be empty')
end
commands = [
'db:drop',
'db:create',
'db:migrate',
'redmine:plugins:migrate'
]
commands << 'db:seed' if rails_env == 'development'
# If all commands are sent at once, redmine:plugins:migrate fails.
# Hence, the commands are being sent separately.
commands.each do |command|
sh "docker compose exec -e RAILS_ENV=#{rails_env} redmine rake #{command}"
end
puts "The env '#{rails_env}' has been reset."
end
desc 'Provision the environment.'
task :provision do
puts 'Installing dev packages...'
sleep(2)
sh 'docker compose exec redmine bundle lock --add-platform x86-mingw32 x64-mingw32 x86-mswin32'
sh 'docker compose exec redmine bundle config set with "default dev test"'
sh 'docker compose exec redmine bundle install'
puts 'Preparing database...'
sleep(2)
sh 'docker compose exec redmine rake db:seed'
puts <<~RESULT
======
Redmine is ready!
======
RESULT
Rake::Task[:info].invoke
end
desc 'Dev env info.'
task :info do
puts <<~INFO
Sample time entries exist for john.doe on Nov 03, 2012.
USERS
----------------------------------------------------
Login | Email address | Password
----------------------------------------------------
admin | [email protected] | admin
jsmith | [email protected] | jsmith
----------------------------------------------------
URLS
----------------------------------------------------
Redmine | #{REDMINE_URL}/
Toggl 2 Redmine | #{REDMINE_URL}/toggl2redmine
Mailhog | #{MAILHOG_URL}/
----------------------------------------------------
INFO
end
desc 'Lint all code.'
task :lint do
Rake::Task['lint_ruby'].execute
Rake::Task['lint_javascript'].execute
end
desc 'Lint Ruby code.'
task :lint_ruby do
sh 'docker compose exec redmine rubocop -c plugins/toggl2redmine/.rubocop.yml plugins/toggl2redmine'
end
desc 'Lint JavaScript code.'
task :lint_javascript do
sh 'docker compose exec -w /app/assets.src/javascripts node npm run lint'
end
desc 'Test all code.'
task :test do
Rake::Task['test_ruby'].execute
Rake::Task['test_javascript'].execute
end
desc 'Test Ruby code.'
task :test_ruby do
file = ENV.fetch('TEST', nil)
type = ENV.fetch('TYPE', nil)
type = type ? ":#{type}" : nil
command =
if file
"test TEST=plugins/toggl2redmine/#{file}"
else
"redmine:plugins:test#{type} NAME=toggl2redmine"
end
sh "docker compose exec -e RAILS_ENV=test redmine rake #{command}"
end
desc 'Test JavaScript code.'
task :test_javascript do
sh 'docker compose exec -w /app/assets.src node npm run test'
end
desc 'Watch and compile CSS and JS assets.'
task :watch do
sh 'docker compose exec -w /app/assets.src node npm run watch'
end