1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 # If you change this file, you'll probably also want to make the same
6 # changes in apps/workbench/lib/app_version.rb.
9 def self.git(*args, &block)
10 IO.popen(["git", "--git-dir", ".git"] + args, "r",
11 chdir: Rails.root.join('../..'),
18 @package_version = nil
21 # Return abbrev commit hash for current code version: "abc1234", or
22 # "abc1234-modified" if there are uncommitted changes. If present,
23 # return contents of {root}/git-commit.version instead.
25 if (cached = Rails.configuration.source_version || @hash)
29 # Read the version from our package's git-commit.version file, if available.
31 @hash = IO.read(Rails.root.join("git-commit.version")).strip
35 if @hash.nil? or @hash.empty?
37 local_modified = false
38 git("status", "--porcelain") do |git_pipe|
39 git_pipe.each_line do |_|
41 # Continue reading the pipe so git doesn't get SIGPIPE.
45 git("log", "-n1", "--format=%H") do |git_pipe|
46 git_pipe.each_line do |line|
47 @hash = line.chomp[0...8] + (local_modified ? '-modified' : '')
51 rescue SystemCallError
58 def self.package_version
59 if (cached = Rails.configuration.package_version || @package_version)
64 @package_version = IO.read(Rails.root.join("package-build.version")).strip
66 @package_version = "unknown"