capistrano-slacky 0.1.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -2
- data/README.md +113 -3
- data/lib/capistrano/slacky/block/context.rb +3 -3
- data/lib/capistrano/slacky/block/header.rb +1 -1
- data/lib/capistrano/slacky/block/root.rb +2 -2
- data/lib/capistrano/slacky/block/section.rb +3 -3
- data/lib/capistrano/slacky/command/current_revision.rb +23 -0
- data/lib/capistrano/slacky/command/diff.rb +16 -7
- data/lib/capistrano/slacky/command/duration.rb +1 -1
- data/lib/capistrano/slacky/command.rb +1 -0
- data/lib/capistrano/slacky/configuration.rb +3 -3
- data/lib/capistrano/slacky/facade/body.rb +3 -3
- data/lib/capistrano/slacky/facade/changelog.rb +9 -13
- data/lib/capistrano/slacky/facade/deployed_by.rb +1 -1
- data/lib/capistrano/slacky/facade/exception.rb +1 -1
- data/lib/capistrano/slacky/facade/header.rb +1 -1
- data/lib/capistrano/slacky/facade/revision.rb +4 -3
- data/lib/capistrano/slacky/fanout.rb +3 -7
- data/lib/capistrano/slacky/messaging/default.rb +9 -3
- data/lib/capistrano/slacky/messaging.rb +1 -1
- data/lib/capistrano/slacky/on.rb +29 -0
- data/lib/capistrano/slacky/payload.rb +2 -0
- data/lib/capistrano/slacky/runner.rb +1 -1
- data/lib/capistrano/slacky/version.rb +1 -1
- data/lib/capistrano/slacky.rb +8 -11
- data/lib/tasks/defaults.rake +7 -0
- data/lib/tasks/hooks.rake +5 -0
- data/lib/tasks/slacky.rake +15 -24
- metadata +14 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e963a3083a780ee771dd59f8a8f393152d5229506f9b2b8caa882ca3d2d69fab
|
4
|
+
data.tar.gz: e47195e93a85ed5dd1ccf2e46fca45c5e8f7f4ccd9eafc59abe95fb42115a441
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caad10775d254c7d44b0b919fed9fc4edd5899890ca4722e22b936daf0702ac885f86cff6994f69d08b9c36fbec15bd0da26cd3e47a057cacffed3dc796058d2
|
7
|
+
data.tar.gz: 35e4cc8a48f1fbe90f34ea563a74c83e29243f991bb3ca19b45778aa63177e5840ebe3850552c8ce0ccd9f284b78c0de40cde3cb4d5e0436edebb711c9c09a79
|
data/CHANGELOG.md
CHANGED
@@ -6,15 +6,53 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.1.5] - 2021-11-11
|
10
|
+
### Fixed
|
11
|
+
- Add fall back in case of the primary server is not defined. ([@chubchenko][])
|
12
|
+
- Require `json` to convert `Hash` object to `JSON`. ([@chubchenko][])
|
13
|
+
|
14
|
+
## [0.1.4] - 2021-07-27
|
15
|
+
### Fixed
|
16
|
+
- Ensure that `:current_revision` exists during rollback. ([@chubchenko][])
|
17
|
+
|
18
|
+
## [0.1.3] - 2021-06-14
|
19
|
+
### Changed
|
20
|
+
- Update `README.md`. ([@chubchenko][])
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
- Change commit message encoding to `UTF-8`. ([@chubchenko][])
|
24
|
+
|
25
|
+
## [0.1.2] - 2021-06-03
|
26
|
+
### Changed
|
27
|
+
- Use `I18n.t` instead of `t`. ([@chubchenko][])
|
28
|
+
- Use `forwardable` instead of `method_missing` + `respond_to_missing?`. ([@chubchenko][])
|
29
|
+
- Use the `On` module to interact with the remote server. ([@chubchenko][])
|
30
|
+
- Extracted hooks and defaults from `slacky.rake` into separate files. ([@chubchenko][])
|
31
|
+
- Renamed `#to_json` to `#as_json`. ([@chubchenko][])
|
32
|
+
- Updated hooks from `before` to `after`. ([@chubchenko][])
|
33
|
+
- Added 💯 test coverage. ([@chubchenko][])
|
34
|
+
|
35
|
+
### Fixed
|
36
|
+
- Use `@env` instance variable instead of missing getter `env`. ([@chubchenko][])
|
37
|
+
- Update your SSH regex to match the repository with a dash in the name. ([@chubchenko][])
|
38
|
+
- Use `SSHKit::Backend.current.capture` instead of `IO.popen` to perform `git log ..` on the remote server. ([@chubchenko][])
|
39
|
+
|
40
|
+
### Security
|
41
|
+
- Fix possible command injection during the duration retrieval. ([@chubchenko][])
|
42
|
+
|
9
43
|
## [0.1.1] - 2021-05-27
|
10
44
|
### Fixed
|
11
|
-
- Fix a bug related to using a `Null` messaging
|
45
|
+
- Fix a bug related to using a `Null` messaging. ([@chubchenko][])
|
12
46
|
|
13
47
|
## [0.1.0] - 2021-05-26
|
14
48
|
### Added
|
15
49
|
- Initial version. ([@chubchenko][])
|
16
50
|
|
17
51
|
[@chubchenko]: https://github.com/chubchenko
|
18
|
-
[Unreleased]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.
|
52
|
+
[Unreleased]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.5...HEAD
|
53
|
+
[0.1.5]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.4...v0.1.5
|
54
|
+
[0.1.4]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.3...v0.1.4
|
55
|
+
[0.1.3]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.2...v0.1.3
|
56
|
+
[0.1.2]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.1...v0.1.2
|
19
57
|
[0.1.1]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.0...v0.1.1
|
20
58
|
[0.1.0]: https://github.com/chubchenko/capistrano-slacky/releases/tag/v0.1.0
|
data/README.md
CHANGED
@@ -1,13 +1,123 @@
|
|
1
|
+
<div align="center">
|
2
|
+
<img align="center"
|
3
|
+
height="100"
|
4
|
+
title="capistrano-slacky logo"
|
5
|
+
src="./assets/images/logo.svg">
|
6
|
+
</div>
|
7
|
+
|
8
|
+
[![gem version][9]][10]
|
1
9
|
[![build][1]][2]
|
10
|
+
[![downloads][11]][12]
|
2
11
|
|
3
12
|
# capistrano-slacky
|
4
13
|
|
5
|
-
Send `Capistrano` deployment status to `Slack
|
14
|
+
Send `Capistrano` deployment status to `Slack` via the Incoming Webhooks integration.
|
15
|
+
|
16
|
+
- Messages are built on the basis of the [Block Kit][13]. See [Demo](#demo) section.
|
17
|
+
- Fires after every successful/failed deployment or rollback.
|
18
|
+
- Use _Incoming Webhook URL_ from the remote server.
|
19
|
+
- Send commit log between 2 deployments.
|
20
|
+
|
21
|
+
## Table of Contents
|
22
|
+
|
23
|
+
- [Requirements](#requirements)
|
24
|
+
- [Installation](#installation)
|
25
|
+
- [Configuration](#configuration)
|
26
|
+
- [Usage](#usage)
|
27
|
+
- [Demo](#demo)
|
28
|
+
|
29
|
+
## Requirements
|
30
|
+
|
31
|
+
- Ruby >= 2.5
|
32
|
+
- Capistrano ~> 3.0
|
33
|
+
- Slack
|
34
|
+
|
35
|
+
## Installation
|
36
|
+
|
37
|
+
Add the following line to your `Gemfile`:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
gem "capistrano-slacky", "~> 0.1", require: false
|
41
|
+
```
|
42
|
+
|
43
|
+
And then execute:
|
44
|
+
|
45
|
+
```bash
|
46
|
+
bundle install
|
47
|
+
```
|
48
|
+
|
49
|
+
## Configuration
|
50
|
+
|
51
|
+
Out of the box, the gem has a default configuration:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
set :slacky, username: "ChatOps", # Set your bot's user name.
|
55
|
+
icon_emoji: ":robot_face:", # Emoji to use as the icon for this message.
|
56
|
+
channel: "#deployment", # The name of the channel to send a message to.
|
57
|
+
klass: Capistrano::Slacky::Messaging::Default # The class that responsible for creating a message.
|
58
|
+
```
|
59
|
+
|
60
|
+
So you can easily tweak your deployment messages and all other configuration to what you want.
|
61
|
+
|
62
|
+
## Usage
|
63
|
+
|
64
|
+
Require the library in your application's Capfile
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
require "capistrano/slacky"
|
68
|
+
```
|
69
|
+
|
70
|
+
- Add an [Incoming Webhooks][4] to your Slack.
|
71
|
+
- The received _Incoming Webhook URL_ must be uploaded to the remote server. It should be stored in a `shared` directory under the following path `config/slacky.yml`.
|
72
|
+
- Run `cap production slacky:ping` command to test your integration.
|
73
|
+
|
74
|
+
That's all, deploy your application as usual and you will see a deployment notification in your Slack channel.
|
75
|
+
|
76
|
+
In case if you want to disable deployment notifications for a specific stage just set `slacky` to `false`.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
set :slacky, false
|
80
|
+
```
|
81
|
+
|
82
|
+
## Demo
|
83
|
+
|
84
|
+
![Deployed successfully][5]
|
85
|
+
|
86
|
+
![Reverted successfully][6]
|
87
|
+
|
88
|
+
## Supported Ruby Versions
|
89
|
+
|
90
|
+
This library aims to support and is [tested against][2] the following Ruby implementations:
|
91
|
+
|
92
|
+
- Ruby 2.5
|
93
|
+
- Ruby 2.6
|
94
|
+
- Ruby 2.7
|
95
|
+
- Ruby 3.0
|
96
|
+
|
97
|
+
If something doesn't work on one of these Ruby versions, it's a bug.
|
98
|
+
|
99
|
+
## Versioning
|
100
|
+
|
101
|
+
This library aims to adhere to [Semantic Versioning 2.0.0][4]. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately yanked, and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions. As a result of this policy, you can (and should) specify a dependency on this gem using the [Pessimistic Version Constraint][5] with two digits of precision. For example:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
gem "capistrano-slacky", "~> 0.1"
|
105
|
+
```
|
6
106
|
|
7
107
|
## License
|
8
108
|
|
9
109
|
[MIT][3]
|
10
110
|
|
11
|
-
[1]: https://github.com/chubchenko/capistrano-slacky/workflows/build/badge.svg
|
12
|
-
[2]: https://github.com/chubchenko/capistrano-slacky/actions
|
111
|
+
[1]: https://github.com/chubchenko/capistrano-slacky/actions/workflows/build.yml/badge.svg
|
112
|
+
[2]: https://github.com/chubchenko/capistrano-slacky/actions/workflows/build.yml
|
13
113
|
[3]: https://choosealicense.com/licenses/mit
|
114
|
+
[4]: https://api.slack.com/messaging/webhooks
|
115
|
+
[5]: ./assets/images/deployed_successfully.jpg
|
116
|
+
[6]: ./assets/images/deployment_failed.jpg
|
117
|
+
[7]: ./assets/images/reverted_successfully.jpg
|
118
|
+
[8]: ./assets/images/rollback_failed.jpg
|
119
|
+
[9]: https://badge.fury.io/rb/capistrano-slacky.svg
|
120
|
+
[10]: https://badge.fury.io/rb/capistrano-slacky
|
121
|
+
[11]: https://img.shields.io/gem/dt/capistrano-slacky
|
122
|
+
[12]: https://rubygems.org/gems/capistrano-slacky
|
123
|
+
[13]: https://api.slack.com/block-kit
|
@@ -10,10 +10,10 @@ module Capistrano
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def as_json
|
14
14
|
{
|
15
15
|
type: :context,
|
16
|
-
elements: @elements.map(&:
|
16
|
+
elements: @elements.map(&:as_json)
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
@@ -22,7 +22,7 @@ module Capistrano
|
|
22
22
|
@text = text
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def as_json
|
26
26
|
{
|
27
27
|
type: :mrkdwn,
|
28
28
|
text: @text
|
@@ -10,10 +10,10 @@ module Capistrano
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def as_json
|
14
14
|
{
|
15
15
|
type: :section,
|
16
|
-
fields: @fields.map(&:
|
16
|
+
fields: @fields.map(&:as_json)
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
@@ -22,7 +22,7 @@ module Capistrano
|
|
22
22
|
@text = text
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def as_json
|
26
26
|
{
|
27
27
|
type: :mrkdwn, text: @text
|
28
28
|
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Slacky
|
5
|
+
module Command
|
6
|
+
class CurrentRevision
|
7
|
+
REVISION_FILE = "REVISION"
|
8
|
+
|
9
|
+
private_constant :REVISION_FILE
|
10
|
+
|
11
|
+
def self.call
|
12
|
+
output = nil
|
13
|
+
|
14
|
+
::Capistrano::Slacky.on(within: :release) do
|
15
|
+
output = ::SSHKit::Backend.current.capture(:cat, REVISION_FILE)
|
16
|
+
end
|
17
|
+
|
18
|
+
output
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -5,7 +5,13 @@ module Capistrano
|
|
5
5
|
module Command
|
6
6
|
class Diff
|
7
7
|
def self.call(previous:, current:)
|
8
|
-
|
8
|
+
output = nil
|
9
|
+
|
10
|
+
::Capistrano::Slacky.on(within: :repository) do
|
11
|
+
output = new(previous: previous, current: current).call
|
12
|
+
end
|
13
|
+
|
14
|
+
output
|
9
15
|
end
|
10
16
|
|
11
17
|
def initialize(previous:, current:)
|
@@ -14,15 +20,15 @@ module Capistrano
|
|
14
20
|
end
|
15
21
|
|
16
22
|
def call
|
17
|
-
|
18
|
-
|
19
|
-
).
|
23
|
+
log = ::SSHKit::Backend.current.capture(
|
24
|
+
:git, :log, "--oneline", "--first-parent", "#{previous}..#{current}"
|
25
|
+
).split("\n")
|
20
26
|
|
21
|
-
|
27
|
+
log.map.with_index(1) do |line, index|
|
22
28
|
sha, commit = line.match(/^(\w+) (.*+?)/).captures
|
23
29
|
|
24
30
|
if /^Merge pull request/.match?(commit)
|
25
|
-
commit = ::
|
31
|
+
commit = ::SSHKit::Backend.current.capture(:git, :log, "-1", sha, '--pretty=format:"%b"')
|
26
32
|
end
|
27
33
|
|
28
34
|
Message.new(index: index, sha: sha, commit: commit)
|
@@ -48,6 +54,9 @@ module Capistrano
|
|
48
54
|
"0" => ":zero:"
|
49
55
|
}.freeze
|
50
56
|
|
57
|
+
DEFAULT_ENCODING = "UTF-8"
|
58
|
+
private_constant :DEFAULT_ENCODING
|
59
|
+
|
51
60
|
def initialize(index:, sha:, commit:)
|
52
61
|
@index = index
|
53
62
|
@sha = sha
|
@@ -65,7 +74,7 @@ module Capistrano
|
|
65
74
|
end
|
66
75
|
|
67
76
|
def commit
|
68
|
-
@commit.delete('"').strip
|
77
|
+
@commit.delete('"').strip.force_encoding(DEFAULT_ENCODING)
|
69
78
|
end
|
70
79
|
|
71
80
|
def to_a
|
@@ -37,14 +37,14 @@ module Capistrano
|
|
37
37
|
|
38
38
|
def repo
|
39
39
|
@repo ||= Repo.new(
|
40
|
-
remote: env.fetch(:repo_url)
|
40
|
+
remote: @env.fetch(:repo_url)
|
41
41
|
)
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def data
|
47
|
-
@data ||= env.fetch(:slacky, {})
|
47
|
+
@data ||= @env.fetch(:slacky, {})
|
48
48
|
end
|
49
49
|
|
50
50
|
class Repo
|
@@ -64,7 +64,7 @@ module Capistrano
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def ssh?
|
67
|
-
@remote.match?(/((git|ssh|http(s)?)|(git@[\w.]+))(:(\/)?)([\w
|
67
|
+
@remote.match?(/((git|ssh|http(s)?)|(git@[\w.]+))(:(\/)?)([\w.@:\/~-]+)(\.git)(\/)?/)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -8,9 +8,9 @@ module Capistrano
|
|
8
8
|
@env = env
|
9
9
|
|
10
10
|
super(
|
11
|
-
t("slacky.stage"), "`#{stage}`",
|
12
|
-
t("slacky.branch"), "`#{branch}`",
|
13
|
-
t("slacky.duration"), "`#{duration}`",
|
11
|
+
::I18n.t("slacky.stage", scope: "capistrano"), "`#{stage}`",
|
12
|
+
::I18n.t("slacky.branch", scope: "capistrano"), "`#{branch}`",
|
13
|
+
::I18n.t("slacky.duration", scope: "capistrano"), "`#{duration}`",
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
@@ -11,25 +11,17 @@ module Capistrano
|
|
11
11
|
).call
|
12
12
|
end
|
13
13
|
|
14
|
-
attr_accessor :difference
|
15
|
-
|
16
14
|
def initialize(previous:, current:)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
ref.difference = ::Capistrano::Slacky::Command::Diff.call(
|
22
|
-
previous: previous,
|
23
|
-
current: current
|
24
|
-
)
|
25
|
-
end
|
26
|
-
end
|
15
|
+
@difference = ::Capistrano::Slacky::Command::Diff.call(
|
16
|
+
previous: previous,
|
17
|
+
current: current
|
18
|
+
)
|
27
19
|
end
|
28
20
|
|
29
21
|
def call
|
30
22
|
if difference.empty?
|
31
23
|
return ::Capistrano::Slacky::Block::Context.new(
|
32
|
-
t("slacky.nothing_has_changed_since_the_previous_release")
|
24
|
+
::I18n.t("slacky.nothing_has_changed_since_the_previous_release", scope: "capistrano")
|
33
25
|
)
|
34
26
|
end
|
35
27
|
|
@@ -39,6 +31,10 @@ module Capistrano
|
|
39
31
|
)
|
40
32
|
end
|
41
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :difference
|
42
38
|
end
|
43
39
|
end
|
44
40
|
end
|
@@ -6,7 +6,7 @@ module Capistrano
|
|
6
6
|
class DeployedBy < ::Capistrano::Slacky::Block::Context
|
7
7
|
def initialize(env:)
|
8
8
|
super(
|
9
|
-
t("slacky.deployed_by", deployer: env.fetch(:local_user))
|
9
|
+
::I18n.t("slacky.deployed_by", scope: "capistrano", deployer: env.fetch(:local_user))
|
10
10
|
)
|
11
11
|
end
|
12
12
|
end
|
@@ -6,7 +6,7 @@ module Capistrano
|
|
6
6
|
class Exception < ::Capistrano::Slacky::Block::Context
|
7
7
|
DefaultException = ::Class.new(::StandardError) do
|
8
8
|
def initialize
|
9
|
-
super(t("slacky.something_went_wrong"))
|
9
|
+
super(::I18n.t("slacky.something_went_wrong", scope: "capistrano"))
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -8,9 +8,10 @@ module Capistrano
|
|
8
8
|
@env = env
|
9
9
|
|
10
10
|
super(
|
11
|
-
t("slacky.revision",
|
12
|
-
|
13
|
-
|
11
|
+
I18n.t("slacky.revision", scope: "capistrano",
|
12
|
+
repository_url: ::Capistrano::Slacky.repo.url,
|
13
|
+
current: current,
|
14
|
+
previous: previous)
|
14
15
|
)
|
15
16
|
end
|
16
17
|
|
@@ -9,19 +9,15 @@ module Capistrano
|
|
9
9
|
|
10
10
|
module_function
|
11
11
|
|
12
|
-
def uri
|
12
|
+
def uri
|
13
13
|
output = nil
|
14
14
|
|
15
|
-
on(
|
16
|
-
output = capture(:cat,
|
15
|
+
::Capistrano::Slacky.on(within: :shared) do
|
16
|
+
output = ::SSHKit::Backend.current.capture(:cat, DEFAULT_HOOK_FILE)
|
17
17
|
end
|
18
18
|
|
19
19
|
URI(output)
|
20
20
|
end
|
21
|
-
|
22
|
-
def role
|
23
|
-
::Capistrano::Configuration.env.primary(:app)
|
24
|
-
end
|
25
21
|
end
|
26
22
|
|
27
23
|
private_constant :Hook
|
@@ -11,7 +11,7 @@ module Capistrano
|
|
11
11
|
::Capistrano::Slacky::Facade::Revision.new(env: env),
|
12
12
|
::Capistrano::Slacky::Facade::Changelog.for(env: env),
|
13
13
|
::Capistrano::Slacky::Facade::DeployedBy.new(env: env)
|
14
|
-
).
|
14
|
+
).as_json
|
15
15
|
end
|
16
16
|
|
17
17
|
def payload_for_reverted
|
@@ -20,7 +20,7 @@ module Capistrano
|
|
20
20
|
::Capistrano::Slacky::Facade::Body.new(env: env),
|
21
21
|
::Capistrano::Slacky::Facade::Revision.new(env: env),
|
22
22
|
::Capistrano::Slacky::Facade::DeployedBy.new(env: env)
|
23
|
-
).
|
23
|
+
).as_json
|
24
24
|
end
|
25
25
|
|
26
26
|
def payload_for_failed
|
@@ -29,7 +29,13 @@ module Capistrano
|
|
29
29
|
::Capistrano::Slacky::Facade::Body.new(env: env),
|
30
30
|
::Capistrano::Slacky::Facade::Exception.new,
|
31
31
|
::Capistrano::Slacky::Facade::DeployedBy.new(env: env)
|
32
|
-
).
|
32
|
+
).as_json
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def deploying?
|
38
|
+
env.fetch(:deploying, false)
|
33
39
|
end
|
34
40
|
end
|
35
41
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Slacky
|
5
|
+
module On
|
6
|
+
class Path
|
7
|
+
extend ::Capistrano::DSL
|
8
|
+
end
|
9
|
+
|
10
|
+
PATH_MAP = {
|
11
|
+
repository: -> { Path.repo_path },
|
12
|
+
shared: -> { Path.shared_path },
|
13
|
+
release: -> { Path.release_path }
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
private_constant :PATH_MAP
|
17
|
+
|
18
|
+
module_function
|
19
|
+
|
20
|
+
def on(within:, &block)
|
21
|
+
role = ::Capistrano::Configuration.env.primary(:app) || ::Capistrano::Configuration.env.roles(:all).first
|
22
|
+
|
23
|
+
::Capistrano::DSL.on(role) do
|
24
|
+
::SSHKit::Backend.current.within(PATH_MAP.fetch(within).call, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/capistrano/slacky.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
load File.expand_path("../../tasks/slacky.rake", __FILE__)
|
4
|
+
load File.expand_path("../../tasks/hooks.rake", __FILE__)
|
5
|
+
load File.expand_path("../../tasks/defaults.rake", __FILE__)
|
4
6
|
|
5
7
|
require_relative "slacky/version"
|
6
8
|
require_relative "slacky/configuration"
|
@@ -9,24 +11,19 @@ require_relative "slacky/runner"
|
|
9
11
|
require_relative "slacky/block"
|
10
12
|
require_relative "slacky/facade"
|
11
13
|
require_relative "slacky/command"
|
14
|
+
require_relative "slacky/on"
|
12
15
|
|
13
16
|
module Capistrano
|
14
17
|
module Slacky
|
15
|
-
|
18
|
+
require "forwardable"
|
16
19
|
|
17
|
-
|
18
|
-
def method_missing(method_name, *arguments, &block)
|
19
|
-
return super unless configuration.respond_to?(method_name)
|
20
|
+
module_function
|
20
21
|
|
21
|
-
|
22
|
-
end
|
22
|
+
extend ::SingleForwardable
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
configuration.respond_to?(method_name) || super
|
27
|
-
end
|
24
|
+
def_delegators :configuration, :username, :icon_emoji, :channel, :klass, :slacky?, :repo
|
25
|
+
def_delegator :"Capistrano::Slacky::On", :on
|
28
26
|
|
29
|
-
# @return [Capistrano::Slacky::Configuration]
|
30
27
|
def configuration
|
31
28
|
@configuration ||= ::Capistrano::Slacky::Configuration.new
|
32
29
|
end
|
data/lib/tasks/slacky.rake
CHANGED
@@ -3,40 +3,31 @@
|
|
3
3
|
namespace :slacky do
|
4
4
|
desc "Slacky after a successful deployment"
|
5
5
|
task :updated do
|
6
|
-
Capistrano::Slacky::Runner.call(
|
7
|
-
env: self, action: :updated
|
8
|
-
)
|
6
|
+
Capistrano::Slacky::Runner.call(action: :updated)
|
9
7
|
end
|
10
8
|
|
11
9
|
desc "Slacky after successful rollback"
|
12
|
-
task :
|
13
|
-
Capistrano::Slacky::Runner.call(
|
14
|
-
env: self, action: :reverted
|
15
|
-
)
|
10
|
+
task reverted: [:ensure_current_revision] do
|
11
|
+
Capistrano::Slacky::Runner.call(action: :reverted)
|
16
12
|
end
|
17
13
|
|
18
14
|
desc "Slacky after failure deployment or rollback"
|
19
15
|
task :failed do
|
20
|
-
Capistrano::Slacky::Runner.call(
|
21
|
-
env: self, action: :failed
|
22
|
-
)
|
16
|
+
Capistrano::Slacky::Runner.call(action: :failed)
|
23
17
|
end
|
24
18
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# )
|
30
|
-
# end
|
31
|
-
# end
|
32
|
-
end
|
19
|
+
desc "Slacky all slackable task (updated, reverted, failed)"
|
20
|
+
task :ping do
|
21
|
+
ask(:previous_revision) unless env.any?(:previous_revision)
|
22
|
+
ask(:current_revision) unless env.any?(:current_revision)
|
33
23
|
|
34
|
-
|
35
|
-
|
36
|
-
|
24
|
+
[:updated, :reverted, :failed].each do |action|
|
25
|
+
Capistrano::Slacky::Runner.call(action: action)
|
26
|
+
end
|
27
|
+
end
|
37
28
|
|
38
|
-
|
39
|
-
task :
|
40
|
-
|
29
|
+
desc "Ensure that the current revision is set"
|
30
|
+
task :ensure_current_revision do
|
31
|
+
set_if_empty(:current_revision) { Capistrano::Slacky::Command::CurrentRevision.call }
|
41
32
|
end
|
42
33
|
end
|
metadata
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-slacky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Chubchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 3.0.0
|
20
17
|
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: '3.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 3.0.0
|
30
27
|
- - "~>"
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '3.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,21 +72,7 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0.21'
|
75
|
-
|
76
|
-
name: webmock
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '3.12'
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - "~>"
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '3.12'
|
89
|
-
description: Send Capistrano deployment status to Slack via the incoming webhooks
|
75
|
+
description: Send Capistrano deployment status to Slack via the Incoming Webhooks
|
90
76
|
integration
|
91
77
|
email: artem.chubchenko@gmail.com
|
92
78
|
executables: []
|
@@ -104,6 +90,7 @@ files:
|
|
104
90
|
- lib/capistrano/slacky/block/root.rb
|
105
91
|
- lib/capistrano/slacky/block/section.rb
|
106
92
|
- lib/capistrano/slacky/command.rb
|
93
|
+
- lib/capistrano/slacky/command/current_revision.rb
|
107
94
|
- lib/capistrano/slacky/command/diff.rb
|
108
95
|
- lib/capistrano/slacky/command/duration.rb
|
109
96
|
- lib/capistrano/slacky/configuration.rb
|
@@ -121,9 +108,12 @@ files:
|
|
121
108
|
- lib/capistrano/slacky/messaging/base.rb
|
122
109
|
- lib/capistrano/slacky/messaging/default.rb
|
123
110
|
- lib/capistrano/slacky/messaging/null.rb
|
111
|
+
- lib/capistrano/slacky/on.rb
|
124
112
|
- lib/capistrano/slacky/payload.rb
|
125
113
|
- lib/capistrano/slacky/runner.rb
|
126
114
|
- lib/capistrano/slacky/version.rb
|
115
|
+
- lib/tasks/defaults.rake
|
116
|
+
- lib/tasks/hooks.rake
|
127
117
|
- lib/tasks/slacky.rake
|
128
118
|
homepage: https://github.com/chubchenko/capistrano-slacky
|
129
119
|
licenses:
|
@@ -149,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
139
|
- !ruby/object:Gem::Version
|
150
140
|
version: '0'
|
151
141
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
142
|
+
rubygems_version: 3.2.28
|
153
143
|
signing_key:
|
154
144
|
specification_version: 4
|
155
145
|
summary: Send Capistrano deployment status to Slack
|