depl 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4eff59033859fce127ee93cf953d43e210b340a
4
- data.tar.gz: 9782ae13f49e5d3da1eb6a6c54f4db759fcb535e
3
+ metadata.gz: 15687a80e9ac8e4666c3ac6903173add2ba28096
4
+ data.tar.gz: bfe44d5ac3a5cd481166ff4baa7d5745fdb893da
5
5
  SHA512:
6
- metadata.gz: 4e596864ffcc42fb63728175e2f1d1021ecbfc8c83934590d890fe7a11bc9334c9fd20903419225001dcb45af54d6a22c8e88cba6e959af481246811e40ff712
7
- data.tar.gz: 51d1ff3eb63e8391b482ca787c97f5aa02ab8b42b7a92c061f15e11e9da0174a0b292e7ad498a077d98e9c78d5d19ed4fc90bea09cdefd6d8dcb3afb31d030ab
6
+ metadata.gz: 5997fee34089fab8c49049b9a5aad8907821e9539df276c42d45971cd68bccf54ee88d529a54631dfb1125e6f97223ca5fc3bbc8f13f4cf50151ad3b76894df5
7
+ data.tar.gz: 8e45fee13a66726ae29438e49c15a14712ffd5b4e11e990f728990d7fe37cc4a2b359b71452f75f800399cdbfe8ca153452843c28daad5628f632e604e10e2a6
data/bin/depl CHANGED
@@ -69,7 +69,7 @@ end
69
69
 
70
70
  deploy = Depl::Main.new(options)
71
71
 
72
- if deploy.up_to_date
72
+ if deploy.up_to_date?
73
73
  output "Everything up-to-date (#{deploy.environment.green}: #{deploy.remote_sha.green})"
74
74
  exit 0
75
75
  end
@@ -23,12 +23,25 @@ module Depl
23
23
  @config[:prefix] || "deploy-"
24
24
  end
25
25
 
26
+ def origin
27
+ @config[:origin] || "origin"
28
+ end
29
+
26
30
  def deploy_branch
27
- "#{prefix}#{environment}"
31
+ [prefix, environment].join('')
32
+ end
33
+
34
+ def tag_name
35
+ date = Time.now.strftime('%Y-%m-%d-%H-%M-%S')
36
+ [prefix, environment, '-', date].join('')
37
+ end
38
+
39
+ def tag_release
40
+ execute("git tag -a '#{tag_name}' #{local_sha}")
28
41
  end
29
42
 
30
- def save_sha
31
- execute("git push --force origin #{local_sha}:refs/heads/#{deploy_branch}")
43
+ def advance_branch_pointer
44
+ execute("git push --follow-tags --force #{origin} #{local_sha}:refs/heads/#{deploy_branch}")
32
45
  end
33
46
 
34
47
  def run!
@@ -36,7 +49,8 @@ module Depl
36
49
  `#{@config['before_hook']}`
37
50
  end
38
51
 
39
- save_sha
52
+ tag_release
53
+ advance_branch_pointer
40
54
 
41
55
  if @config['after_hook']
42
56
  `#{@config['after_hook']}`
@@ -44,32 +58,32 @@ module Depl
44
58
  end
45
59
 
46
60
  def remote_sha
47
- `git fetch origin`
48
- sha = execute("git rev-parse -q --verify origin/#{deploy_branch}").chomp
49
- sha if sha != ""
61
+ `git fetch #{origin}`
62
+ sha = execute("git rev-parse -q --verify #{origin}/#{deploy_branch}")
63
+ sha && sha.chomp || raise("missing remote sha for #{origin}/#{deploy_branch}")
50
64
  end
51
65
 
52
- def up_to_date
66
+ def up_to_date?
53
67
  local_sha == remote_sha
54
68
  end
55
69
 
56
70
  def local_sha
57
71
  rev = @options[:rev] || @config[:branch] || 'head'
58
- sha = execute("git rev-parse -q --verify #{rev}").chomp
59
- sha if sha != ""
72
+ sha = execute("git rev-parse -q --verify #{rev}")
73
+ sha && sha.chomp || raise("missing local sha: #{rev}")
60
74
  end
61
75
 
62
76
  def diff
63
- execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' -10 #{remote_sha}..#{local_sha}"
77
+ execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' #{remote_sha}..#{local_sha}"
64
78
  end
65
79
 
66
80
  def reverse_diff
67
- execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' -10 #{local_sha}..#{remote_sha}"
81
+ execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' #{local_sha}..#{remote_sha}"
68
82
  end
69
83
 
70
84
  def older_local_sha
71
85
  return false unless remote_sha
72
- execute("git merge-base --is-ancestor #{local_sha} #{remote_sha}") && $?.exitstatus == 0
86
+ !!execute("git merge-base --is-ancestor #{local_sha} #{remote_sha}")
73
87
  end
74
88
 
75
89
  def commit_count
@@ -79,7 +93,8 @@ module Depl
79
93
  protected
80
94
 
81
95
  def execute(cmd)
82
- `#{cmd}`
96
+ output = `#{cmd}`
97
+ $?.exitstatus == 0 && output
83
98
  end
84
99
  end
85
100
  end
@@ -1,3 +1,3 @@
1
1
  module Depl
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -13,38 +13,40 @@ describe Depl::Main do
13
13
 
14
14
  describe '#diff' do
15
15
  it 'uses git to find the commits between two shas' do
16
- deploy.should_receive(:remote_sha).and_return("remote")
17
- deploy.should_receive(:local_sha).and_return("local")
16
+ expect(deploy).to receive(:remote_sha).and_return("remote")
17
+ expect(deploy).to receive(:local_sha).and_return("local")
18
18
 
19
- cmd = "git log --pretty=format:' %h %<(20)%an %ar\t %s' -10 remote..local"
20
- deploy.should_receive(:execute).with(cmd)
19
+ cmd = "git log --pretty=format:' %h %<(20)%an %ar\t %s' remote..local"
20
+ expect(deploy).to receive(:execute).with(cmd)
21
21
 
22
22
  deploy.diff
23
23
  end
24
24
  end
25
25
 
26
- describe '#save_sha' do
26
+ describe '#advance_branch_pointer' do
27
27
  it 'pushes a sha to the origin' do
28
- deploy.should_receive(:local_sha).and_return("12345")
28
+ expect(deploy).to receive(:local_sha).and_return("12345")
29
29
 
30
- cmd = "git push --force origin 12345:refs/heads/deploy-production"
31
- deploy.should_receive(:execute).with(cmd)
30
+ cmd = "git push --follow-tags --force origin 12345:refs/heads/deploy-production"
31
+ expect(deploy).to receive(:execute).with(cmd)
32
32
 
33
- deploy.save_sha
33
+ deploy.advance_branch_pointer
34
34
  end
35
35
  end
36
36
 
37
37
  describe '#up_to_date' do
38
38
  it 'returns true when shas match' do
39
- deploy.should_receive(:remote_sha).and_return("same")
40
- deploy.should_receive(:local_sha).and_return("same")
41
- expect(deploy.up_to_date).to be_true
39
+ expect(deploy).to receive(:remote_sha).and_return("same")
40
+ expect(deploy).to receive(:local_sha).and_return("same")
41
+
42
+ expect(deploy.up_to_date?).to be true
42
43
  end
43
44
 
44
45
  it 'returns true when shas differ' do
45
- deploy.should_receive(:remote_sha).and_return("remote")
46
- deploy.should_receive(:local_sha).and_return("local")
47
- expect(deploy.up_to_date).to be_false
46
+ expect(deploy).to receive(:remote_sha).and_return("remote")
47
+ expect(deploy).to receive(:local_sha).and_return("local")
48
+
49
+ expect(deploy.up_to_date?).to be false
48
50
  end
49
51
  end
50
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: depl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Nutt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-15 00:00:00.000000000 Z
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.4.8
98
+ rubygems_version: 2.6.8
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Writes project deployment hash to s3 file