shalala 1.0.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/README.md +67 -0
- data/Rakefile +7 -0
- data/app/controllers/shalala/commits_controller.rb +58 -0
- data/config/routes.rb +5 -0
- data/lib/shalala/engine.rb +17 -0
- data/lib/shalala/version.rb +5 -0
- data/lib/shalala.rb +7 -0
- data/shalala.gemspec +30 -0
- metadata +76 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8ca88e78836e4744c0c07f92c5dce712b346f3667d892ecd3dbf9764d4cff1ec
|
|
4
|
+
data.tar.gz: 97957e540122129c3e200f840b5eb269b4577d58daec08a540d584a1568191bc
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: af34805ae8b66e2183dcc8f582950fda18ba1fc96e318d4f0e2d2094ff19f0522ad40846ec742e07a72cfbf1a0c4d7d8d804507a0a2b1d42e3fb8b48dfe4c28b
|
|
7
|
+
data.tar.gz: e67655ec1ac7627196ff8fbea71881db4ce8e2cd5a1646e6cb9eb9c99bd77992d0423468e2fa3cf2e691cc390dd83fd6dbd9f88b50ab059c5fdde66fb77e1b41
|
data/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Shalala
|
|
2
|
+
|
|
3
|
+
Shalala is a Rails engine that exposes the current git commit SHA and branch name at `/commit`.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
When you request `GET /commit`:
|
|
8
|
+
|
|
9
|
+
- If `GIT_COMMIT` is set, it returns that value.
|
|
10
|
+
- If `GIT_BRANCH` is set, it returns that value for the branch.
|
|
11
|
+
- If `GIT_COMMIT` is not set and the Rails environment is development, it runs `git rev-parse HEAD` and returns the current SHA.
|
|
12
|
+
- If `GIT_BRANCH` is not set, it derives the branch from git (`git branch --show-current`, with `git rev-parse --abbrev-ref HEAD` as fallback).
|
|
13
|
+
- If `GIT_COMMIT` is not set and the environment is not development, it returns `404 Not Found`.
|
|
14
|
+
|
|
15
|
+
This is useful for surfacing deployment version information in environments like staging and production.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add this line to your application Gemfile:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
gem "shalala"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then install:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
bundle install
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Mounting
|
|
32
|
+
|
|
33
|
+
The engine mounts itself at `/commit` via an initializer, so no manual route declaration is required.
|
|
34
|
+
|
|
35
|
+
## Usage examples
|
|
36
|
+
|
|
37
|
+
Set the commit explicitly (recommended for CI/CD and production):
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
export GIT_COMMIT=$(git rev-parse HEAD)
|
|
41
|
+
export GIT_BRANCH=$(git branch --show-current)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Then request:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
curl http://localhost:3000/commit
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Example response:
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
commit: f2e9b8d4a3c11f2f9c2fd6f5b76f6f3cf1a1d9e2
|
|
54
|
+
branch: main
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Testing
|
|
58
|
+
|
|
59
|
+
Run the test suite with:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
bundle exec rspec
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
MIT
|
data/Rakefile
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Shalala
|
|
4
|
+
class CommitsController < ActionController::Base
|
|
5
|
+
def show
|
|
6
|
+
commit = resolved_commit
|
|
7
|
+
branch = resolved_branch
|
|
8
|
+
|
|
9
|
+
if commit.present?
|
|
10
|
+
render plain: "commit: #{commit}\nbranch: #{branch}"
|
|
11
|
+
else
|
|
12
|
+
head :not_found
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def resolved_commit
|
|
19
|
+
env_commit = ENV["GIT_COMMIT"]
|
|
20
|
+
return env_commit if env_commit.present?
|
|
21
|
+
return current_git_commit if development_environment?
|
|
22
|
+
|
|
23
|
+
nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def resolved_branch
|
|
27
|
+
env_branch = ENV["GIT_BRANCH"]
|
|
28
|
+
return env_branch if env_branch.present?
|
|
29
|
+
|
|
30
|
+
current_git_branch
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def development_environment?
|
|
34
|
+
Rails.env.development?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def current_git_commit
|
|
38
|
+
Dir.chdir(Rails.root) do
|
|
39
|
+
sha = `git rev-parse HEAD`.strip
|
|
40
|
+
$?.success? ? sha : nil
|
|
41
|
+
end
|
|
42
|
+
rescue StandardError
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def current_git_branch
|
|
47
|
+
Dir.chdir(Rails.root) do
|
|
48
|
+
branch = `git branch --show-current`.strip
|
|
49
|
+
return branch if $?.success? && branch.present?
|
|
50
|
+
|
|
51
|
+
fallback_branch = `git rev-parse --abbrev-ref HEAD`.strip
|
|
52
|
+
$?.success? ? fallback_branch : nil
|
|
53
|
+
end
|
|
54
|
+
rescue StandardError
|
|
55
|
+
nil
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Shalala
|
|
4
|
+
class Engine < ::Rails::Engine
|
|
5
|
+
isolate_namespace Shalala
|
|
6
|
+
|
|
7
|
+
initializer "shalala.mount_route" do |app|
|
|
8
|
+
app.config.to_prepare do
|
|
9
|
+
next if app.routes.named_routes.key?(:shalala)
|
|
10
|
+
|
|
11
|
+
app.routes.append do
|
|
12
|
+
mount Shalala::Engine, at: "/commit", as: :shalala
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/shalala.rb
ADDED
data/shalala.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
|
4
|
+
require 'shalala/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "shalala"
|
|
8
|
+
spec.version = Shalala::VERSION
|
|
9
|
+
spec.authors = ["Ryan Bigg"]
|
|
10
|
+
spec.email = ["ryan@example.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Rails engine exposing current git commit"
|
|
13
|
+
spec.description = "Mounts /commit and returns a git commit SHA based on environment rules."
|
|
14
|
+
spec.homepage = "https://github.com/radar/shalala"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
spec.required_ruby_version = ">= 3.1"
|
|
17
|
+
|
|
18
|
+
spec.files = Dir[
|
|
19
|
+
"app/**/*",
|
|
20
|
+
"config/**/*",
|
|
21
|
+
"lib/**/*",
|
|
22
|
+
"*.md",
|
|
23
|
+
"*.gemspec",
|
|
24
|
+
"Rakefile"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
spec.add_dependency "rails", ">= 7.0"
|
|
28
|
+
|
|
29
|
+
spec.add_development_dependency "rspec-rails", ">= 6.0"
|
|
30
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: shalala
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ryan Bigg
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '7.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rspec-rails
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '6.0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '6.0'
|
|
40
|
+
description: Mounts /commit and returns a git commit SHA based on environment rules.
|
|
41
|
+
email:
|
|
42
|
+
- ryan@example.com
|
|
43
|
+
executables: []
|
|
44
|
+
extensions: []
|
|
45
|
+
extra_rdoc_files: []
|
|
46
|
+
files:
|
|
47
|
+
- README.md
|
|
48
|
+
- Rakefile
|
|
49
|
+
- app/controllers/shalala/commits_controller.rb
|
|
50
|
+
- config/routes.rb
|
|
51
|
+
- lib/shalala.rb
|
|
52
|
+
- lib/shalala/engine.rb
|
|
53
|
+
- lib/shalala/version.rb
|
|
54
|
+
- shalala.gemspec
|
|
55
|
+
homepage: https://github.com/radar/shalala
|
|
56
|
+
licenses:
|
|
57
|
+
- MIT
|
|
58
|
+
metadata: {}
|
|
59
|
+
rdoc_options: []
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '3.1'
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0'
|
|
72
|
+
requirements: []
|
|
73
|
+
rubygems_version: 3.6.9
|
|
74
|
+
specification_version: 4
|
|
75
|
+
summary: Rails engine exposing current git commit
|
|
76
|
+
test_files: []
|