capistrano-sentry 0.4.2 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa08b17ff84fe1b532e61db8eb1523386d1067fdbebb2f1e35e08ea3838321a7
4
- data.tar.gz: 37f28cfb7948b2f466459edc77d415df07110792c4aeb195e0c9b9ae3c41ba3a
3
+ metadata.gz: 1309178927aac5e5af01a3dd3e42ed491dd88c6915ab250d419b9ead97f630ca
4
+ data.tar.gz: 28bcd3f86fbdfacec11a91e58e98df9df216c924db5022b1138450a11de1c056
5
5
  SHA512:
6
- metadata.gz: 2f29484e5511e9a3c6a2446c4ce50910e8eeb06ca9bcce512322ea111bfed2ff18e747378deee98389fb34c7e659315d0ff35f512252e6196e627c9bf66574ae
7
- data.tar.gz: 7aa867b34a28f3fca952372e847134326df5210872b634db857497ba5e080223302534a28535eeb06e5de2c616d21240c246ea7768c8908c496bdf2e122be0b8
6
+ metadata.gz: c6964c9789df72462efb1b3f6c0e90625904f7d173403277815358f38f36377ece78807766966a214d2ae4d0981d07fe7c98eda0d37f7d69f3d092b5b5cb1bd0
7
+ data.tar.gz: 8c210ac87ef38e0758f95cb5410759adf0f9abfa3b6cbc00c33c427e0aa2e312a5acac3cc09463048b29993e484665c2fcc7f18552a2ae9fa743a2ef9a01e58f
@@ -9,18 +9,19 @@ jobs:
9
9
 
10
10
  strategy:
11
11
  matrix:
12
- ruby: [ '2.6' ]
12
+ ruby: [ '3.4' ]
13
13
 
14
14
  steps:
15
15
  - uses: actions/checkout@v2
16
16
 
17
17
  - name: Set up Ruby ${{ matrix.ruby }}
18
- uses: actions/setup-ruby@v1
18
+ uses: ruby/setup-ruby@v1
19
19
  with:
20
20
  ruby-version: ${{ matrix.ruby }}
21
+ bundler-cache: true
21
22
 
22
23
  - name: Retrieve gems cache
23
- uses: actions/cache@v1.1.2
24
+ uses: actions/cache@v5
24
25
  with:
25
26
  path: vendor/bundle
26
27
  key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }}
@@ -35,7 +36,7 @@ jobs:
35
36
  run: bundle exec rake test
36
37
 
37
38
  - name: Upload log if failure
38
- uses: actions/upload-artifact@v1
39
+ uses: actions/upload-artifact@v6
39
40
  if: failure()
40
41
  with:
41
42
  name: test.log
data/Gemfile CHANGED
@@ -6,3 +6,6 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
7
  # Specify your gem's dependencies in capistrano-sentry.gemspec
8
8
  gemspec
9
+
10
+ gem 'minitest', '~> 5.0'
11
+ gem 'rake', '>= 10'
data/README.md CHANGED
@@ -33,9 +33,10 @@ set :sentry_api_token, '0123456789abcdef0123456789abcdef'
33
33
  set :sentry_organization, 'my-org' # fetch(:application) by default
34
34
  set :sentry_project, 'my-proj' # fetch(:application) by default
35
35
  set :sentry_repo, 'my-org/my-proj' # computed from repo_url by default
36
+ set :sentry_stages, %w[production] # only these stages create releases and deploys, %w[production] by default
36
37
  ```
37
38
 
38
- If you want deployments to be published in every Rails environment, put this in `config/deploy.rb`, otherwise put it your environment-specific deploy file (i.e. `config/deploy/production.rb`):
39
+ Then hook the tasks in `config/deploy.rb`:
39
40
  ```ruby
40
41
  before 'deploy:starting', 'sentry:validate_config'
41
42
  after 'deploy:published', 'sentry:notice_deployment'
@@ -56,6 +57,8 @@ after 'deploy:published', 'sentry:notice_deployment'
56
57
 
57
58
  * `sentry_repo`: The `repository` name to be used when reporting repository details to Sentry [computed from `fetch(:repo_url)` by default -- `https://github.com/codeur/capistrano-sentry` becomes `//github.com/codeur/capistrano-sentry` and `git@github.com:codeur/capistrano-sentry.git` becomes `codeur/capistrano-sentry`]
58
59
 
60
+ * `sentry_stages`: the Capistrano stages allowed to create releases and deploys in Sentry. Both tasks are skipped for any other stage, so a staging deploy never creates a release. [`%w[production]` by default]
61
+
59
62
  * `sentry_repo_integration`: this enables/disables submission of git repo information (`release_refs` below) to Sentry [Enabled (`true`) by default].
60
63
 
61
64
  * `sentry_release_refs`: Repository details about this realease (`repository`, `commit`, `previousCommit`) to Sentry [computed from `sentry_repo`, `current_revision`, and `previous_revision`)].
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require 'rake/testtask'
5
5
 
6
6
  Rake::TestTask.new(:test) do |t|
7
7
  t.libs << 'test'
8
+ t.warning = false # capistrano itself triggers circular require warnings
8
9
  t.libs << 'lib'
9
10
  t.test_files = FileList['test/**/*_test.rb']
10
11
  end
@@ -25,8 +25,4 @@ Gem::Specification.new do |spec|
25
25
  spec.require_paths = ['lib']
26
26
 
27
27
  spec.add_dependency 'capistrano', '~> 3.1'
28
-
29
- spec.add_development_dependency 'bundler', '~> 1.17'
30
- spec.add_development_dependency 'minitest', '~> 5.0'
31
- spec.add_development_dependency 'rake', '>= 10'
32
28
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capistrano
4
4
  module Sentry
5
- VERSION = '0.4.2'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -15,9 +15,19 @@ module Capistrano
15
15
  end
16
16
 
17
17
  namespace :sentry do
18
+ # Only the stages listed in `:sentry_stages` (`production` by default) notify Sentry.
19
+ def sentry_stage_enabled?
20
+ Array(fetch(:sentry_stages, %w[production])).map(&:to_s).include?(fetch(:stage).to_s)
21
+ end
22
+
18
23
  desc 'Confirm configuration for notification to Sentry'
19
24
  task :validate_config do
20
25
  run_locally do
26
+ unless sentry_stage_enabled?
27
+ info "[sentry:validate_config] Skipped: stage #{fetch(:stage).inspect} is not listed in :sentry_stages"
28
+ next
29
+ end
30
+
21
31
  info '[sentry:validate_config] Validating Sentry notification config'
22
32
  api_token = ENV['SENTRY_API_TOKEN'] || fetch(:sentry_api_token)
23
33
  if api_token.nil? || api_token.empty?
@@ -32,6 +42,11 @@ namespace :sentry do
32
42
  desc 'Notice new deployment in Sentry'
33
43
  task :notice_deployment do
34
44
  run_locally do
45
+ unless sentry_stage_enabled?
46
+ info "[sentry:notice_deployment] Skipped: stage #{fetch(:stage).inspect} is not listed in :sentry_stages"
47
+ next
48
+ end
49
+
35
50
  require 'uri'
36
51
  require 'net/https'
37
52
  require 'json'
@@ -1,12 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
- require 'capistrano/sentry/version'
5
4
 
6
5
  module Capistrano
7
- class SentryTest < Minitest::Test
8
- def test_that_it_has_a_version_number
9
- assert !::Capistrano::Sentry::VERSION.nil?
6
+ class SentryTest < TestCase
7
+ def test_production_creates_a_release_and_a_deploy
8
+ set :stage, :production
9
+ run_task :notice_deployment
10
+
11
+ assert_equal 2, @http.requests.size
12
+ release, deploy = @http.requests
13
+ assert_equal '/api/0/organizations/my-app/releases/', release.path
14
+ assert_equal 'Bearer secret', release['Authorization']
15
+ body = JSON.parse(release.body)
16
+ assert_equal 'abc123', body['version']
17
+ assert_equal ['my-app'], body['projects']
18
+ assert_equal 'my-org/my-app', body['refs'].first['repository']
19
+ assert_equal '/api/0/organizations/my-app/releases/abc123/deploys/', deploy.path
20
+ assert_equal({ 'environment' => 'production', 'name' => 'abc123-20260910120000' }, JSON.parse(deploy.body))
21
+ assert_includes log, 'Notified Sentry of new deployment'
22
+ end
23
+
24
+ def test_other_stages_do_not_notify_sentry
25
+ set :stage, :staging
26
+ run_task :notice_deployment
27
+
28
+ assert_empty @http.requests
29
+ assert_includes log, 'Skipped: stage :staging is not listed in :sentry_stages'
30
+ end
31
+
32
+ def test_sentry_stages_can_enable_other_stages
33
+ set :stage, :staging
34
+ set :sentry_stages, %w[staging production]
35
+ run_task :notice_deployment
36
+
37
+ assert_equal 2, @http.requests.size
38
+ assert_equal 'staging', JSON.parse(@http.requests.last.body)['environment']
39
+ end
40
+
41
+ def test_validate_config_requires_a_token_on_enabled_stages
42
+ set :stage, :production
43
+ set :sentry_api_token, nil
44
+
45
+ assert_raises(Capistrano::SentryConfigurationError) { run_task :validate_config }
46
+ end
47
+
48
+ def test_validate_config_is_skipped_on_other_stages
49
+ set :stage, :staging
50
+ set :sentry_api_token, nil
51
+
52
+ run_task :validate_config
53
+ assert_includes log, 'Skipped: stage :staging is not listed in :sentry_stages'
10
54
  end
11
55
  end
12
56
  end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,62 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
- require 'capistrano/sentry'
5
4
 
5
+ require 'capistrano/all'
6
+ Rake.application.options.trace = false # re-enabled by capistrano/all
6
7
  require 'minitest/autorun'
8
+ require 'stringio'
9
+ require 'net/http'
10
+ require 'json'
11
+
12
+ include Capistrano::DSL # rubocop:disable Style/MixinUsage
13
+
14
+ require 'capistrano/sentry'
15
+
16
+ module Capistrano
17
+ # Runs Capistrano tasks against a fresh configuration, with SSHKit output captured
18
+ # and Sentry's HTTP API replaced by a recorder.
19
+ class TestCase < Minitest::Test
20
+ class FakeHTTP
21
+ attr_reader :requests
22
+
23
+ def initialize
24
+ @requests = []
25
+ end
26
+
27
+ def use_ssl=(_value); end
28
+
29
+ def request(req)
30
+ @requests << req
31
+ Net::HTTPCreated.new('1.1', '201', 'Created').tap do |response|
32
+ response.instance_variable_set(:@body, '{}')
33
+ response.instance_variable_set(:@read, true)
34
+ end
35
+ end
36
+ end
37
+
38
+ def setup
39
+ Capistrano::Configuration.reset!
40
+ @log = StringIO.new
41
+ SSHKit.config.output = SSHKit::Formatter::Pretty.new(@log)
42
+ SSHKit.config.output_verbosity = :debug
43
+ @http = FakeHTTP.new
44
+ set :application, 'my-app'
45
+ set :repo_url, 'git@github.com:my-org/my-app.git'
46
+ set :sentry_api_token, 'secret'
47
+ set :current_revision, 'abc123'
48
+ set :previous_revision, 'def456'
49
+ set :release_timestamp, '20260910120000'
50
+ end
51
+
52
+ def run_task(name)
53
+ task = Rake::Task["sentry:#{name}"]
54
+ task.reenable
55
+ Net::HTTP.stub(:new, @http) { task.invoke }
56
+ end
57
+
58
+ def log
59
+ @log.string
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-sentry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brice Texier
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2020-05-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: capistrano
@@ -24,48 +23,6 @@ dependencies:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
25
  version: '3.1'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.17'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.17'
41
- - !ruby/object:Gem::Dependency
42
- name: minitest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '5.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '5.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '10'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '10'
69
26
  description: Sentry release/deployment integration
70
27
  email:
71
28
  - brice@codeur.com
@@ -94,7 +51,6 @@ homepage: https://github.com/codeur/capistrano-sentry
94
51
  licenses:
95
52
  - MIT
96
53
  metadata: {}
97
- post_install_message:
98
54
  rdoc_options: []
99
55
  require_paths:
100
56
  - lib
@@ -109,8 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
65
  - !ruby/object:Gem::Version
110
66
  version: '0'
111
67
  requirements: []
112
- rubygems_version: 3.0.3
113
- signing_key:
68
+ rubygems_version: 3.6.9
114
69
  specification_version: 4
115
70
  summary: Push release and deployment information on Sentry on each deploy
116
71
  test_files: