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

pulibrary / pdc_discovery / 529bb1cf-d0bf-4901-97c6-12679aea8117

17 Aug 2023 01:30PM UTC coverage: 90.265% (-6.3%) from 96.544%
529bb1cf-d0bf-4901-97c6-12679aea8117

Pull #478

circleci

carolyncole
Updates to css to fix tests after bundle update
Also ran rubocop -A && Prettier
Pull Request #478: Switching to selenium to fix CI

2 of 2 new or added lines in 2 files covered. (100.0%)

2142 of 2373 relevant lines covered (90.27%)

93.35 hits per line

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

82.61
/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?
46✔
24
    { sha: git_sha, branch: branch, version: version, stale: stale?, tagged_release: tagged_release? }
46✔
25
  end
26

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

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

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

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

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

71
  def self.version
1✔
72
    @@version ||= if File.exist?(revisions_logfile)
46✔
73
                    deployed = `tail -1 #{revisions_logfile}`.chomp.split(" ")[7]
×
74
                    Date.parse(deployed).strftime("%d %B %Y")
×
75
                  else
76
                    "Not in deployed environment"
46✔
77
                  end
78
  end
79

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

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

92
  # These assignment methods are needed to facilitate testing
93
  def self.revision_file=(x)
1✔
94
    @@revision_file = x
2✔
95
  end
96

97
  def self.revisions_logfile=(x)
1✔
98
    @@revisions_logfile = x
2✔
99
  end
100
end
101
# 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