Skip to content

Commit e83fb58

Browse files
committed
Add support for a VERSION file
1 parent c4ab657 commit e83fb58

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ RUN mkdir -p $APP_ROOT && \
6363
chgrp -R 0 $APP_ROOT && \
6464
chmod -R g=u $APP_ROOT && \
6565
cp $APP_ROOT/container-assets/container_env /usr/local/bin && \
66-
cp $APP_ROOT/container-assets/entrypoint /usr/local/bin
66+
cp $APP_ROOT/container-assets/entrypoint /usr/local/bin && \
67+
echo "$REF" > $APP_ROOT/VERSION
6768

6869
WORKDIR $APP_ROOT
6970

config/application.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ class Application < Rails::Application
3434
end
3535

3636
def self.version
37-
@version ||= `GIT_DIR=#{Rails.root.join('.git')} git describe --tags`.chomp
37+
@version ||= begin
38+
if Rails.root.join('.git').exist?
39+
`GIT_DIR=#{Rails.root.join('.git')} git describe --tags`.chomp
40+
elsif Rails.root.join("VERSION").exist?
41+
Rails.root.join("VERSION").read.chomp
42+
else
43+
""
44+
end
45+
end
3846
end
3947
end

spec/miq_bot_spec.rb

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
RSpec.describe MiqBot do
2+
describe ".version" do
3+
before { MiqBot.instance_variable_set(:@version, nil) }
4+
after { MiqBot.instance_variable_set(:@version, nil) }
5+
6+
it "with git dir present" do
7+
expect(described_class).to receive(:`).with("GIT_DIR=#{File.expand_path("..", __dir__)}/.git git describe --tags").and_return("v0.21.2-91-g6800275\n")
8+
9+
expect(described_class.version).to eq("v0.21.2-91-g6800275")
10+
end
11+
12+
context "with git dir not present" do
13+
let!(:tmpdir) do
14+
Pathname.new(Dir.mktmpdir("fake_rails_root")).tap do |tmpdir|
15+
expect(Rails).to receive(:root).at_least(:once).and_return(tmpdir)
16+
end
17+
end
18+
after { FileUtils.rm_rf(tmpdir) }
19+
20+
context "and VERSION file present" do
21+
before { tmpdir.join("VERSION").write("v0.21.2-91-g6800275\n") }
22+
23+
it "returns the content of the VERSION file" do
24+
expect(described_class.version).to eq("v0.21.2-91-g6800275")
25+
end
26+
end
27+
28+
context "and VERSION file not present" do
29+
it "returns nothing" do
30+
expect(described_class.version).to be_empty
31+
end
32+
end
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)