Top Level Namespace

Defined Under Namespace

Modules: Deplo

Instance Method Summary collapse

Instance Method Details

#set_cap_consts ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/deplo/set_cap_consts.rb', line 1

def set_cap_consts
  set :gem , fetch( :application ).to_s.gsub( /\Agem_/ , "" )
  set :latest_version_file , ::File.expand_path( "#{ fetch( :pj_dir ) }/.latest_version" )

  # Version of Gem

  dirname = [ fetch( :pj_dir ) , :lib , fetch( :gem ).gsub( /::/ , "_" ) ].map( &:to_s ).join( "/" )
  require "#{ dirname }/version.rb"

  namespace = fetch( :gem ).to_s.split( "::" ).map( &:camelize ).join( "::" )
  set :new_version , eval( "#{ namespace }::VERSION" )

  require "#{ ::File.dirname( __FILE__ ) }/version.rb"
end

#set_cap_namespace_gem ⇒ Object



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

      #-------- xxxx.gemspec


      ::Deplo.display_file_content_to_check(
        "#{ fetch( :gem ) }.gemspec" ,
        "spec.add_development_dependency \"capistrano\"" ,
        "spec.add_development_dependency \"deplo\", \">= #{ ::Deplo::VERSION }\""
      )

      #-------- lib/xxxx/version.rb



      ::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"
      )

      #-------- spec/xxxx_spec.rb


      ::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"
      )

      #-------- Capfile (1)


      ::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\'"
      )

      #-------- Capfile (2)


      ::Deplo.display_file_content_to_check(
        "Capfile" ,
        #

        "Rake::Task[:production].invoke" ,
        "invoke :production" ,
        "set_cap_tasks_from_deplo"
      )

      #-------- .gitignore


      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 )

      #-------- version.rb


      ::Deplo.display_file_content_to_check( "lib/#{ fetch( :gem ) }/version.rb" )

      #-------- config/deploy.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

#set_cap_namespace_git ⇒ Object



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
# File 'lib/deplo/git.rb', line 27

def set_cap_namespace_git

  namespace :git do

    desc 'add to git all files under this directory'
    task :add do
      ::Deplo.process "git:add" do
        system "git add -A ."
      end
    end

    desc 'commit to git'
    task commit: :add do
      ::Deplo.process "git:commit" do
        system "git commit -m \"#{ ::Deplo::TitleForGitCommit.set }\""
      end
    end

    desc 'commit to git (amend)'
    task :commit_amend do
      ::Deplo.process "git:commit_amend" do
        system "git commit --amend -m \"#{ ::Deplo::TitleForGitCommit.set }\""
      end
    end

    desc 'commit to git (for Gem install or release)'
    task commit_for_gem: :add do
      ::Deplo.process "git:commit_for_gem" do
        gem_v = fetch( :new_version )
        t = ::Deplo::TitleForGitCommit.set( gem_version: gem_v )
        system "git commit -m \"#{t}\""
      end
    end

  end

end

#set_cap_namespace_github ⇒ Object



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
# File 'lib/deplo/github.rb', line 19

def set_cap_namespace_github

  namespace :github do

    desc 'push to github'
    task :push do
      ::Deplo.process "github:push" do
        github_remote_name = fetch( :github_remote_name )
        branch_name = ::Deplo::BranchNameForGithub.set
        system "git push #{ github_remote_name } #{ branch_name }"
      end
    end

    desc 'pull from github'
    task :pull do
      ::Deplo.process "github:pull" do
        github_remote_name = fetch( :github_remote_name )
        branch_name = ::Deplo::BranchNameForGithub.set
        system "git push #{ github_remote_name } #{ branch_name }"
      end
    end

  end

end

#set_cap_tasks_from_deplo(cap_consts: true) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/deplo.rb', line 57

def set_cap_tasks_from_deplo( cap_consts: true )
  if cap_consts
    set_cap_consts
  end

  set_cap_namespace_git
  set_cap_namespace_github
  set_cap_namespace_gem
end