elocal_capistrano 2.0.4 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adf35f9ea4139535dbf52045345ffc9dcaf5ee0a
4
- data.tar.gz: c3ac70191742d92b3c79745cecea241d0541ebe0
3
+ metadata.gz: 1cf236043f8dc14523bf9c83e5bc189cc22f4244
4
+ data.tar.gz: 56dde8b4563dcd0ac38f54548e5d8e0a811e7dbc
5
5
  SHA512:
6
- metadata.gz: c8b9249e4d869cc7f02484e1e8edc3217f21f7ad6dc03b8dc0e82dc32557a40c02dc07d790011344f675a76a2934e5cd470b9f53220151f128eb3b7b832f92c3
7
- data.tar.gz: cb1e259642a43361da679071b55565751da0733c8c0530645ef48e4470a3814d71d03f32e02b029f834174c830fe1ec7f9121f3070778f64185d3ff3a0c06b0f
6
+ metadata.gz: d1c633b20b23a409e4d09c035cfcd478b52b2016fbfb6ec278ad18e270bf4523f4e893ba45beb2f3ebf6a3b63fe889bd0f3f521bfba46d2846d61bff87f79e1b
7
+ data.tar.gz: 79b8123b1dfa58ab7d3d1ea017f88988783d7cf552b95d18ef739ceb5803be34a6f682cea9009224c3823f6eef22d5e6ad22fef9fbd3a1b88b3a66350d53186a
@@ -0,0 +1,92 @@
1
+ require 'yaml'
2
+
3
+ module ElocalCapistrano::GitTools
4
+ # Represents an API release, which is tagged in the repository as
5
+ # +rel_<MAJOR>.<MINOR>.<PATCH>+. Capistrano uses this pushed tag
6
+ # to deploy the next version of the API, which is reflected in the
7
+ # footer of each page. In development mode, this simply returns the
8
+ # latest commit in master.
9
+ class ReleaseTag
10
+ attr_accessor :major, :minor, :patch, :other
11
+
12
+ # Create a new ReleaseTag from a version string.
13
+ def initialize(tag=nil)
14
+ @major, @minor, @patch, @other = tag.gsub(/^rel_/,'').split(/[^0-9a-zA-Z]+/).map(&:to_i) unless tag.nil?
15
+ end
16
+
17
+ # Version number as an array of integers.
18
+ def to_a
19
+ [@major, @minor, @patch, @other].compact
20
+ end
21
+
22
+ # Compare two tags by version. The latest version is always chosen.
23
+ def <=>(rel_tag)
24
+ to_a <=> rel_tag.to_a
25
+ end
26
+
27
+ # Version number as a string, or tag name.
28
+ def to_s
29
+ "rel_" + to_a.compact.join(".")
30
+ end
31
+
32
+ def ==(rel_tag)
33
+ to_a == rel_tag.to_a
34
+ end
35
+
36
+ # Return the current ReleaseTag as specified in versions.yml.
37
+ def self.current(environment="production")
38
+ ReleaseTag.new(versions_hash[environment])
39
+ end
40
+
41
+ # Return the latest ReleaseTag as computed by looking at the most
42
+ # recent "rel_*" tag created on Git.
43
+ def self.latest
44
+ tags = %x(git tag).split("\n").select{|l| l =~ /^rel_/}.map{ |l| ReleaseTag.new(l) }.sort
45
+ tags.last || ReleaseTag.new('rel_0.0.0')
46
+ end
47
+ end
48
+
49
+ # A short user prompt if there are uncommitted changes in the repo, in
50
+ # case the user forgets before they deploy. Naturally, one may cancel
51
+ # this process effectively cancelling the entire deploy cleanly. This
52
+ # occurs before any hard changes (e.g., writing changes, pushes,
53
+ # command execution, etc.) are made.
54
+ def working_directory_copasetic?(options={})
55
+ return true if options[:force]
56
+ return false unless no_changes_pending? || yes?('There are currently uncommitted changes. Are you sure you want to continue?')
57
+ return false unless on_master? || yes?('You are not currently on the master branch. Are you sure you want to continue?')
58
+ true
59
+ end
60
+
61
+ # Test whether we are currently using the master branch. All
62
+ # deployment activity should take place on the master branch.
63
+ def on_master?
64
+ out = %x(git symbolic-ref -q HEAD)
65
+ out.strip == "refs/heads/master"
66
+ end
67
+
68
+ # Test whether there are any uncommitted changes in the working
69
+ # directory.
70
+ def no_changes_pending?
71
+ %x(git status --porcelain).split("\n").length == 0
72
+ end
73
+
74
+ def increment_patch_version
75
+ tag = ReleaseTag.latest
76
+ tag.patch += 1
77
+ tag
78
+ end
79
+
80
+ def versions_hash
81
+ YAML.load_file(fetch(:versions_path))
82
+ end
83
+
84
+ def update_versions_file(tag)
85
+ File.write(fetch(:versions_path), versions_hash.merge(fetch(:stage).to_s => tag.to_s).to_yaml.to_s)
86
+ end
87
+
88
+ def yes?(prompt_msg)
89
+ ask(:proceed, prompt_msg + ' [y/N]', default: 'y')
90
+ fetch(:proceed) == 'y'
91
+ end
92
+ end
@@ -1,3 +1,3 @@
1
1
  module ElocalCapistrano
2
- VERSION = '2.0.4'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -1,3 +1,6 @@
1
+ module ElocalCapistrano
2
+ end
3
+
1
4
  # Load any pertinent libraries
2
5
  Dir["#{File.expand_path('..', __FILE__)}/**/*.rb"].each { |path| require path }
3
6
 
@@ -0,0 +1,60 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :syslog_grep_pattern, ENV['pattern']
4
+ set :syslog_all_logs, %w(y Y yes true 1).include?(ENV['all_logs'])
5
+ end
6
+ end
7
+ namespace :git do
8
+ namespace :tagging do
9
+ include ElocalCapistrano::GitTools
10
+
11
+ desc <<-DESC
12
+ Make sure the working directory is clean and on right branch
13
+ DESC
14
+ task :check_local do
15
+ run_locally do
16
+ unless working_directory_copasetic?
17
+ error 'Cannot continue because working directory is not clean'
18
+ raise 'Working directory not clean'
19
+ end
20
+ end
21
+ end
22
+
23
+ desc <<-DESC
24
+ Create a new tag for current release and set current revision
25
+ DESC
26
+ task :tag_release do
27
+ run_locally do
28
+ tag = increment_patch_version
29
+ update_versions_file(tag)
30
+ execute :git, "commit -m '[RELEASE][#{fetch(:rails_env)}] Update release tag for #{fetch(:rails_env)} to #{tag}' #{fetch(:versions_path)}"
31
+ execute :git, 'push origin master'
32
+ execute :git, "tag #{tag}"
33
+ execute :git, "push origin #{tag}"
34
+ set :branch, tag.to_s
35
+ end
36
+ end
37
+
38
+ desc <<-DESC
39
+ Use previous staging tag for release
40
+ DESC
41
+ task :use_release do
42
+ run_locally do
43
+ tag = ReleaseTag.current('staging')
44
+ update_versions_file(tag)
45
+ execute :git, "commit -m '[RELEASE][#{fetch(:rails_env)}] Update release tag for #{fetch(:rails_env)} to #{tag}' #{fetch(:versions_path)}"
46
+ execute :git, 'push origin master'
47
+ set :branch, tag.to_s
48
+ end
49
+ end
50
+
51
+ desc <<-DESC
52
+ Prints out current environment release information
53
+ DESC
54
+ task :current_release do
55
+ run_locally do
56
+ puts "#{fetch(:stage)}: #{ReleaseTag.current(fetch(:stage).to_s)}"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,7 +1,6 @@
1
1
  namespace :load do
2
2
  task :defaults do
3
- set :syslog_grep_pattern, ENV['pattern']
4
- set :syslog_all_logs, %w(y Y yes true 1).include?(ENV['all_logs'])
3
+ set :versions_path, 'config/versions.yml'
5
4
  end
6
5
  end
7
6
 
@@ -0,0 +1,57 @@
1
+ namespace :deploy do
2
+ namespace :webpack do
3
+ def frontend_changed?
4
+ %x(git diff #{ReleaseTag.latest} #{fetch(:fronted_path)}).length > 0
5
+ end
6
+
7
+ desc <<-DESC
8
+ Check if a new frontend release is required and deploy to S3
9
+ DESC
10
+ task :release do
11
+ on roles(:all) do
12
+ if frontend_changed? || fetch(:force_webpack_release, false)
13
+ info '[deploy:webpack] Creating new webpack release'
14
+ invoke 'deploy:webpack:make_new_release'
15
+ else
16
+ info '[deploy:webpack] Skipping webpack release as no changes were detected in frontend directory'
17
+ end
18
+ end
19
+ end
20
+
21
+ desc <<-DESC
22
+ create new webpack bundle and release
23
+ DESC
24
+ task :make_new_release do
25
+ invoke 'deploy:webpack:install_dependencies'
26
+ invoke 'deploy:webpack:bundle'
27
+ invoke 'deploy:webpack:add_to_version_control'
28
+ end
29
+
30
+ desc <<-DESC
31
+ Installs required javascript packages from Node Package Manager
32
+ DESC
33
+ task :install_dependencies do
34
+ run_locally do
35
+ execute 'yarn install --pure-lockfile'
36
+ end
37
+ end
38
+
39
+ desc <<-DESC
40
+ Compiles webpack bundle and uploads to S3
41
+ DESC
42
+ task :bundle do
43
+ run_locally do
44
+ execute 'yarn run build'
45
+ end
46
+ end
47
+
48
+ desc <<-DESC
49
+ Check in updated webpack manifest and S3 paths to git
50
+ DESC
51
+ task :add_to_version_control do
52
+ run_locally do
53
+ execute "git commit -m '[FRONTEND] Updated webpack bundle' #{fetch(:webpack_manifest_file)}"
54
+ end
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elocal_capistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Di Marco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,12 +53,15 @@ files:
53
53
  - Rakefile
54
54
  - elocal_capistrano.gemspec
55
55
  - lib/elocal_capistrano.rb
56
+ - lib/elocal_capistrano/git_tools.rb
56
57
  - lib/elocal_capistrano/version.rb
57
58
  - lib/tasks/chef.rake
59
+ - lib/tasks/git_tagging.rake
58
60
  - lib/tasks/maintenance.rake
59
61
  - lib/tasks/ssh.rake
60
62
  - lib/tasks/syslog.rake
61
63
  - lib/tasks/upstart.rake
64
+ - lib/tasks/webpack.rake
62
65
  homepage: https://github.com/eLocal/elocal_capistrano
63
66
  licenses:
64
67
  - MIT
@@ -79,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
82
  version: '0'
80
83
  requirements: []
81
84
  rubyforge_project:
82
- rubygems_version: 2.4.8
85
+ rubygems_version: 2.5.2
83
86
  signing_key:
84
87
  specification_version: 4
85
88
  summary: Common eLocal Capistrano tasks