capistrano-hook 0.3.4 → 0.4.0
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 +4 -4
- data/.rubocop.yml +5 -4
- data/.rubocop_todo.yml +7 -0
- data/.travis.yml +5 -4
- data/Capfile +2 -0
- data/bin/setup +4 -0
- data/capistrano-hook.gemspec +7 -2
- data/config/deploy.rb +1 -2
- data/config/deploy/{staging.rb → all.rb} +8 -19
- data/config/deploy/discord.rb +44 -0
- data/config/deploy/{production.rb → slack.rb} +1 -1
- data/lib/capistrano/hook/version.rb +1 -1
- data/lib/capistrano/hook/web.rb +29 -14
- data/lib/capistrano/tasks/webhook.rake +13 -7
- metadata +24 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99bc36d1c0f7464499165ef8406b0b28a13c58410c7c9f7aabd566c17550339a
|
4
|
+
data.tar.gz: a3f5b8ab947dada284400bbe0e09596ca3cb3b07649c8a5bceef9fad2845b4bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f242724c1176a34f71b0000456d4d813d62c63f7f67799bc02b4650f2e60d9dd4a358f0c376a585ae69f252b67372ed1a55b57c667c7d971b841ba698dac7021
|
7
|
+
data.tar.gz: 8addfb5040dbd8ecdefea9c25eb06fbf28b0d77172a0f02321f893633789c68ca0abb456d143822eb8948361d55ade6dbde990fd4c14d1c5bbfc27c25a3218ca
|
data/.rubocop.yml
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
1
3
|
Metrics/BlockLength:
|
2
|
-
Max:
|
4
|
+
Max: 100
|
3
5
|
|
4
6
|
Metrics/LineLength:
|
5
|
-
Max:
|
7
|
+
Max: 160
|
6
8
|
|
7
9
|
Style/Documentation:
|
8
10
|
Enabled: false
|
9
11
|
|
10
|
-
|
12
|
+
Layout/SpaceBeforeFirstArg:
|
11
13
|
Enabled: false
|
12
|
-
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2020-05-26 17:01:17 +0000 using RuboCop version 0.75.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
data/.travis.yml
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- 2.3.8
|
4
|
-
- 2.4.
|
5
|
-
- 2.5.
|
6
|
-
- 2.6.
|
7
|
-
|
4
|
+
- 2.4.10
|
5
|
+
- 2.5.8
|
6
|
+
- 2.6.6
|
7
|
+
- 2.7.1
|
8
|
+
before_install: gem install bundler -v 2.1.4
|
8
9
|
script:
|
9
10
|
- bundle exec rake
|
10
11
|
- bundle exec rubocop
|
data/Capfile
CHANGED
data/bin/setup
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
set -euo pipefail
|
3
3
|
IFS=$'\n\t'
|
4
4
|
|
5
|
+
VERSION=$(ruby -e "require './lib/capistrano/hook/version'; print Capistrano::Hook::VERSION")
|
6
|
+
|
5
7
|
bundle install
|
8
|
+
bundle exec rake build
|
9
|
+
gem install pkg/capistrano-hook-${VERSION}.gem
|
6
10
|
|
7
11
|
# Do any other automated setup that you need to do here
|
data/capistrano-hook.gemspec
CHANGED
@@ -15,7 +15,11 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.homepage = 'https://github.com/yulii/capistrano-hook'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
18
|
-
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
19
23
|
spec.bindir = 'exe'
|
20
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
25
|
spec.require_paths = ['lib']
|
@@ -25,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
25
29
|
spec.add_development_dependency 'bundler'
|
26
30
|
spec.add_development_dependency 'minitest'
|
27
31
|
spec.add_development_dependency 'minitest-reporters'
|
28
|
-
spec.add_development_dependency 'rake', '
|
32
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
29
33
|
spec.add_development_dependency 'rubocop'
|
34
|
+
spec.add_development_dependency 'webmock'
|
30
35
|
end
|
data/config/deploy.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# config valid only for current version of Capistrano
|
4
|
-
lock '3.4.0'
|
4
|
+
# lock '3.4.0'
|
5
5
|
|
6
6
|
set :application, 'capistrano-hook'
|
7
7
|
set :repo_url, 'git@github.com:yulii/capistrano-hook.git'
|
8
8
|
set :branch, :master
|
9
9
|
|
10
10
|
set :deploy_to, '/tmp'
|
11
|
-
set :scm, :git
|
12
11
|
set :format, :pretty
|
13
12
|
set :log_level, :debug
|
14
13
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
# server-based syntax
|
3
4
|
# ======================
|
4
5
|
# Defines a single server with a list of roles and multiple properties.
|
@@ -22,26 +23,14 @@
|
|
22
23
|
|
23
24
|
# Configuration
|
24
25
|
# =============
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
set :webhook_url, ENV.fetch('WEBHOOK_URL') { MOCK_URL[(ENV['STATUS_CODE'] || '200')] }
|
27
|
+
set :webhook_http_headers, 'Content-Type' => 'application/x-www-form-urlencoded'
|
28
|
+
set :webhook_starting_payload, params: '[production] Now, deploying...'
|
29
|
+
set :webhook_finished_payload, params: '[production] Deployment has been completed!'
|
30
|
+
set :webhook_failed_payload, params: '[production] Oops! something went wrong.'
|
31
|
+
set :webhook_reverting_payload, params: '[production] Reverting...'
|
32
|
+
set :webhook_rollbacked_payload, params: '[production] Rollback has been completed!'
|
30
33
|
|
31
|
-
# Custom SSH Options
|
32
|
-
# ==================
|
33
|
-
# You may pass any option but keep in mind that net/ssh understands a
|
34
|
-
# limited set of options, consult the Net::SSH documentation.
|
35
|
-
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
|
36
|
-
#
|
37
|
-
# Global options
|
38
|
-
# --------------
|
39
|
-
# set :ssh_options, {
|
40
|
-
# keys: %w(/home/rlisowski/.ssh/id_rsa),
|
41
|
-
# forward_agent: false,
|
42
|
-
# auth_methods: %w(password)
|
43
|
-
# }
|
44
|
-
#
|
45
34
|
# The server-based syntax can be used to override options:
|
46
35
|
# ------------------------------------
|
47
36
|
# server 'example.com',
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# server-based syntax
|
4
|
+
# ======================
|
5
|
+
# Defines a single server with a list of roles and multiple properties.
|
6
|
+
# You can define all roles on a single server, or split them:
|
7
|
+
|
8
|
+
# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
|
9
|
+
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
|
10
|
+
# server 'db.example.com', user: 'deploy', roles: %w{db}
|
11
|
+
|
12
|
+
# role-based syntax
|
13
|
+
# ==================
|
14
|
+
|
15
|
+
# Defines a role with one or multiple servers. The primary server in each
|
16
|
+
# group is considered to be the first unless any hosts have the primary
|
17
|
+
# property set. Specify the username and a domain or IP for the server.
|
18
|
+
# Don't use `:all`, it's a meta role.
|
19
|
+
|
20
|
+
# role :app, %w{deploy@example.com}, my_property: :my_value
|
21
|
+
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
|
22
|
+
# role :db, %w{deploy@example.com}
|
23
|
+
|
24
|
+
# Configuration
|
25
|
+
# =============
|
26
|
+
set :webhook_url, ENV.fetch('WEBHOOK_URL') { MOCK_URL[(ENV['STATUS_CODE'] || '200')] }
|
27
|
+
set :webhook_starting_payload, content: '[production] Now, deploying...'
|
28
|
+
set :webhook_finished_payload, content: '[production] Deployment has been completed!'
|
29
|
+
set :webhook_failed_payload, content: '[production] Oops! something went wrong.'
|
30
|
+
set :webhook_reverting_payload, content: '[production] Reverting...'
|
31
|
+
set :webhook_rollbacked_payload, content: '[production] Rollback has been completed!'
|
32
|
+
|
33
|
+
# The server-based syntax can be used to override options:
|
34
|
+
# ------------------------------------
|
35
|
+
# server 'example.com',
|
36
|
+
# user: 'user_name',
|
37
|
+
# roles: %w{web app},
|
38
|
+
# ssh_options: {
|
39
|
+
# user: 'user_name', # overrides user setting above
|
40
|
+
# keys: %w(/home/user_name/.ssh/id_rsa),
|
41
|
+
# forward_agent: false,
|
42
|
+
# auth_methods: %w(publickey password)
|
43
|
+
# # password: 'please use keys'
|
44
|
+
# }
|
@@ -23,7 +23,7 @@
|
|
23
23
|
|
24
24
|
# Configuration
|
25
25
|
# =============
|
26
|
-
set :webhook_url, MOCK_URL[(ENV['STATUS_CODE'] || '200')]
|
26
|
+
set :webhook_url, ENV.fetch('WEBHOOK_URL') { MOCK_URL[(ENV['STATUS_CODE'] || '200')] }
|
27
27
|
set :webhook_starting_payload, text: '[production] Now, deploying...'
|
28
28
|
set :webhook_finished_payload, text: '[production] Deployment has been completed!'
|
29
29
|
set :webhook_failed_payload, text: '[production] Oops! something went wrong.'
|
data/lib/capistrano/hook/web.rb
CHANGED
@@ -5,34 +5,49 @@ require 'net/http'
|
|
5
5
|
module Capistrano
|
6
6
|
module Hook
|
7
7
|
class Web
|
8
|
+
attr_reader :uri, :http, :request, :headers
|
8
9
|
private_class_method :new
|
9
10
|
|
10
|
-
def initialize(url)
|
11
|
-
@uri
|
12
|
-
@
|
13
|
-
|
11
|
+
def initialize(url, headers)
|
12
|
+
@uri = URI.parse(url).freeze
|
13
|
+
@headers = headers
|
14
|
+
initialize_http
|
15
|
+
initialize_request
|
14
16
|
end
|
15
17
|
|
16
18
|
def post(params)
|
17
|
-
# TODO: rescue / logger
|
18
19
|
http.start do
|
19
|
-
|
20
|
+
request.body = params.to_json
|
21
|
+
http.request(request)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
def
|
24
|
-
|
25
|
-
o.set_form_data(payload: params.to_json)
|
26
|
-
end
|
25
|
+
def self.client(url, headers = {})
|
26
|
+
new(url, headers.is_a?(Hash) ? headers : {})
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
private
|
30
|
+
|
31
|
+
def path
|
32
|
+
return '/' if uri.path.nil?
|
33
|
+
return '/' if uri.path.empty?
|
34
|
+
|
35
|
+
uri.path
|
31
36
|
end
|
32
37
|
|
33
|
-
|
38
|
+
def default_headers
|
39
|
+
{ 'Content-Type' => 'application/json' }
|
40
|
+
end
|
34
41
|
|
35
|
-
|
42
|
+
def initialize_http
|
43
|
+
@http = Net::HTTP.new(uri.host, uri.port)
|
44
|
+
http.use_ssl = uri.is_a?(URI::HTTPS)
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize_request
|
48
|
+
@request = Net::HTTP::Post.new(path)
|
49
|
+
request.initialize_http_header(default_headers.merge(headers))
|
50
|
+
end
|
36
51
|
end
|
37
52
|
end
|
38
53
|
end
|
@@ -12,11 +12,11 @@
|
|
12
12
|
# set :webhook_rollbacked_payload, { text: 'Rollback has been completed!' }
|
13
13
|
|
14
14
|
namespace :webhook do
|
15
|
-
def webhook(url, payload)
|
15
|
+
def webhook(url, payload, headers = {})
|
16
16
|
return if url.nil? || payload.nil? || payload.empty?
|
17
17
|
|
18
18
|
info "POST #{url} payload='#{payload}'"
|
19
|
-
result = Capistrano::Hook::Web.client(url).post(payload)
|
19
|
+
result = Capistrano::Hook::Web.client(url, headers).post(payload)
|
20
20
|
message = "HTTP #{result.code} #{result.message} body='#{result.body}'; "
|
21
21
|
if result.is_a?(Net::HTTPSuccess)
|
22
22
|
info message
|
@@ -30,6 +30,7 @@ namespace :webhook do
|
|
30
30
|
task :list do
|
31
31
|
run_locally do
|
32
32
|
keys = %i[webhook_url
|
33
|
+
webhook_http_headers
|
33
34
|
webhook_starting_payload
|
34
35
|
webhook_finished_payload
|
35
36
|
webhook_failed_payload
|
@@ -51,7 +52,8 @@ namespace :webhook do
|
|
51
52
|
run_locally do
|
52
53
|
url = fetch(:webhook_url)
|
53
54
|
payload = fetch(:webhook_starting_payload)
|
54
|
-
|
55
|
+
headers = fetch(:webhook_http_headers)
|
56
|
+
webhook(url, payload, headers)
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -60,7 +62,8 @@ namespace :webhook do
|
|
60
62
|
run_locally do
|
61
63
|
url = fetch(:webhook_url)
|
62
64
|
payload = fetch(:webhook_finished_payload)
|
63
|
-
|
65
|
+
headers = fetch(:webhook_http_headers)
|
66
|
+
webhook(url, payload, headers)
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
@@ -69,7 +72,8 @@ namespace :webhook do
|
|
69
72
|
run_locally do
|
70
73
|
url = fetch(:webhook_url)
|
71
74
|
payload = fetch(:webhook_failed_payload)
|
72
|
-
|
75
|
+
headers = fetch(:webhook_http_headers)
|
76
|
+
webhook(url, payload, headers)
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
@@ -78,7 +82,8 @@ namespace :webhook do
|
|
78
82
|
run_locally do
|
79
83
|
url = fetch(:webhook_url)
|
80
84
|
payload = fetch(:webhook_reverting_payload)
|
81
|
-
|
85
|
+
headers = fetch(:webhook_http_headers)
|
86
|
+
webhook(url, payload, headers)
|
82
87
|
end
|
83
88
|
end
|
84
89
|
|
@@ -87,7 +92,8 @@ namespace :webhook do
|
|
87
92
|
run_locally do
|
88
93
|
url = fetch(:webhook_url)
|
89
94
|
payload = fetch(:webhook_rollbacked_payload)
|
90
|
-
|
95
|
+
headers = fetch(:webhook_http_headers)
|
96
|
+
webhook(url, payload, headers)
|
91
97
|
end
|
92
98
|
end
|
93
99
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-hook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yulii
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 12.3.3
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 12.3.3
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Notification hooks include start, finish and fail of deployments.
|
98
112
|
email:
|
99
113
|
- yone.info@gmail.com
|
@@ -103,6 +117,7 @@ extra_rdoc_files: []
|
|
103
117
|
files:
|
104
118
|
- ".gitignore"
|
105
119
|
- ".rubocop.yml"
|
120
|
+
- ".rubocop_todo.yml"
|
106
121
|
- ".travis.yml"
|
107
122
|
- CODE_OF_CONDUCT.md
|
108
123
|
- Capfile
|
@@ -116,8 +131,9 @@ files:
|
|
116
131
|
- bin/test
|
117
132
|
- capistrano-hook.gemspec
|
118
133
|
- config/deploy.rb
|
119
|
-
- config/deploy/
|
120
|
-
- config/deploy/
|
134
|
+
- config/deploy/all.rb
|
135
|
+
- config/deploy/discord.rb
|
136
|
+
- config/deploy/slack.rb
|
121
137
|
- lib/capistrano/hook.rb
|
122
138
|
- lib/capistrano/hook/load.rb
|
123
139
|
- lib/capistrano/hook/version.rb
|