deployment_notifications 0.1.3
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 +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +8 -0
- data/deployment_notifications.gemspec +35 -0
- data/lib/deployment_notifications/deployment_messaging.rb +104 -0
- data/lib/deployment_notifications/notifier.rb +15 -0
- data/lib/deployment_notifications/railtie.rb +33 -0
- data/lib/deployment_notifications/version.rb +5 -0
- data/lib/deployment_notifications.rb +20 -0
- data/sig/deployment_notifications.rbs +4 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 013e2cecba81f4ff7924bd0db65c34c424f5c1f50fc04fc48c704545e8b074a9
|
4
|
+
data.tar.gz: cc6912e19c46650a2af53daee5080555b7b5d291f4e226a8e2e67c9ea289aed5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f2010f36cf93f274c067df44a033074ea873f9c1ef8fcd0104fe3987757c3b429626aae3a397ce10883fd4ff64759843915ee17db1081776739ce93090568da
|
7
|
+
data.tar.gz: c75147606b336cc27b6bb694af7688d229f173d02fddef75649f35ef91dcf40ec73339b12982ca35492fb6dc8cfea48d57d0d643f0d49cab6f1c416f8a3f817c
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Ashish Garg
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# DeploymentNotifications
|
2
|
+
|
3
|
+
`DeploymentNotifications` is a gem that integrates with Capistrano and Slackistrano to provide custom deployment messages to your Slack channel. This gem simplifies the setup process by automatically configuring the necessary settings.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'deployment_notifications', path: '/path/to/your/local/gem'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
### Step 1: Configure the Gem in an Initializer
|
22
|
+
Create a new initializer file in your Rails application, e.g., config/initializers/deployment_notifications.rb, and configure it as follows:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
DeploymentNotifications.configure do |config|
|
26
|
+
config.channel = '#your-slack-channel'
|
27
|
+
config.webhook = 'https://hooks.slack.com/services/YOUR/WEBHOOK/URL'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
### Step 2: Capfile Modifications
|
32
|
+
The gem automatically adds the necessary require 'slackistrano/capistrano' line to your Capfile. If you need to verify or manually add it, your Capfile should include:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'slackistrano/capistrano'
|
36
|
+
```
|
37
|
+
|
38
|
+
### Step 3: Deployment Configuration
|
39
|
+
Ensure that your Capistrano deploy configuration is set up correctly. The gem will automatically set the Slackistrano configuration based on the provided initializer settings.
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
Once configured, you can deploy your application using Capistrano as usual:
|
43
|
+
|
44
|
+
```bash
|
45
|
+
cap production deploy
|
46
|
+
```
|
47
|
+
|
48
|
+
Deployment notifications will be sent to your specified Slack channel using the custom messaging format defined in the DeploymentNotifications gem.
|
49
|
+
|
50
|
+
## Custom Messaging
|
51
|
+
The gem provides a custom messaging format for deployment notifications. It sends detailed deployment information at the start, success, and failure stages of your deployment process.
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/your-username/deployment_notifications.
|
55
|
+
|
56
|
+
## License
|
57
|
+
The gem is available as open-source under the terms of the MIT License.
|
58
|
+
|
59
|
+
Make sure to replace `'/path/to/your/local/gem'` with the actual path to your gem and update the GitHub repository URL to your actual repository.
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/deployment_notifications/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'deployment_notifications'
|
7
|
+
spec.version = DeploymentNotifications::VERSION
|
8
|
+
spec.authors = ['Ashish Garg']
|
9
|
+
spec.email = '01ashishgarg@gmail.com'
|
10
|
+
|
11
|
+
spec.summary = 'Deliver deployment notifications to Slack'
|
12
|
+
spec.description = 'Deliver Capistrano deployment notifications to Slack'
|
13
|
+
spec.homepage = 'https://github.com/aashishgarg/deployment_notifications'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = '>= 2.6.0'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/aashishgarg/deployment_notifications'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/aashishgarg/deployment_notifications/blob/main/CHANGELOG.md'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(File.expand_path(f) == __FILE__) ||
|
25
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
# Specify the dependencies of the gem
|
34
|
+
spec.add_dependency 'slackistrano'
|
35
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
if defined?(Slackistrano::Messaging)
|
2
|
+
module Slackistrano
|
3
|
+
class DeploymentMessaging < Messaging::Base
|
4
|
+
|
5
|
+
def info_item(item, value)
|
6
|
+
"• #{item} - _*#{value.to_s.gsub("\n", '')}*_"
|
7
|
+
end
|
8
|
+
|
9
|
+
def info_list(items)
|
10
|
+
items.join(" \n ")
|
11
|
+
end
|
12
|
+
|
13
|
+
def payload_for_starting
|
14
|
+
deployer_name = ENV['DEPLOYER_NAME'] || `git log -n 1 --format='%ae'`
|
15
|
+
|
16
|
+
if ENV['DEPLOYMENT_IDENTIFIER']
|
17
|
+
deployment_identifier = ENV['DEPLOYMENT_IDENTIFIER']
|
18
|
+
else
|
19
|
+
deployment_identifier = Time.now.strftime("%Y%m%d_%H%M%S")
|
20
|
+
ENV['DEPLOYMENT_IDENTIFIER'] = deployment_identifier
|
21
|
+
end
|
22
|
+
|
23
|
+
{
|
24
|
+
"blocks": [
|
25
|
+
{
|
26
|
+
"type": 'section',
|
27
|
+
"text": {
|
28
|
+
"type": 'mrkdwn',
|
29
|
+
"text": 'Deployment _*Started*_ for _*Eportfolio*_ application :wave:'
|
30
|
+
}
|
31
|
+
},
|
32
|
+
{ "type": 'divider' },
|
33
|
+
{
|
34
|
+
"type": 'section',
|
35
|
+
"text": {
|
36
|
+
"type": 'mrkdwn',
|
37
|
+
"text": '_Information related to this deployment_:'
|
38
|
+
}
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"type": 'section',
|
42
|
+
"text": {
|
43
|
+
"type": 'mrkdwn',
|
44
|
+
"text": info_list([
|
45
|
+
info_item('Deployer name', deployer_name),
|
46
|
+
info_item('Deployment identifier', deployment_identifier),
|
47
|
+
info_item('Env', ENV['ENV_NAME'] || stage),
|
48
|
+
info_item('Branch', ENV['BRANCH_NAME'] || branch),
|
49
|
+
info_item('Last commit by', ENV['LAST_COMMIT_AUTHOR'] || `git log -n 1 --format='%ae'`),
|
50
|
+
info_item('Commit time', ENV['LAST_COMMIT_TIME'] || `git show -s --format=%cd`),
|
51
|
+
info_item('Commit id', ENV['LAST_COMMIT_ID'] || `git rev-parse --short HEAD`),
|
52
|
+
info_item('Commit message', ENV['LAST_COMMIT_MESSAGE'] || `git show -s --format=%s`)
|
53
|
+
])
|
54
|
+
}
|
55
|
+
}
|
56
|
+
]
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
# Suppress updating message.
|
61
|
+
def payload_for_updating
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
|
65
|
+
# Fancy updated message.
|
66
|
+
# See https://api.slack.com/docs/message-attachments
|
67
|
+
def payload_for_updated
|
68
|
+
{
|
69
|
+
attachments: [{
|
70
|
+
color: 'good',
|
71
|
+
title: "#{application} Deployed :boom::bangbang:",
|
72
|
+
fields: [{
|
73
|
+
title: 'Deployment Identifier',
|
74
|
+
value: ENV['DEPLOYMENT_IDENTIFIER'],
|
75
|
+
short: true
|
76
|
+
},{
|
77
|
+
title: 'Environment',
|
78
|
+
value: stage,
|
79
|
+
short: true
|
80
|
+
}, {
|
81
|
+
title: 'Branch',
|
82
|
+
value: branch,
|
83
|
+
short: true
|
84
|
+
}, {
|
85
|
+
title: 'Time',
|
86
|
+
value: elapsed_time,
|
87
|
+
short: true
|
88
|
+
}],
|
89
|
+
fallback: super[:text]
|
90
|
+
}],
|
91
|
+
text: "<!here> #{application} Application Deployed!"
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
# Slightly tweaked failed message.
|
96
|
+
# See https://api.slack.com/docs/message-formatting
|
97
|
+
def payload_for_failed
|
98
|
+
payload = super
|
99
|
+
payload[:text] = "OMG :fire: #{payload[:text]}"
|
100
|
+
payload
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'slackistrano'
|
2
|
+
require 'deployment_notifications/deployment_messaging'
|
3
|
+
|
4
|
+
module DeploymentNotifications
|
5
|
+
class Notifier
|
6
|
+
def self.setup_slackistrano
|
7
|
+
Slackistrano.configure do |config|
|
8
|
+
config.channel = DeploymentNotifier.channel
|
9
|
+
config.webhook = DeploymentNotifier.webhook
|
10
|
+
|
11
|
+
config.messaging = Slackistrano::DeploymentMessaging
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
require 'deployment_notifications/notifier'
|
3
|
+
|
4
|
+
module DeploymentNotifications
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer 'deployment_notifier.add_to_capfile' do
|
8
|
+
capfile_path = Rails.root.join('Capfile')
|
9
|
+
if File.exist?(capfile_path)
|
10
|
+
content = File.read(capfile_path)
|
11
|
+
unless content.include?("require 'slackistrano/capistrano'")
|
12
|
+
File.open(capfile_path, 'a') do |file|
|
13
|
+
file.puts("\nrequire 'slackistrano/capistrano'\n")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
initializer 'deployment_notifications.configure_capistrano' do |app|
|
20
|
+
# Automatically configure Capistrano settings
|
21
|
+
if defined?(Capistrano::Configuration)
|
22
|
+
Capistrano::Configuration.instance.load do
|
23
|
+
set :slackistrano, {
|
24
|
+
channel: DeploymentNotifications.channel,
|
25
|
+
webhook: DeploymentNotifications.webhook,
|
26
|
+
klass: Slackistrano::DeploymentMessaging
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'slackistrano'
|
4
|
+
require_relative "deployment_notifications/railtie"
|
5
|
+
require_relative "deployment_notifications/version"
|
6
|
+
|
7
|
+
module DeploymentNotifications
|
8
|
+
class << self
|
9
|
+
attr_accessor :channel, :webhook
|
10
|
+
|
11
|
+
def configure
|
12
|
+
yield self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Notifier; end
|
17
|
+
|
18
|
+
class Error < StandardError; end
|
19
|
+
# Your code goes here...
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deployment_notifications
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ashish Garg
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slackistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Deliver Capistrano deployment notifications to Slack
|
28
|
+
email: 01ashishgarg@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".rspec"
|
34
|
+
- CHANGELOG.md
|
35
|
+
- LICENSE.txt
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- deployment_notifications.gemspec
|
39
|
+
- lib/deployment_notifications.rb
|
40
|
+
- lib/deployment_notifications/deployment_messaging.rb
|
41
|
+
- lib/deployment_notifications/notifier.rb
|
42
|
+
- lib/deployment_notifications/railtie.rb
|
43
|
+
- lib/deployment_notifications/version.rb
|
44
|
+
- sig/deployment_notifications.rbs
|
45
|
+
homepage: https://github.com/aashishgarg/deployment_notifications
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata:
|
49
|
+
homepage_uri: https://github.com/aashishgarg/deployment_notifications
|
50
|
+
source_code_uri: https://github.com/aashishgarg/deployment_notifications
|
51
|
+
changelog_uri: https://github.com/aashishgarg/deployment_notifications/blob/main/CHANGELOG.md
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.6.0
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.1.2
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Deliver deployment notifications to Slack
|
71
|
+
test_files: []
|