rack-commithash-endpoint 0.1.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 +7 -0
- data/.DS_Store +0 -0
- data/.devcontainer/devcontainer.json +22 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +107 -0
- data/Rakefile +12 -0
- data/lib/rack/commithash/endpoint/version.rb +9 -0
- data/lib/rack/commithash/endpoint.rb +67 -0
- data/sig/rack/commithash/endpoint.rbs +27 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f8e8034f776ae71e00f9b2ab14f3d3a6f6a190d2809748bb6bed093b539066df
|
4
|
+
data.tar.gz: c6b4dd07ad39cd7d36a5ba9239618226b0269e15c52b022243089c156130fbf2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44231e62a45e5b18685fd70c70b2805837ef90c1997ac2e7f25949efb25e57f5012b24bb29ad59cd86d811e964bc23dc0ffead042b955060205f3062b6752f33
|
7
|
+
data.tar.gz: f20e14edf6a84d7ce24b5ae8f0ac80ff8d0486af179ede410a2d00c3ee671d5a0ca24bec81b7b218217933778ad3040ac3cb64f4a80a6cf70e049f0ab4833133
|
data/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
2
|
+
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby
|
3
|
+
{
|
4
|
+
"name": "Ruby",
|
5
|
+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
6
|
+
"image": "mcr.microsoft.com/devcontainers/ruby:1-3.1-bookworm"
|
7
|
+
|
8
|
+
// Features to add to the dev container. More info: https://containers.dev/features.
|
9
|
+
// "features": {},
|
10
|
+
|
11
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
12
|
+
// "forwardPorts": [],
|
13
|
+
|
14
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
15
|
+
// "postCreateCommand": "ruby --version",
|
16
|
+
|
17
|
+
// Configure tool-specific properties.
|
18
|
+
// "customizations": {},
|
19
|
+
|
20
|
+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
21
|
+
// "remoteUser": "root"
|
22
|
+
}
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Shirakawa Hiroyuki
|
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,107 @@
|
|
1
|
+
# Rack::Commithash::Endpoint
|
2
|
+
|
3
|
+
Rack middleware to return git commit hash.
|
4
|
+
|
5
|
+
A simple Rack middleware that exposes the current git commit hash of your application through an HTTP endpoint. This is useful for identifying which version of your application is deployed in various environments.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rack-commithash-endpoint'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
gem install rack-commithash-endpoint
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
### Basic Usage
|
30
|
+
|
31
|
+
Add the middleware to your Rack application:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# config.ru or similar
|
35
|
+
require 'rack/commithash/endpoint'
|
36
|
+
|
37
|
+
use Rack::Commithash::Endpoint
|
38
|
+
run YourApp
|
39
|
+
```
|
40
|
+
|
41
|
+
This will make the `/__revision__` endpoint available in all environments where the initializer is loaded.
|
42
|
+
|
43
|
+
|
44
|
+
With this configuration, the commit hash will be available at `/__revision__` and will be read from the `COMMIT_HASH` environment variable.
|
45
|
+
|
46
|
+
By default, the response will be in JSON format:
|
47
|
+
|
48
|
+
```
|
49
|
+
GET /__revision__
|
50
|
+
|
51
|
+
{"revision":"abc123"}
|
52
|
+
Content-Type: application/json
|
53
|
+
```
|
54
|
+
|
55
|
+
#### Rails Integration
|
56
|
+
|
57
|
+
If you're using Rails, you can add the middleware in an initializer to expose the commit hash endpoint for your app:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
# config/initializers/commithash_endpoint.rb
|
61
|
+
Rails.configuration.middleware.insert(0, Rack::Commithash::Endpoint)
|
62
|
+
```
|
63
|
+
|
64
|
+
**Note:**
|
65
|
+
By inserting the middleware at position `0`, it is placed before all other middlewares, including `ActionDispatch::SSL` (which is automatically added when `config.force_ssl = true` is set).
|
66
|
+
This ensures that the commit hash endpoint is accessible even if SSL redirection is enabled, as requests to this endpoint will not be redirected to HTTPS before reaching the middleware.
|
67
|
+
|
68
|
+
### Advanced Configuration
|
69
|
+
|
70
|
+
You can customize both the endpoint path and the environment variable name:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
use Rack::Commithash::Endpoint, path: '/__version__', env_var: 'APP_REVISION'
|
74
|
+
```
|
75
|
+
|
76
|
+
You can also return the commit hash as plain text by setting `json_format: false`:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
use Rack::Commithash::Endpoint, json_format: false
|
80
|
+
```
|
81
|
+
|
82
|
+
This will return:
|
83
|
+
|
84
|
+
```
|
85
|
+
GET /__revision__
|
86
|
+
|
87
|
+
abc123
|
88
|
+
Content-Type: text/plain
|
89
|
+
```
|
90
|
+
|
91
|
+
## Development
|
92
|
+
|
93
|
+
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.
|
94
|
+
|
95
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
96
|
+
|
97
|
+
## Contributing
|
98
|
+
|
99
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rack-commithash-endpoint. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rack-commithash-endpoint/blob/main/CODE_OF_CONDUCT.md).
|
100
|
+
|
101
|
+
## License
|
102
|
+
|
103
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
104
|
+
|
105
|
+
## Code of Conduct
|
106
|
+
|
107
|
+
Everyone interacting in the Rack::Commithash::Endpoint project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rack-commithash-endpoint/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'endpoint/version'
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
module Commithash
|
7
|
+
# Rack::Commithash provides a middleware that exposes the current Git commit hash
|
8
|
+
# through a configurable endpoint. This is useful for identifying the exact version
|
9
|
+
# of your application in production environments, facilitating debugging and deployment tracking.
|
10
|
+
class Endpoint
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
DEFAULT_REQUEST_PATH = '/__revision__'
|
14
|
+
DEFAULT_ENV_VAR = 'COMMIT_HASH'
|
15
|
+
|
16
|
+
# @param [#call] app
|
17
|
+
# @param [String] env_var
|
18
|
+
# @param [String] path
|
19
|
+
# @param [Boolean] json_format
|
20
|
+
def initialize(
|
21
|
+
app,
|
22
|
+
env_var: DEFAULT_ENV_VAR,
|
23
|
+
path: DEFAULT_REQUEST_PATH,
|
24
|
+
json_format: true
|
25
|
+
)
|
26
|
+
@app = app
|
27
|
+
@path = path
|
28
|
+
commit_hash = ENV[env_var] || 'unknown'
|
29
|
+
@body, @length, @content_type = build_response(commit_hash, json_format)
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param [Hash] env Rack env.
|
33
|
+
# @return [Array] Rack response.
|
34
|
+
def call(env)
|
35
|
+
if env['PATH_INFO'] == @path
|
36
|
+
[
|
37
|
+
200,
|
38
|
+
{
|
39
|
+
'content-length' => @length,
|
40
|
+
'content-type' => @content_type
|
41
|
+
},
|
42
|
+
[@body]
|
43
|
+
]
|
44
|
+
else
|
45
|
+
@app.call(env)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Builds the response body, length, and content type based on the commit hash and format.
|
52
|
+
# @param [String] commit_hash The commit hash to include in the response.
|
53
|
+
# @param [Boolean] json_format Whether to return the response in JSON format.
|
54
|
+
# @return [Array] An array containing the response body, its length, and content type.
|
55
|
+
def build_response(commit_hash, json_format)
|
56
|
+
if json_format
|
57
|
+
body = "{\"revision\":\"#{commit_hash}\"}"
|
58
|
+
content_type = 'application/json'
|
59
|
+
else
|
60
|
+
body = commit_hash
|
61
|
+
content_type = 'text/plain'
|
62
|
+
end
|
63
|
+
[body, body.bytesize.to_s, content_type]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rack
|
2
|
+
module Commithash
|
3
|
+
class Endpoint
|
4
|
+
class Error < ::StandardError; end
|
5
|
+
|
6
|
+
DEFAULT_REQUEST_PATH: String
|
7
|
+
DEFAULT_ENV_VAR: String
|
8
|
+
|
9
|
+
def initialize: (
|
10
|
+
app: untyped,
|
11
|
+
env_var: String named 'env_var' = DEFAULT_ENV_VAR,
|
12
|
+
path: String named 'path' = DEFAULT_REQUEST_PATH,
|
13
|
+
json_format: bool named 'json_format' = true
|
14
|
+
) -> void
|
15
|
+
|
16
|
+
def call: (env: Hash[String, untyped]) -> [String, Hash[String, String], Array[String]]
|
17
|
+
|
18
|
+
private
|
19
|
+
def build_response: (commit_hash: String, json_format: bool) -> [String, String, String]
|
20
|
+
end
|
21
|
+
|
22
|
+
module Endpoint
|
23
|
+
VERSION: String
|
24
|
+
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-commithash-endpoint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shirakawa Hiroyuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Rack middleware to return commit hash.
|
14
|
+
email:
|
15
|
+
- shrkwh@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".DS_Store"
|
21
|
+
- ".devcontainer/devcontainer.json"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- CHANGELOG.md
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/rack/commithash/endpoint.rb
|
29
|
+
- lib/rack/commithash/endpoint/version.rb
|
30
|
+
- sig/rack/commithash/endpoint.rbs
|
31
|
+
homepage: https://github.com/shrkw/rack-commithash-endpoint
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata:
|
35
|
+
homepage_uri: https://github.com/shrkw/rack-commithash-endpoint
|
36
|
+
source_code_uri: https://github.com/shrkw/rack-commithash-endpoint
|
37
|
+
changelog_uri: https://github.com/shrkw/rack-commithash-endpoint/blob/master/CHANGELOG.md
|
38
|
+
rubygems_mfa_required: 'true'
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.3.27
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Rack middleware to return commit hash.
|
58
|
+
test_files: []
|