Merge branch '12983-containerd' closes #12983
[arvados.git] / apps / workbench / lib / app_version.rb
index 05b9f2694d26bb81113d46d9db8ea1e5a00ebe1f..9db76e25728da4e4127ed68cc8064c1d3a4f5d8c 100644 (file)
@@ -1,5 +1,9 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 # If you change this file, you'll probably also want to make the same
-# changes in apps/workbench/lib/app_version.rb.
+# changes in services/api/lib/app_version.rb.
 
 class AppVersion
   def self.git(*args, &block)
@@ -11,6 +15,7 @@ class AppVersion
 
   def self.forget
     @hash = nil
+    @package_version = nil
   end
 
   # Return abbrev commit hash for current code version: "abc1234", or
@@ -30,7 +35,7 @@ class AppVersion
     if @hash.nil? or @hash.empty?
       begin
         local_modified = false
-        git("status", "-s") do |git_pipe|
+        git("status", "--porcelain") do |git_pipe|
           git_pipe.each_line do |_|
             STDERR.puts _
             local_modified = true
@@ -50,4 +55,18 @@ class AppVersion
 
     @hash || "unknown"
   end
+
+  def self.package_version
+    if (cached = Rails.configuration.package_version || @package_version)
+      return cached
+    end
+
+    begin
+      @package_version = IO.read(Rails.root.join("package-build.version")).strip
+    rescue Errno::ENOENT
+      @package_version = "unknown"
+    end
+
+    @package_version
+  end
 end