rails_app_version 1.2.0 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -45
- data/config/app_version.yml +5 -0
- data/lib/rails_app_version/app_info_middleware.rb +5 -4
- data/lib/rails_app_version/railtie.rb +8 -1
- data/lib/rails_app_version/version.rb +2 -2
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bad17b9f85b940ae01cd9fe6dad8ef04143eba4780b79259e020339a754bdf6
|
4
|
+
data.tar.gz: 651b75a9acc0c1afae576bcdbea83ef91bda0d4c7a36040dea64e2faac39c7cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a9c0d991be2a9d744101219b84fe45849ab39337163d516456b98e3f4b76ffdc64cf06e8de69dea1ec38f763dd9175797f04554fc27b0d67f3ea7dc7c6d5884
|
7
|
+
data.tar.gz: 5aeafa9a3363f2fa6cb76b5034e09890385511db3cd6559d2880487cfcc1c2cd2cbefff8a95e5f9ff217722c6f515cd3961ebea0141f61a4fa318a11d38f6a8b
|
data/README.md
CHANGED
@@ -33,6 +33,14 @@ class AssetManifest
|
|
33
33
|
"/assets/#{path}?v=#{Rails.application.version.to_cache_key}"
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
# Or in your controller
|
38
|
+
|
39
|
+
def index
|
40
|
+
Rails.cache.fetch("index-page#{Rails.application.version.to_cache_key}") do
|
41
|
+
render :index
|
42
|
+
end
|
43
|
+
end
|
36
44
|
```
|
37
45
|
|
38
46
|
## Installation
|
@@ -48,7 +56,7 @@ Then execute:
|
|
48
56
|
```bash
|
49
57
|
$ bundle install
|
50
58
|
$ rails app:version:config # Copies the default configuration file
|
51
|
-
$ echo "1.0.0" > VERSION
|
59
|
+
$ echo "1.0.0" > VERSION # Create initial version file
|
52
60
|
```
|
53
61
|
|
54
62
|
## Version Management
|
@@ -61,7 +69,6 @@ The recommended approach is to maintain a `VERSION` file in your application's r
|
|
61
69
|
only the version number:
|
62
70
|
|
63
71
|
```plaintext
|
64
|
-
# VERSION
|
65
72
|
1.2.3
|
66
73
|
```
|
67
74
|
|
@@ -128,7 +135,7 @@ Rails.application.version.to_cache_key # => "1-2-3"
|
|
128
135
|
## Version Headers Middleware
|
129
136
|
|
130
137
|
Rails AppVersion includes an optional middleware that adds version and environment information to HTTP response headers.
|
131
|
-
This is particularly useful in staging and
|
138
|
+
This is particularly useful in staging and pre-production environments to verify deployment success and track which version
|
132
139
|
of the application is serving requests.
|
133
140
|
|
134
141
|
### Configuring the Middleware
|
@@ -138,12 +145,7 @@ Enable and configure the middleware in your `config/app_version.yml`:
|
|
138
145
|
```yaml
|
139
146
|
development:
|
140
147
|
middleware:
|
141
|
-
enabled:
|
142
|
-
options:
|
143
|
-
include_revision: true # Include git revision in headers
|
144
|
-
version_header: X-App-Version
|
145
|
-
environment_header: X-App-Environment
|
146
|
-
revision_header: X-App-Revision
|
148
|
+
enabled: false
|
147
149
|
|
148
150
|
staging:
|
149
151
|
middleware:
|
@@ -161,8 +163,7 @@ You can also add the middleware manually in your application configuration:
|
|
161
163
|
# config/application.rb or config/environments/staging.rb
|
162
164
|
config.middleware.use RailsAppVersion::AppInfoMiddleware, {
|
163
165
|
version_header: 'X-Custom-Version',
|
164
|
-
environment_header: 'X-Custom-Environment'
|
165
|
-
include_revision: true
|
166
|
+
environment_header: 'X-Custom-Environment'
|
166
167
|
}
|
167
168
|
```
|
168
169
|
|
@@ -171,7 +172,7 @@ The middleware will add the following headers to each response:
|
|
171
172
|
- X-App-Version: Current application version, optionally including revision (e.g., "1.2.3" or "1.2.3 (abc123de)")
|
172
173
|
- X-App-Environment: Current environment (e.g., "staging")
|
173
174
|
|
174
|
-
When `
|
175
|
+
When `show_revision` is enabled, the version header will include the first 8 characters of the git revision in
|
175
176
|
parentheses. This provides a quick way to verify both the version and the specific deployment in a single header.
|
176
177
|
|
177
178
|
This makes it easy for developers to verify which version is deployed and running in each environment, particularly
|
@@ -211,39 +212,6 @@ Rails AppVersion supports several version formats:
|
|
211
212
|
Version strings are parsed according to Semantic Versioning principles and maintain compatibility with `Gem::Version`
|
212
213
|
for comparison operations.
|
213
214
|
|
214
|
-
## Version Headers
|
215
|
-
|
216
|
-
Enable version headers in HTTP responses to verify deployments and track running versions:
|
217
|
-
|
218
|
-
```yaml
|
219
|
-
# config/app_version.yml
|
220
|
-
development:
|
221
|
-
middleware:
|
222
|
-
enabled: true
|
223
|
-
options:
|
224
|
-
include_revision: true
|
225
|
-
|
226
|
-
staging:
|
227
|
-
middleware:
|
228
|
-
enabled: true
|
229
|
-
```
|
230
|
-
|
231
|
-
Or add the middleware manually:
|
232
|
-
|
233
|
-
```ruby
|
234
|
-
# config/application.rb
|
235
|
-
config.middleware.use RailsAppVersion::AppInfoMiddleware, {
|
236
|
-
version_header: 'X-App-Version',
|
237
|
-
environment_header: 'X-App-Environment',
|
238
|
-
include_revision: true
|
239
|
-
}
|
240
|
-
```
|
241
|
-
|
242
|
-
Headers added:
|
243
|
-
|
244
|
-
- X-App-Version: "1.2.3" (or "1.2.3 (abc123de)" with revision)
|
245
|
-
- X-App-Environment: "production"
|
246
|
-
|
247
215
|
## Contributing
|
248
216
|
|
249
217
|
We welcome contributions! Here's how you can help:
|
data/config/app_version.yml
CHANGED
@@ -3,3 +3,8 @@ shared:
|
|
3
3
|
revision: <%= Rails.root.join('REVISION').read.strip rescue (`git rev-parse HEAD`.strip rescue '0') %>
|
4
4
|
show_revision: <%= Rails.env.local? %>
|
5
5
|
environment: <%= ENV.fetch('RAILS_APP_ENV', Rails.env) %>
|
6
|
+
middleware:
|
7
|
+
enabled: true
|
8
|
+
options:
|
9
|
+
version_header: X-App-Version
|
10
|
+
environment_header: X-App-Environment
|
@@ -4,22 +4,23 @@ module RailsAppVersion
|
|
4
4
|
class AppInfoMiddleware
|
5
5
|
DEFAULT_OPTIONS = {
|
6
6
|
version_header: "X-App-Version",
|
7
|
-
environment_header: "X-App-Environment"
|
8
|
-
revision_header: "X-App-Revision",
|
9
|
-
include_revision: false
|
7
|
+
environment_header: "X-App-Environment"
|
10
8
|
}.freeze
|
11
9
|
|
12
10
|
def initialize(app, options = {})
|
13
|
-
@app = app
|
14
11
|
@options = DEFAULT_OPTIONS.merge(options)
|
12
|
+
@app = app
|
15
13
|
end
|
16
14
|
|
17
15
|
def call(env)
|
16
|
+
# Call the next middleware in the chain first
|
18
17
|
status, headers, response = @app.call(env)
|
19
18
|
|
19
|
+
# Add our custom headers to the response
|
20
20
|
headers[@options[:version_header]] = Rails.application.version.full
|
21
21
|
headers[@options[:environment_header]] = Rails.application.env
|
22
22
|
|
23
|
+
# Return the modified response
|
23
24
|
[ status, headers, response ]
|
24
25
|
end
|
25
26
|
end
|
@@ -45,9 +45,16 @@ module RailsAppVersion
|
|
45
45
|
all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
|
46
46
|
all_configs[:shared]
|
47
47
|
end
|
48
|
-
|
49
48
|
@version = RailsAppVersion::Version.create(@app_config[:version], @app_config[:revision])
|
50
49
|
@env = ActiveSupport::StringInquirer.new(@app_config.fetch(:environment, Rails.env))
|
51
50
|
end
|
51
|
+
|
52
|
+
initializer "middleware" do |app|
|
53
|
+
# Add the middleware to the stack if enabled
|
54
|
+
if @app_config.dig(:middleware, :enabled)
|
55
|
+
options = @app_config.dig(:middleware, :options) || {}
|
56
|
+
app.middleware.insert_before Rails::Rack::Logger, RailsAppVersion::AppInfoMiddleware, **options
|
57
|
+
end
|
58
|
+
end
|
52
59
|
end
|
53
60
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RailsAppVersion
|
4
|
-
VERSION = "1.2.
|
4
|
+
VERSION = "1.2.2"
|
5
5
|
|
6
6
|
class Version < Gem::Version
|
7
7
|
attr_reader :major, :minor, :patch, :pre, :revision
|
@@ -27,7 +27,7 @@ module RailsAppVersion
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def short_revision
|
30
|
-
revision
|
30
|
+
revision.to_s.slice(0, 8)
|
31
31
|
end
|
32
32
|
|
33
33
|
def prerelease?
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_app_version
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdelkader Boudih
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
10
|
+
date: 2024-12-31 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: railties
|
@@ -81,7 +80,6 @@ metadata:
|
|
81
80
|
source_code_uri: https://github.com/seuros/rails_app_version
|
82
81
|
changelog_uri: https://github.com/seuros/rails_app_version/blob/master/CHANGELOG.md
|
83
82
|
rubygems_mfa_required: 'true'
|
84
|
-
post_install_message:
|
85
83
|
rdoc_options: []
|
86
84
|
require_paths:
|
87
85
|
- lib
|
@@ -96,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
94
|
- !ruby/object:Gem::Version
|
97
95
|
version: '0'
|
98
96
|
requirements: []
|
99
|
-
rubygems_version: 3.
|
100
|
-
signing_key:
|
97
|
+
rubygems_version: 3.6.2
|
101
98
|
specification_version: 4
|
102
99
|
summary: Get the version of your Rails app
|
103
100
|
test_files: []
|