Last active
October 22, 2018 09:02
-
-
Save cannikin/2fc8134491943c04814b to your computer and use it in GitHub Desktop.
Notify Sentry of a new release via Capistrano
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This task will notify Sentry via their API[1] that you have deployed | |
# a new release. It uses the release timestamp as the `version` | |
# (like 20151113182847) and the git ref as the optional `ref` value. | |
# | |
# This task requires several environment variables be set (or just | |
# hardcode the values in here if you like living on the edge): | |
# | |
# ENV['SENTRY_API_ENDPOINT'] : API endpoint, https://app.getsentry.com | |
# ENV['SENTRY_ORG'] : the organization for this app | |
# ENV['SENTRY_PROJECT'] : the project for this app | |
# ENV['SENTRY_API_KEY'] : your API key (not DSN) [2] | |
# | |
# [1]: https://docs.getsentry.com/hosted/api/releases/post-project-releases | |
# [2]: https://app.getsentry.com/organizations/YOUR-ORG-SLUG/api-keys | |
# For Rails app, this goes in config/deploy.rb | |
namespace :sentry do | |
task :notify_deployment do | |
run_locally do | |
require 'uri' | |
require 'net/https' | |
puts "Notifying Sentry of release..." | |
uri = URI.parse(ENV['SENTRY_API_ENDPOINT']) | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
req = Net::HTTP::Post.new("/api/0/projects/#{ENV['SENTRY_ORG']}/#{ENV['SENTRY_PROJECT']}/releases/", initheader={'Content-Type' =>'application/json'}) | |
req.basic_auth(ENV['SENTRY_API_KEY'], '') | |
req.body = %Q[{"version":"#{fetch(:release_timestamp)}","ref":"#{fetch(:current_revision)}"}] | |
response = http.start { |h| h.request(req) } | |
puts "Sentry response: #{response.body}" | |
end | |
end | |
end | |
# 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 | |
after 'deploy:published', 'sentry:notify_deployment' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks @cannikin, a fork with auth token (instead of api key) can be found here https://gist.github.com/pablopaul/892d7f8b3f031985f1c690cbeff9ef9e