heroku-stage 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83eb5ffcfa3d8b8b20e4842c0dde8959e31d9664
4
+ data.tar.gz: ecf4b7077f0f9d55f9ea24f5b4d52e55fbf5851e
5
+ SHA512:
6
+ metadata.gz: 831bd6fe38287543da56604868ad15715dd1b332aacf111745f46a898f0ec2952f2662367718d6536728cb8284ec8ceb3a445653d5d2d977a9862a1a2c8fc091
7
+ data.tar.gz: 2e3e0f9036053cd08a376e1ba1443981897c77ec3f349b319a5d5502dfc14ba46f6166e84e4362bc9f04aa8500dc30de8a7a2927b3dc4b47884e4cd82fb530e0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.6
4
+ - 2.3.3
5
+ - 2.4.0-preview3
6
+ script:
7
+ - bundle exec rake spec
8
+ deploy:
9
+ provider: rubygems
10
+ api_key:
11
+ secure: gkWXoXo5OmksiDkLkDPBaXr2mO14N+y9OyX5YCbPtQXgj1p+jFUgtfRZifTImwtEWzUuzJJ+39k6kCrfC7tlA8WqWrggednyEAXCmG+klCiZm5wPG+23sbQzZimJGBdcy3ZBWBpLC7pgCn1y2x4SxV/FOTDDDFo1My/A/ZXpxYL1XLUtE9tqMxYRGbdmjsEKKl3I1MtjwvDPN3PDofrdYJMC1oBIAgqkyobTP+RHFK3WnRCh871DFyR5cR7j+HsJ8jZklWOuYHpYx5qWcs9g+u54TRWMNdMFArq6q6bRoPmrPpWCv2EdHg7bnntpgphmh3MfBb7ZLe6vQO6tA/qfYm6n/w5R/y8a2teXMFzTnm9UL2Nhuh8PnudKqatTtBpR2xa8OcM+iS/kqEe5z5OsUtjEDVK0HVzbOOzHB1gfo8UAOEs4uH7SAxgiFs4zuLJUt/Cles2BuWoEmAnljuIsxpfhcWlRPLsaLy2CufMuf5FhKDxcmdOIQCY0PYrcyWgBWo+HxCz00Q3xOfm6HcMIITjZR5qCbEkaZYU8AZBoCGrLhYDBS6BBBxNPklQ9usMWuhio075zt9dh8dmoLDzOk2VaGXPD/b9kVVs25DqBNejPhsQnIEJnX4D/uO3hstdnLjd3LQtWoYuPDsEIWuU0642xXG6wb23/66E5GDC0c4Y=
12
+ gem: heroku-stage
13
+ on:
14
+ tags: true
15
+ repo: platanus/heroku-stage
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ### v0.1.0
6
+
7
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in heroku-stage.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2016 Platanus
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,113 @@
1
+ # Heroku Stage
2
+ [![Build Status](https://travis-ci.org/platanus/heroku-stage.svg?branch=master)](https://travis-ci.org/platanus/heroku-stage)
3
+
4
+ Get the current deployment stage of your rails app deployed using heroku pipelines.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ gem install heroku-stage
10
+ ```
11
+
12
+ Or add to your Gemfile:
13
+
14
+ ```ruby
15
+ gem "heroku-stage"
16
+ ```
17
+
18
+ ```bash
19
+ bundle install
20
+ ```
21
+
22
+ ## Why
23
+
24
+ We've been following the heroku's recommendation on running just one
25
+ environment for our apps *productions*. We've moved from having
26
+ `staging.rb` and `production.rb` to just have the `production.rb`.
27
+ The goal is to promote parity between the two environments. At the end,
28
+ we have different **deployment** environments but the same rails one.
29
+
30
+ This approach makes it difficult when you have to differentiate
31
+ some actions based on your deploy environment. We cannot rely on `Rails.env`
32
+ anymore because it will always be `production`.
33
+
34
+ One example is for error monitoring. If we want to know from which
35
+ environment the errors are, we need to provide that information somehow.
36
+
37
+ The idea is to take the same syntax from `Rails.env` but with
38
+ `Heroku.stage`
39
+
40
+ This gem uses the `HEROKU_APP_NAME` environmental variable to get the
41
+ current stage on the heroku pipeline.
42
+
43
+ ## The convention
44
+
45
+ The application name convention is `my-app-<stage>`.
46
+
47
+ You can manually add the environmental variable `HEROKU_APP_NAME` with the app name
48
+ or you can use the [dyno metadata labs](https://devcenter.heroku.com/articles/dyno-metadata)
49
+ from heroku which will add the variable on your next deploy.
50
+
51
+ ```shell
52
+ heroku labs:enable runtime-dyno-metadata --app <your app>
53
+ heroku labs:enable runtime-dyno-metadata --remote production
54
+ ```
55
+
56
+ > *Note*: Heroku does not provide the information on what stage the app is running,
57
+ > so this gem relies on that convention. I've contacted heroku requesting this information
58
+ > but I haven't had any response.
59
+
60
+ ## Usage
61
+
62
+ To get the current state
63
+
64
+ ```ruby
65
+ Heroku.stage # => 'production'
66
+ ```
67
+
68
+ You can ask for the production or staging stages
69
+
70
+ ```ruby
71
+ Heroku.stage.production? # => true
72
+ Heroku.stage.staging? # => false
73
+ ```
74
+
75
+ ### In development
76
+
77
+ When using in the *development* rails environment the `Heroku.stage` will
78
+ respond with an empty string.
79
+
80
+ ```ruby
81
+ Rails.env.development? # true
82
+ Heroku.stage # => ''
83
+ ```
84
+
85
+ ## Testing
86
+
87
+ To run the specs you need to execute, **in the root path of the gem**, the following command:
88
+
89
+ ```bash
90
+ bundle exec guard
91
+ ```
92
+
93
+ You need to put **all your tests** in the `/my_gem/spec/` directory.
94
+
95
+ ## Contributing
96
+
97
+ 1. Fork it
98
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
99
+ 1. Commit your changes (`git commit -am 'Add some feature'`)
100
+ 1. Push to the branch (`git push origin my-new-feature`)
101
+ 1. Create new Pull Request
102
+
103
+ ## Credits
104
+
105
+ Thank you [contributors](https://github.com/platanus/heroku-stage/graphs/contributors)!
106
+
107
+ <img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
108
+
109
+ Heroku Stage is maintained by [platanus](http://platan.us).
110
+
111
+ ## License
112
+
113
+ Heroku Stage is © 2016 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "heroku/stage"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "heroku/stage/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "heroku-stage"
8
+ spec.version = Heroku::Stage::VERSION
9
+ spec.authors = ["Platanus", "Juan Ignacio Donoso"]
10
+ spec.email = ["rubygems@platan.us", "juan.ignacio@platan.us"]
11
+ spec.homepage = "https://github.com/platanus/heroku-stage"
12
+ spec.summary = "Read stage name from heroku pipelines"
13
+ spec.description = "Based on convention this gem will get the heroku pipeline stage from the app name"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rails"
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.4"
26
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
27
+ spec.add_development_dependency "pry"
28
+ end
@@ -0,0 +1,37 @@
1
+ require 'heroku/stage/version'
2
+ require 'active_support'
3
+ require 'rails'
4
+
5
+ module Heroku
6
+ class << self
7
+ # Returns the current Heroku stage.
8
+ #
9
+ # Heroku.stage # => "staging"
10
+ # Heroku.stage.staging? # => true
11
+ # Heroku.stage.production? # => false
12
+ def stage
13
+ @_stage ||= ActiveSupport::StringInquirer.new(heroku_pipeline_stage)
14
+ end
15
+
16
+ private
17
+
18
+ def heroku_pipeline_stage
19
+ Rails.env.development? ? '' : ENV.fetch('HEROKU_APP_NAME')[/staging|production/]
20
+ rescue KeyError
21
+ raise $!, enable_dyno_metadata_message($!), $!.backtrace
22
+ end
23
+
24
+ def enable_dyno_metadata_message(exception)
25
+ <<~EOS
26
+ #{exception.message}
27
+
28
+ Remember to enable the heroku dyno metadata to add the HEROKU_APP_NAME key to the environment.
29
+ To do that run the folowing command:
30
+
31
+ heroku labs:enable runtime-dyno-metadata --remote production
32
+
33
+ On the next deploy the key will be populated with the app name
34
+ EOS
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Heroku
2
+ module Stage
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku-stage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Platanus
8
+ - Juan Ignacio Donoso
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.4'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.4'
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard-rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '4.7'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '4.7'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Based on convention this gem will get the heroku pipeline stage from
99
+ the app name
100
+ email:
101
+ - rubygems@platan.us
102
+ - juan.ignacio@platan.us
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - ".ruby-version"
109
+ - ".travis.yml"
110
+ - CHANGELOG.md
111
+ - Gemfile
112
+ - Guardfile
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - bin/console
117
+ - bin/setup
118
+ - heroku-stage.gemspec
119
+ - lib/heroku/stage.rb
120
+ - lib/heroku/stage/version.rb
121
+ homepage: https://github.com/platanus/heroku-stage
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.5
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Read stage name from heroku pipelines
145
+ test_files: []