Commit e83fb58 1 parent c4ab657 commit e83fb58 Copy full SHA for e83fb58
File tree 3 files changed +46
-2
lines changed
3 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,8 @@ RUN mkdir -p $APP_ROOT && \
63
63
chgrp -R 0 $APP_ROOT && \
64
64
chmod -R g=u $APP_ROOT && \
65
65
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
67
68
68
69
WORKDIR $APP_ROOT
69
70
Original file line number Diff line number Diff line change @@ -34,6 +34,14 @@ class Application < Rails::Application
34
34
end
35
35
36
36
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
38
46
end
39
47
end
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments