Module: AllStak::GitRelease
- Defined in:
- lib/allstak/config.rb
Overview
Runtime release detection from the local git checkout.
The parsing logic is split from the actual shelling-out so it stays seamable: tests inject a fake “git runner” callable instead of relying on a real repository on disk.
PRODUCTION HONESTY: a deployed artifact (packaged gem / container image) usually has no ‘.git` directory, so GitRelease.detect_release returns nil there and the SDK version constant becomes the effective release. Runtime git detection mainly helps source/dev deployments running inside a checkout.
Constant Summary collapse
- DEFAULT_RUNNER =
Default runner: shells out to the real ‘git` binary from the process working directory with a short timeout. Raises on any failure (git missing, no repo, timeout) so callers can treat every failure uniformly.
lambda do |args| require "open3" require "timeout" out = nil Timeout.timeout(2) do stdout, _stderr, status = Open3.capture3("git", *args) raise "git exited #{status.exitstatus}" unless status.success? out = stdout end out.to_s end
Class Method Summary collapse
-
.detect_release(runner = DEFAULT_RUNNER) ⇒ Object
Best-effort release string from local git.
Class Method Details
.detect_release(runner = DEFAULT_RUNNER) ⇒ Object
Best-effort release string from local git. Order:
1. `git describe --tags --always --dirty` (preferred).
2. else `git rev-parse --short HEAD`, with `-dirty` appended when
`git status --porcelain` is non-empty.
Fully guarded: returns nil if the runner raises or yields nothing for both strategies. Never raises.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/allstak/config.rb', line 38 def detect_release(runner = DEFAULT_RUNNER) begin described = runner.call(["describe", "--tags", "--always", "--dirty"]).to_s.strip return described unless described.empty? rescue StandardError # fall through to rev-parse end begin sha = runner.call(["rev-parse", "--short", "HEAD"]).to_s.strip return nil if sha.empty? status = begin runner.call(["status", "--porcelain"]).to_s rescue StandardError "" end return "#{sha}-dirty" unless status.strip.empty? sha rescue StandardError nil end end |