21406: Declare python_requires~=3.8 in all packages
[arvados.git] / services / api / lib / app_version.rb
index 769f4e5ed86cbf65f2ee8afd1ad79a1c47bea1dc..95685ea5fe65d5db24e605de66c331e1f910f7fa 100644 (file)
@@ -1,5 +1,6 @@
-# If you change this file, you'll probably also want to make the same
-# changes in apps/workbench/lib/app_version.rb.
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
 
 class AppVersion
   def self.git(*args, &block)
@@ -11,6 +12,7 @@ class AppVersion
 
   def self.forget
     @hash = nil
+    @package_version = nil
   end
 
   # Return abbrev commit hash for current code version: "abc1234", or
@@ -49,4 +51,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