From 3801789e8f8e078290f5a814d28c0bd93220fbc2 Mon Sep 17 00:00:00 2001 From: Jamie Gaskins Date: Mon, 4 Oct 2021 09:35:20 -0400 Subject: [PATCH] Add real release version into the running code (#14870) * Add real release version into the running code * Fix warnings --- .../api/v0/instances_controller.rb | 20 ++++++++++++++++++- scripts/release | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v0/instances_controller.rb b/app/controllers/api/v0/instances_controller.rb index 17cb8fbda..79f4dc022 100644 --- a/app/controllers/api/v0/instances_controller.rb +++ b/app/controllers/api/v0/instances_controller.rb @@ -13,7 +13,7 @@ module Api name: Settings::Community.community_name, registered_users_count: User.registered.estimated_count, tagline: Settings::Community.tagline, - version: "edge.#{Time.now.utc.strftime('%Y%m%d')}.0", + version: release_version, visibility: visibility }, status: :ok end @@ -25,6 +25,24 @@ module Api Settings::UserExperience.public ? "public" : "private" end + + def release_version + File.read(Rails.root.join(".release-version")) + + # Accommodate the .release-version file not existing in the case where + # this deployment is deployed from a checkout/snapshot of the code. + rescue StandardError + # Get the latest modified file in the app. We don't use git in case it's + # being run from a snapshot of the code outside a git repo (for example: + # https://github.com/forem/forem/archive/refs/heads/main.zip), but + # instead we use the latest modified time ("mtime") from application + # code. + latest_mtime = Dir[Rails.root.join("{app,config,db,lib}/**/*")] + .max_by { |filename| File.mtime(filename) } + .then { |filename| File.mtime(filename) } + + "edge.#{latest_mtime.strftime('%Y%m%d')}.0" + end end end end diff --git a/scripts/release b/scripts/release index b6148ce68..419eeb7c5 100755 --- a/scripts/release +++ b/scripts/release @@ -69,6 +69,9 @@ begin puts "Merged #{source} into #{channel}" begin + run "echo '#{tag}' > .release-version" + run "git add .release-version" + run "git commit --message 'Version #{tag}'" run "git tag #{tag}" puts "Tagged #{tag}" rescue StandardError