This repository has been archived by the owner on Mar 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathRakefile
executable file
·210 lines (179 loc) · 6.78 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/rake
#Needed for task desc rake/gem '= 0.9.2.2'
if defined? Rake::TaskManager.record_task_metadata
Rake::TaskManager.record_task_metadata = true
end
rootPath = Rake.application.original_dir
buildPath = 'data/build'
cachePath = 'data/cache'
logPath = 'data/log'
srcPath = 'module'
codeStyle = 'PSR2'
testPath = "module/%s/test"
coveragePath = 'coverage'
testableModules = %w(Dashboard)
defaultTestType = "unit"
behatPath = 'behat'
buildDirs = %w(api code-browser coverage/html coverage/clover logs pdepend behat)
def is_composer_installed
return system("composer --version > /dev/null 2>&1")
end
desc "Cleanup build artifacts"
task :clean do |task|
puts task.comment
FileUtils.rm_rf buildPath
FileUtils.rm_rf "#{cachePath}/**"
FileUtils.rm_rf "#{logPath}/**"
end
desc "Prepare for build"
task :prepare do |task|
puts task.comment
buildDirs.each do |dirName|
FileUtils.mkdir_p("#{buildPath}/#{dirName}")
end
end
desc "Prepare directories for deploy"
task :prepareDeploy do |task|
puts task.comment
unless File.directory? cachePath
FileUtils.mkdir_p cachePath
end
FileUtils.chmod 0777, cachePath
unless File.directory? logPath
FileUtils.mkdir_p logPath
end
FileUtils.chmod 0777, logPath
end
desc "Perform syntax check of sourcecode files"
task :lint do |task|
puts task.comment
system_check "find #{srcPath} -name '*.php' -exec php -l {} \\; | grep -v 'No syntax error' ; test $? -eq 1"
end
desc "Measure project size using PHPLOC"
task :phploc do |task|
puts task.comment
system_check "vendor/bin/phploc --log-csv #{buildPath}/logs/phploc.csv #{srcPath}"
end
desc "Calculate software metrics using PHP_Depend"
task :pdepend do |task|
puts task.comment
system_check "vendor/bin/pdepend --jdepend-xml=#{buildPath}/logs/jdepend.xml" +
" --jdepend-chart=#{buildPath}/pdepend/dependencies.svg" +
" --overview-pyramid=#{buildPath}/pdepend/overview-pyramid.svg" +
" #{srcPath}"
end
desc "Perform project mess detection using PHPMD and print human readable output. Intended for usage on the command line before committing."
task :phpmd do |task|
puts task.comment
system "vendor/bin/phpmd #{srcPath} text scripts/php/phpmd.xml"
end
desc "Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing."
task :phpcs do |task|
puts task.comment
system "vendor/bin/phpcs --standard=#{codeStyle} #{srcPath}"
end
desc "Find duplicate code using PHPCPD"
task :phpcpd do |task|
puts task.comment
system_check "vendor/bin/phpcpd #{srcPath}"
end
##### Composer #####
namespace :composer do
desc "Install composer's dependencies"
task :install, [:params] do |task, args|
puts task.comment
unless File.exist?('composer.phar')
system "curl -s http://getcomposer.org/installer | php -d \"apc.enable_cli=off\" "
end
system_check "php -d \"apc.enable_cli=off\" composer.phar self-update"
system_check "if [ -n \"$GITHUB_OAUTH_TOKEN\" ]; then php composer.phar config github-oauth.github.com $GITHUB_OAUTH_TOKEN; php -d \"apc.enable_cli=off\" composer.phar install #{args.params} --prefer-dist; else php -d \"apc.enable_cli=off\" composer.phar install #{args.params} --prefer-source; fi"
end
desc "Install composer's dependencies for development"
task :dev do |task|
puts task.comment
Rake::Task["composer:install"].invoke()
end
desc "Install composer's dependencies for production"
task :prod do |task|
puts task.comment
Rake::Task["composer:install"].invoke('--no-dev -o --prefer-dist')
end
end
desc "Install composer's dependencies"
task :composer, :env do |task, args|
env = args.env || "development"
if env == "production"
Rake::Task['composer:prod'].invoke
else
Rake::Task['composer:dev'].invoke
end
end
desc "Run tests on given type (unit|integration)"
task :test, [:testType] do |task, args|
puts task.comment
args.with_defaults :testType => defaultTestType
cloverPath = "#{buildPath}/#{coveragePath}/clover"
testableModules.each do |moduleName|
currentModulePath = sprintf testPath, moduleName
if (!File.exist?("./#{currentModulePath}/#{args.testType}/phpunit.xml"))
system "cp #{currentModulePath}/#{args.testType}/phpunit.xml-dist #{currentModulePath}/#{args.testType}/phpunit.xml"
end
testCaseName = "#{moduleName}Test"
coverageFullPath = "#{buildPath}/#{coveragePath}"
coverageCovFile = "#{buildPath}/#{coveragePath}/#{moduleName.downcase}.cov"
system_check "php vendor/bin/phpunit -c " +
" $PWD/#{currentModulePath}/#{args.testType}/phpunit.xml" +
" --coverage-clover $PWD/#{buildPath}/logs/clover-#{moduleName.downcase}.xml" +
" --coverage-php $PWD/#{coverageCovFile}" +
" --coverage-text" +
" $PWD/#{currentModulePath}/#{args.testType}/#{moduleName}Test/"
system <<END
php -d error_reporting=0 vendor/bin/phpcov merge --clover="#{buildPath}/logs/clover-stp.rtm.xml" #{coverageFullPath}
END
end
end
desc "Run Behat with given profile (default|ci)"
task :behat, [:profile] do |task, args|
puts task.comment
args.with_defaults :profile => "default"
behatPath = "#{buildPath}/#{behatPath}"
system_check "vendor/behat/behat/bin/behat --config config/behat.yml --profile #{args.profile}"
end
desc "Make copy of config/environment.config.php.dist and set env to given one (development testing staging production)"
task :setEnv, [:newEnv] do |task, args|
puts task.comment
system_check "cat config/environment.config.php.dist | sed -e 's/#APPLICATION_ENVIRONMENT#/#{args.newEnv}/g' > config/environment.config.php"
end
module Rake
class Application
attr_accessor :current_task
end
class Task
alias :old_execute :execute
def execute(args=nil)
Rake.application.current_task = @name
old_execute(args)
end
end
end
module Kernel
def system_check(args=nil)
system(args)
unless $?.success?
puts "Task #{Rake.application.current_task} failed"
exit!(1)
end
end
end
testType = ENV["testType"] || defaultTestType
task :ci => ["prepare","prepareDeploy","composer:dev","lint","phploc","pdepend","phpmd","phpcs","phpcpd"] do
Rake::Task["setEnv"].invoke("testing")
Rake::Task["test"].invoke(testType)
end
task :build => ["prepare","prepareDeploy","composer:prod"] do
Rake::Task["setEnv"].invoke("production")
end
task :herokubuild => ["prepare", "prepareDeploy"] do
Rake::Task["setEnv"].invoke("production")
end
task :default => ["build"]