capistrano-sentry 0.1.5 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b604bc26d4b0cf71021d043bbe11976c97f434ec2ada60305775be65e25ca83a
4
- data.tar.gz: dfdaddac07ac73247e7766146f759a6326ce2c030f9c8f59fb337d88b172495f
3
+ metadata.gz: aa08b17ff84fe1b532e61db8eb1523386d1067fdbebb2f1e35e08ea3838321a7
4
+ data.tar.gz: 37f28cfb7948b2f466459edc77d415df07110792c4aeb195e0c9b9ae3c41ba3a
5
5
  SHA512:
6
- metadata.gz: 46ee1f6c34b8c7d363ce49fdf7400dfec5f7b551ac6a69b73fcc934e1e47268a40a831aaf226d7c0ba3d43fe5586bbd91cc7a17ddad91c67f9e16d0b0873ecf9
7
- data.tar.gz: 1c765c330033504b7126b20a060e1231abbdaf2a2f71368ac752c0d022dfd64c2aea275d62f85bd61ecbcf481678871afe15de778ddffea62b7a685ed7667dfd
6
+ metadata.gz: 2f29484e5511e9a3c6a2446c4ce50910e8eeb06ca9bcce512322ea111bfed2ff18e747378deee98389fb34c7e659315d0ff35f512252e6196e627c9bf66574ae
7
+ data.tar.gz: 7aa867b34a28f3fca952372e847134326df5210872b634db857497ba5e080223302534a28535eeb06e5de2c616d21240c246ea7768c8908c496bdf2e122be0b8
@@ -0,0 +1,42 @@
1
+ name: Test
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ strategy:
11
+ matrix:
12
+ ruby: [ '2.6' ]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+
17
+ - name: Set up Ruby ${{ matrix.ruby }}
18
+ uses: actions/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+
22
+ - name: Retrieve gems cache
23
+ uses: actions/cache@v1.1.2
24
+ with:
25
+ path: vendor/bundle
26
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }}
27
+
28
+ - name: Install gems
29
+ run: |
30
+ rm -f .ruby-version
31
+ bundle config path vendor/bundle
32
+ bundle install --jobs 4 --retry 3
33
+
34
+ - name: Run tests
35
+ run: bundle exec rake test
36
+
37
+ - name: Upload log if failure
38
+ uses: actions/upload-artifact@v1
39
+ if: failure()
40
+ with:
41
+ name: test.log
42
+ path: log/test.log
data/.gitignore CHANGED
@@ -6,4 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- *~
9
+ Gemfile.lock
10
+ *~
@@ -0,0 +1,99 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Layout/AccessModifierIndentation:
5
+ EnforcedStyle: outdent
6
+ IndentationWidth: 2
7
+
8
+ Layout/ArgumentAlignment:
9
+ EnforcedStyle: with_fixed_indentation
10
+ IndentationWidth: 2
11
+
12
+ Layout/FirstArrayElementIndentation:
13
+ EnforcedStyle: consistent
14
+
15
+ Layout/FirstHashElementIndentation:
16
+ EnforcedStyle: consistent
17
+
18
+ Layout/HashAlignment:
19
+ EnforcedHashRocketStyle: table
20
+ EnforcedColonStyle: table
21
+
22
+ Layout/MultilineMethodCallIndentation:
23
+ EnforcedStyle: indented
24
+
25
+ Layout/ParameterAlignment:
26
+ EnforcedStyle: with_fixed_indentation
27
+ IndentationWidth: 2
28
+
29
+ Lint/RaiseException:
30
+ Enabled: true
31
+
32
+ Lint/StructNewOverride:
33
+ Enabled: true
34
+
35
+ Metrics/AbcSize:
36
+ Max: 65
37
+
38
+ Metrics/BlockLength:
39
+ Max: 70
40
+
41
+ Metrics/ClassLength:
42
+ Max: 300
43
+
44
+ Metrics/CyclomaticComplexity:
45
+ Max: 10
46
+
47
+ Metrics/MethodLength:
48
+ Max: 60
49
+
50
+ Metrics/ModuleLength:
51
+ Max: 300
52
+
53
+ Metrics/PerceivedComplexity:
54
+ Max: 10
55
+
56
+ Naming/FileName:
57
+ Enabled: false
58
+
59
+ Style/AsciiComments:
60
+ Enabled: false
61
+
62
+ Style/ClassAndModuleChildren:
63
+ AutoCorrect: true
64
+
65
+ Style/ConditionalAssignment:
66
+ Enabled: false
67
+
68
+ Style/Documentation:
69
+ Enabled: false
70
+
71
+ Style/EmptyMethod:
72
+ EnforcedStyle: expanded
73
+
74
+ Style/GuardClause:
75
+ MinBodyLength: 3
76
+
77
+ Style/HashEachMethods:
78
+ Enabled: true
79
+ AutoCorrect: true
80
+
81
+ Style/HashTransformKeys:
82
+ Enabled: true
83
+ AutoCorrect: true
84
+
85
+ Style/HashTransformValues:
86
+ Enabled: true
87
+ AutoCorrect: true
88
+
89
+ Style/IfUnlessModifier:
90
+ Enabled: false
91
+
92
+ Style/MultipleComparison:
93
+ Enabled: false
94
+
95
+ Style/NumericPredicate:
96
+ Enabled: false
97
+
98
+ Style/SymbolArray:
99
+ MinSize: 7
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
data/README.md CHANGED
@@ -2,15 +2,12 @@
2
2
 
3
3
  Simple extension of capistrano for automatic notification of Sentry.
4
4
 
5
- TODO: Prevent user at deployment start if missing parameter to inform sentry
6
- properly
7
-
8
5
  ## Installation
9
6
 
10
7
  Add this line to your application's Gemfile:
11
8
 
12
9
  ```ruby
13
- gem 'capistrano-sentry'
10
+ gem 'capistrano-sentry', require: false
14
11
  ```
15
12
 
16
13
  Then, add this line to your application's Capfile:
@@ -19,9 +16,11 @@ Then, add this line to your application's Capfile:
19
16
  require 'capistrano/sentry'
20
17
  ```
21
18
 
22
- And then execute:
19
+ And then execute from your command line:
23
20
 
24
- $ bundle
21
+ ```bash
22
+ bundle
23
+ ```
25
24
 
26
25
  ## Usage
27
26
 
@@ -29,14 +28,46 @@ Add these lines to your application's `config/deploy.rb`:
29
28
 
30
29
  ```ruby
31
30
  # Sentry deployment notification
32
- set :sentry_api_token, 'd9fe44a1cf34e63993e258dbecf42158918d407978a1bb72f8fb5886aa5f9fe1'
31
+ set :sentry_host, 'https://my-sentry.mycorp.com' # https://sentry.io by default
32
+ 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
+ ```
36
37
 
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
+ ```ruby
40
+ before 'deploy:starting', 'sentry:validate_config'
37
41
  after 'deploy:published', 'sentry:notice_deployment'
38
42
  ```
39
43
 
44
+ ### Explaination of Configuration Properties
45
+
46
+ * `sentry_host`: identifies to which host Sentry submissions are sent. [https://sentry.io by default]
47
+
48
+ * `sentry_api_token`: API Auth Tokens are found/created in you Sentry Account Settings (not in the organization or project): `Settings > Account > Api > Auth Tokens`.
49
+ [https://sentry.io/settings/account/api/auth-tokens/]
50
+
51
+ * `sentry_organization`: The "**Name**" ("*A unique ID used to identify this organization*") from Sentry's Organization Settings page.
52
+ [https://sentry.io/settings/{ORGANIZATION_SLUG}]
53
+
54
+ * `sentry_project`: The "**Name**" ("*A unique ID used to identify this project*") from Sentry's Project Settings page.
55
+ [https://sentry.io/settings/{ORGANIZATION_SLUG}/projects/{PROJECT_SLUG}]
56
+
57
+ * `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
+ * `sentry_repo_integration`: this enables/disables submission of git repo information (`release_refs` below) to Sentry [Enabled (`true`) by default].
60
+
61
+ * `sentry_release_refs`: Repository details about this realease (`repository`, `commit`, `previousCommit`) to Sentry [computed from `sentry_repo`, `current_revision`, and `previous_revision`)].
62
+
63
+ * `sentry_release_version`: Version number (tag, etc.) used to identify this release to Sentry [computed from `current_revision` or repository `HEAD`)].
64
+
65
+ * `deploy_name`: A name (revision, version number, tag, etc.) used to identify this release deploy to Sentry [computed from `sentry_release_version`+`fetch(:release_timestamp)`)].
66
+
67
+ ### Sentry API Documentation
68
+ * [Project Releases](https://docs.sentry.io/api/releases/post-project-releases/)
69
+ * [Release Deploys](https://docs.sentry.io/api/releases/post-release-deploys/)
70
+
40
71
  ## Development
41
72
 
42
73
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'capistrano/sentry'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'capistrano/sentry/version'
@@ -7,8 +9,8 @@ Gem::Specification.new do |spec|
7
9
  spec.version = Capistrano::Sentry::VERSION
8
10
  spec.authors = ['Brice Texier']
9
11
  spec.email = ['brice@codeur.com']
10
-
11
- spec.summary = 'Sentry release/deployment integration'
12
+ spec.description = 'Sentry release/deployment integration'
13
+ spec.summary = 'Push release and deployment information on Sentry on each deploy'
12
14
  spec.homepage = 'https://github.com/codeur/capistrano-sentry'
13
15
  spec.license = 'MIT'
14
16
 
@@ -26,5 +28,5 @@ Gem::Specification.new do |spec|
26
28
 
27
29
  spec.add_development_dependency 'bundler', '~> 1.17'
28
30
  spec.add_development_dependency 'minitest', '~> 5.0'
29
- spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rake', '>= 10'
30
32
  end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  load File.expand_path('tasks/sentry.rake', __dir__)
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Capistrano
2
4
  module Sentry
3
- VERSION = '0.1.5'.freeze
5
+ VERSION = '0.4.2'
4
6
  end
5
7
  end
@@ -1,65 +1,88 @@
1
- # This task will notify Sentry via their API[1] that you have deployed
2
- # a new release. It uses the release timestamp as the `version`
3
- # (like 20151113182847) and the git ref as the optional `ref` value.
4
- #
5
- # This task requires several environment variables be set (or just
6
- # hardcode the values in here if you like living on the edge):
7
- #
8
- # ENV['SENTRY_API_ENDPOINT'] : API endpoint, https://app.getsentry.com
9
- # ENV['SENTRY_ORG'] : the organization for this app
10
- # ENV['SENTRY_PROJECT'] : the project for this app
11
- # ENV['SENTRY_AUTH_TOKEN'] : a valid Auth token (replaces API Key)
1
+ # frozen_string_literal: true
2
+
3
+ # This task will notify Sentry via their API[1][2] that you have deployed
4
+ # a new release. It uses the commit hash as the `version` and the git ref as
5
+ # the optional `ref` value.
12
6
  #
13
- # [1]: https://docs.getsentry.com/hosted/api/releases/post-project-releases
7
+ # [1]: https://docs.sentry.io/api/releases/post-project-releases/
8
+ # [2]: https://docs.sentry.io/api/releases/post-release-deploys/
14
9
 
15
10
  # For Rails app, this goes in config/deploy.rb
16
11
 
12
+ module Capistrano
13
+ class SentryConfigurationError < StandardError
14
+ end
15
+ end
16
+
17
17
  namespace :sentry do
18
- desc 'Notice new deployment in Sentry (sentry.io)'
18
+ desc 'Confirm configuration for notification to Sentry'
19
+ task :validate_config do
20
+ run_locally do
21
+ info '[sentry:validate_config] Validating Sentry notification config'
22
+ api_token = ENV['SENTRY_API_TOKEN'] || fetch(:sentry_api_token)
23
+ if api_token.nil? || api_token.empty?
24
+ msg = 'Missing SENTRY_API_TOKEN. Please set SENTRY_API_TOKEN environment' \
25
+ ' variable or `set :sentry_api_token` in your `config/deploy.rb` file for your Rails application.'
26
+ warn msg
27
+ raise Capistrano::SentryConfigurationError, msg
28
+ end
29
+ end
30
+ end
31
+
32
+ desc 'Notice new deployment in Sentry'
19
33
  task :notice_deployment do
20
34
  run_locally do
21
35
  require 'uri'
22
36
  require 'net/https'
23
37
  require 'json'
24
38
 
25
- uri = URI.parse('https://sentry.io')
26
- http = Net::HTTP.new(uri.host, uri.port)
27
- http.use_ssl = true
39
+ head_revision = fetch(:current_revision) || `git rev-parse HEAD`.strip
40
+ prev_revision = fetch(:previous_revision) || `git rev-parse #{fetch(:current_revision)}^`.strip
28
41
 
29
- version = `git rev-parse HEAD`.strip
30
-
31
- orga_slug = fetch(:sentry_organization) || fetch(:application)
42
+ sentry_host = ENV['SENTRY_HOST'] || fetch(:sentry_host, 'https://sentry.io')
43
+ organization_slug = fetch(:sentry_organization) || fetch(:application)
32
44
  project = fetch(:sentry_project) || fetch(:application)
33
45
  environment = fetch(:stage) || 'default'
34
46
  api_token = ENV['SENTRY_API_TOKEN'] || fetch(:sentry_api_token)
35
- repo_name = fetch(:sentry_repo) || fetch(:repo_url).split(':').last.gsub(/\.git$/, '')
47
+ repo_integration_enabled = fetch(:sentry_repo_integration, true)
48
+ release_refs = fetch(:sentry_release_refs, [{
49
+ repository: fetch(:sentry_repo) || fetch(:repo_url).split(':').last.delete_suffix('.git'),
50
+ commit: head_revision,
51
+ previousCommit: prev_revision
52
+ }])
53
+ release_version = fetch(:sentry_release_version) || head_revision
54
+ deploy_name = fetch(:sentry_deploy_name) || "#{release_version}-#{fetch(:release_timestamp)}"
55
+
56
+ uri = URI.parse(sentry_host)
57
+ http = Net::HTTP.new(uri.host, uri.port)
58
+ http.use_ssl = true
36
59
 
37
60
  headers = {
38
- 'Content-Type' => 'application/json',
61
+ 'Content-Type' => 'application/json',
39
62
  'Authorization' => 'Bearer ' + api_token.to_s
40
63
  }
41
64
 
42
- req = Net::HTTP::Post.new("/api/0/organizations/#{orga_slug}/releases/", headers)
43
- req.body = JSON.generate(
44
- version: version,
45
- refs: [{
46
- repository: repo_name,
47
- commit: fetch(:current_revision) || `git rev-parse HEAD`.strip,
48
- # previousCommit: fetch(:previous_revision)
49
- }],
65
+ req = Net::HTTP::Post.new("/api/0/organizations/#{organization_slug}/releases/", headers)
66
+ body = {
67
+ version: release_version,
50
68
  projects: [project]
51
- )
69
+ }
70
+ body[:refs] = release_refs if repo_integration_enabled
71
+ req.body = JSON.generate(body)
52
72
  response = http.request(req)
53
73
  if response.is_a? Net::HTTPSuccess
54
- info 'Uploaded release infos to Sentry'
55
- req = Net::HTTP::Post.new("/api/0/organizations/#{orga_slug}/releases/#{version}/deploys/", headers)
74
+ info "Notified Sentry of new release: #{release_version}"
75
+ req = Net::HTTP::Post.new(
76
+ "/api/0/organizations/#{organization_slug}/releases/#{release_version}/deploys/",
77
+ headers
78
+ )
56
79
  req.body = JSON.generate(
57
80
  environment: environment,
58
- name: "#{version}-#{fetch(:release_timestamp)}"
81
+ name: deploy_name
59
82
  )
60
83
  response = http.request(req)
61
84
  if response.is_a? Net::HTTPSuccess
62
- info 'Uploaded deployment infos to Sentry'
85
+ info "Notified Sentry of new deployment: #{deploy_name}"
63
86
  else
64
87
  warn "Cannot notify sentry for new deployment. Response: #{response.code.inspect}: #{response.body}"
65
88
  end
@@ -69,8 +92,3 @@ namespace :sentry do
69
92
  end
70
93
  end
71
94
  end
72
-
73
- # If you want deployments to be published in every Rails environment, put this
74
- # in config/deploy.rb, otherwise put it your environment-specific deploy file
75
- # i.e. config/deploy/production.rb
76
- # after 'deploy:published', 'sentry:notice_deployment'
@@ -1,11 +1,12 @@
1
- require 'test_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- class Capistrano::SentryTest < Minitest::Test
4
- def test_that_it_has_a_version_number
5
- refute_nil ::Capistrano::Sentry::VERSION
6
- end
3
+ require 'test_helper'
4
+ require 'capistrano/sentry/version'
7
5
 
8
- def test_it_does_something_useful
9
- assert false
6
+ module Capistrano
7
+ class SentryTest < Minitest::Test
8
+ def test_that_it_has_a_version_number
9
+ assert !::Capistrano::Sentry::VERSION.nil?
10
+ end
10
11
  end
11
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
4
  require 'capistrano/sentry'
3
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-sentry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brice Texier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-19 00:00:00.000000000 Z
11
+ date: 2020-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -56,25 +56,26 @@ dependencies:
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
69
- description:
68
+ version: '10'
69
+ description: Sentry release/deployment integration
70
70
  email:
71
71
  - brice@codeur.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".github/workflows/test.yml"
76
77
  - ".gitignore"
77
- - ".travis.yml"
78
+ - ".rubocop.yml"
78
79
  - CODE_OF_CONDUCT.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
@@ -108,11 +109,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  - !ruby/object:Gem::Version
109
110
  version: '0'
110
111
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.7.6
112
+ rubygems_version: 3.0.3
113
113
  signing_key:
114
114
  specification_version: 4
115
- summary: Sentry release/deployment integration
115
+ summary: Push release and deployment information on Sentry on each deploy
116
116
  test_files:
117
117
  - test/capistrano/sentry_test.rb
118
118
  - test/test_helper.rb
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5.1
7
- before_install: gem install bundler -v 1.17.1