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

pulibrary / pdc_describe / 9091a1ae-29be-458c-984a-339d213919c4

12 Dec 2024 07:41PM UTC coverage: 26.434% (-69.7%) from 96.113%
9091a1ae-29be-458c-984a-339d213919c4

Pull #2000

circleci

jrgriffiniii
Removing integration with ActiveStorage
Pull Request #2000: Bump actionpack from 7.2.1.1 to 7.2.2.1

945 of 3575 relevant lines covered (26.43%)

0.35 hits per line

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

31.48
/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
1✔
16
  @@stale = true
1✔
17
  @@git_sha = nil
1✔
18
  @@branch = nil
1✔
19
  @@version = nil
1✔
20

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

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

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

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

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

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

72
  def self.version
1✔
73
    @@version ||= if File.exist?(revisions_logfile)
×
74
                    deployed = log_line(revisions_logfile).chomp.split(" ")[7]
×
75
                    Date.parse(deployed).strftime("%d %B %Y")
×
76
                  else
77
                    "Not in deployed environment"
×
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
1✔
84
    @@revision_file ||= Rails.root.join("REVISION")
×
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
1✔
90
    @@revisions_logfile ||= Rails.root.join("..", "..", "revisions.log")
×
91
  end
92

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

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

104
  def self.log_line(revisions_logfile)
1✔
105
    log_line = `tail -1 #{revisions_logfile}`
×
106
    if log_line.include?("rolled back")
×
107
      grep_lines = `grep #{log_line.chomp.split(" ").last} #{revisions_logfile}`.split("\n")
×
108
      log_line = grep_lines.first
×
109
    end
110
    log_line
×
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