• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / tigerdata-app / 529f7cba-0651-41c2-9045-ff17f0a5a349

21 Oct 2025 09:43PM UTC coverage: 86.877%. Remained the same
529f7cba-0651-41c2-9045-ff17f0a5a349

Pull #2070

circleci

bess
Remove tests for special production behavior
Pull Request #2070: Remove tests for special behavior in production

2615 of 3010 relevant lines covered (86.88%)

340.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/app/models/version_footer.rb
1
# frozen_string_literal: true
2

3
# Retrieves version information from Capistrano's files. The general approach is
4
# to read the version information (branch name, git SHA, and date deployed) out
5
# of Capistrano's revisions.log file.
6
#
7
# The code is a bit more complicated than it should because Capistrano does not
8
# always update the revision.log file before the application reads this information.
9
# Therefore there is logic in this class to detect if the version information is
10
# stale and re-read it until it is up to date. Because re-reading this file is
11
# an expensive operation we cache the information as soon as we are sure it's
12
# current.
13
#
14
# rubocop:disable Style/ClassVars
15
class VersionFooter
4✔
16
  @@stale = true
4✔
17
  @@git_sha = nil
4✔
18
  @@branch = nil
4✔
19
  @@version = nil
4✔
20

21
  # Returns a hash with version information.
22
  def self.info
4✔
23
    reset! if stale?
219✔
24
    { sha: git_sha, branch:, version:, stale: stale?, tagged_release: tagged_release? }
218✔
25
  rescue StandardError => ex
26
    { error: "Error retrieving version information: #{ex.message}" }
1✔
27
  end
28

29
  def self.reset!
4✔
30
    # Initalize these values so that they recalculated
31
    @@git_sha = nil
227✔
32
    @@branch = nil
227✔
33
    @@version = nil
227✔
34
  end
35

36
  def self.stale?
4✔
37
    return false if @@stale == false
439✔
38
    # Only read the file when version information is stale
39
    if File.exist?(revision_file)
437✔
40
      local_sha = File.read(revision_file).chomp.gsub(/\)$/, "")
8✔
41
      @@stale = local_sha != git_sha
8✔
42
    else
43
      @@stale = true
429✔
44
    end
45
  end
46

47
  def self.git_sha
4✔
48
    @@git_sha ||= if File.exist?(revisions_logfile)
228✔
49
                    log_line(revisions_logfile).chomp.split(" ")[3].gsub(/\)$/, "")
6✔
50
                  elsif Rails.env.development? || Rails.env.test?
218✔
51
                    `git rev-parse HEAD`.chomp
217✔
52
                  else
53
                    "Unknown SHA"
1✔
54
                  end
55
  end
56

57
  def self.tagged_release?
4✔
58
    # e.g. v0.8.0
59
    branch.match(/^v[\d+\.+]+/) != nil
218✔
60
  end
61

62
  def self.branch
4✔
63
    @@branch ||= if File.exist?(revisions_logfile)
438✔
64
                   log_line(revisions_logfile).chomp.split(" ")[1]
3✔
65
                 elsif Rails.env.development? || Rails.env.test?
217✔
66
                   `git rev-parse --abbrev-ref HEAD`.chomp
216✔
67
                 else
68
                   "Unknown branch"
1✔
69
                 end
70
  end
71

72
  def self.version
4✔
73
    @@version ||= if File.exist?(revisions_logfile)
219✔
74
                    deployed = log_line(revisions_logfile).chomp.split(" ")[7]
3✔
75
                    Date.parse(deployed).strftime("%d %B %Y")
3✔
76
                  else
77
                    "Not in deployed environment"
216✔
78
                  end
79
  end
80

81
  # This file is local to the application.
82
  # This file only has the git SHA of the version deployed (i.e. no date or branch)
83
  def self.revision_file
4✔
84
    @@revision_file ||= Rails.root.join("REVISION")
445✔
85
  end
86

87
  # Capistrano keeps this file a couple of levels up _outside_ the application.
88
  # This file includes all the information that we need (git SHA, branch name, date)
89
  def self.revisions_logfile
4✔
90
    @@revisions_logfile ||= Rails.root.join("..", "..", "revisions.log")
675✔
91
  end
92

93
  # These assignment methods are needed to facilitate testing
94
  def self.revision_file=(x)
4✔
95
    @@stale = true
6✔
96
    @@revision_file = x
6✔
97
  end
98

99
  def self.revisions_logfile=(x)
4✔
100
    @@stale = true
10✔
101
    @@revisions_logfile = x
10✔
102
  end
103

104
  def self.log_line(revisions_logfile)
4✔
105
    log_line = `tail -1 #{revisions_logfile}`
11✔
106
    if log_line.include?("rolled back")
11✔
107
      grep_lines = `grep #{log_line.chomp.split(" ").last} #{revisions_logfile}`.split("\n")
3✔
108
      log_line = grep_lines.first
3✔
109
    end
110
    log_line
11✔
111
  end
112
end
113
# rubocop:enable RuboCop::Cop::Style::ClassVars
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc