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
|
# File 'lib/deplo/gem.rb', line 1
def set_cap_namespace_gem
namespace :gem do
desc "Gem - Test"
task :test do
::Deplo.process "gem:test" do
system( "rake spec" )
end
end
desc "Gem - Rake install"
task :rake_install_locally do
::Deplo.process "gem:rake_install_locally" do
system( "rake install" )
end
end
desc "Gem - Update name of latest version"
task :update do
::Deplo.process "gem:update" do
latest_version_file = fetch( :latest_version_file )
::File.open( latest_version_file , "w:utf-8" ) do |f|
f.print fetch( :new_version )
end
end
end
desc "Install Gem #{ fetch( :new_version ) }"
task install_locally: :test do
::Deplo.process "gem:install_locally" do
::Deplo.yes_no( yes: ::Proc.new {
::Rake::Task[ "git:commit_for_gem" ].invoke
::Rake::Task[ "github:push" ].invoke
::Rake::Task[ "gem:rake_install_locally" ].invoke
} )
end
end
desc "Release Gem #{ fetch( :new_version ) }"
task release_to_public: :install_locally do
if ::File.exist?( fetch( :latest_version_file ) )
old_version = open( fetch( :latest_version_file ) , "r:utf-8" ).read
else
old_version = nil
end
::Deplo.process "gem:release_to_public" do
::Deplo.yes_no( message: "Release Gem #{ fetch( :new_version ) }" , yes: ::Proc.new {
::Rake::Task[ "gem:update" ].invoke
system( "rake release" )
})
end
unless old_version.nil?
::Deplo.process "gem:yank_old_version" do
::Deplo.yes_no( message: "Yank Old Gem #{ old_version }" , yes: ::Proc.new {
system( "gem yank #{ fetch( :gem ) } -v #{ old_version }" )
})
end
end
end
desc "Files to check"
task :files_to_check do
::Deplo.display_file_content_to_check(
"#{ fetch( :gem ) }.gemspec" ,
"spec.add_development_dependency \"capistrano\"" ,
"spec.add_development_dependency \"deplo\", \">= #{ ::Deplo::VERSION }\""
)
::Deplo.display_file_content_to_check(
"lib/#{ fetch( :gem ) }/version.rb" ,
"module #{ fetch( :gem ).capitalize }" ,
" VERSION = ::File.open( \"\#\{ ::File.dirname( __FILE__ ) \}/../../.current_version\" , \"r:utf-8\" ).read.chomp" ,
"end"
)
::Deplo.display_file_content_to_check(
"spec/#{ fetch( :gem ) }_spec.rb" ,
"require \'spec_helper\'" ,
"require \'deplo\'" ,
"" ,
"spec_filename = ::File.expand_path( ::File.dirname( __FILE__ ) )" ,
"version = ::File.open( \"\#\{ ::File.dirname( __FILE__ ) \}/..\/.current_version\" , \"r:utf-8\" ).read.chomp" ,
"" ,
"describe #{ fetch( :gem ).camelize } do" ,
" it \"has a version number \\\'\#\{ version \}\\\'\" do" ,
" expect( ::Deplo.version_check( ::#{ fetch( :gem ).camelize }::VERSION , spec_filename ) ).to eq( true )" ,
" end"
)
::Deplo.display_file_content_to_check(
"Capfile" ,
"\# Load DSL and set up stages" ,
"require \'capistrano/setup\'" ,
"" ,
"\# Include default deployment tasks" ,
"require \'capistrano/deploy\'" ,
"" ,
"require \'deplo\'"
)
::Deplo.display_file_content_to_check(
"Capfile" ,
"Rake::Task[:production].invoke" ,
"invoke :production" ,
"set_cap_tasks_from_deplo"
)
gitignore_filename = ::File.expand_path( "#{ fetch( :pj_dir ) }/.gitignore" )
latest_version_setting_in_gitignore = "/.latest_version"
::Deplo.display_file_content_to_check(
".gitignore" ,
latest_version_setting_in_gitignore
)
::Deplo.file_inclusion_check( gitignore_filename , latest_version_setting_in_gitignore , addition: true )
::Deplo.display_file_content_to_check( "lib/#{ fetch( :gem ) }/version.rb" )
::Deplo.display_file_content_to_check( "config/deploy.rb" )
in_file = ::File.open( "#{ fetch( :pj_dir ) }/config/deploy.rb" ).read.split( /\n/ )
regexps = [
/\Aset \:application/ ,
/\Aset \:repo_url/ ,
/\Aset \:pj_dir/ ,
/\Aset \:github_remote_name/ ,
/\Aset \:deploy_to ?, \'\/\'/
]
condition = regexps.all? { | regexp |
included_in_file = in_file.any? { | row | regexp === row }
unless included_in_file
puts "No row matched with #{ regexp.to_s }"
end
included_in_file
}
puts ""
if condition
puts "*** All Capistrano constants are set. (maybe each constant itself is not valid)"
else
puts "[!] Some Capistrano constants are not set."
end
end
end
end
|