From 4549144fbbc7613e575090bca32c09eeff3cf86b Mon Sep 17 00:00:00 2001 From: Ridhwana Date: Wed, 13 Jan 2021 16:53:59 +0200 Subject: [PATCH] Refactor deployed_at and latest_commit_id code (#12224) * WIP: release footprint in the admin UI * feat: show the commit ID and the date * chore: change env optional to empty string * fix: change the FOREM_BUILD_DATE to RELEASE_FOOTPRINT * feat: add Not Available as a last option * test: last deployed time and latest commit id * feat: update the way we change the env variable! * fix: we need to set the RELEASE FOOTPRINT so that this clause is not hit - `return path if release_footprint.blank?` * feat: add a Forem Instance Model * chore: rename variable * feat: use the new model that we created * feat: Update the Forem Instance model to remove Not available from the model method and add it to the view layer * test: Forem Instance model to return the correct values when present * feat: use Forem.deployed_at instead of the Application config directly * chore: remove the initializer * feat: rename the data keys to reflect what it does * fix: oops evaluate the var * refactor: static values that can never change during the lifetime of the app should be constants * chore: setup the test to have a release footprint before the test gets executed * chore: remove the methods * revert to method + cache * revert to using method * reset the instance variable --- app/controllers/async_info_controller.rb | 2 +- app/helpers/application_helper.rb | 2 +- app/models/forem_instance.rb | 9 ++++++ app/views/admin/admin_portals/index.html.erb | 4 +-- app/views/layouts/admin.html.erb | 3 +- app/views/liquid_embeds/show.html.erb | 2 +- app/views/shell/_bottom.html.erb | 2 +- app/views/shell/_top.html.erb | 3 +- config/initializers/set_release_footprint.rb | 2 -- spec/models/forem_instance_spec.rb | 33 ++++++++++++++++++++ spec/requests/admin/admin_portals_spec.rb | 1 + 11 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 app/models/forem_instance.rb delete mode 100644 config/initializers/set_release_footprint.rb create mode 100644 spec/models/forem_instance_spec.rb diff --git a/app/controllers/async_info_controller.rb b/app/controllers/async_info_controller.rb index 87a1ed8e8..8ae8e3744 100644 --- a/app/controllers/async_info_controller.rb +++ b/app/controllers/async_info_controller.rb @@ -29,7 +29,7 @@ class AsyncInfoController < ApplicationController set_surrogate_key_header "shell-version-endpoint" # shell_version will change on every deploy. # *Technically* could be only on changes to assets and shell, but this is more fool-proof. - shell_version = ApplicationConfig["RELEASE_FOOTPRINT"] + SiteConfig.admin_action_taken_at.to_s + shell_version = ForemInstance.deployed_at + SiteConfig.admin_action_taken_at.to_s render json: { version: shell_version }.to_json end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4f9ba680e..e51823fc1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -176,7 +176,7 @@ module ApplicationHelper end def release_adjusted_cache_key(path) - release_footprint = ApplicationConfig["RELEASE_FOOTPRINT"] + release_footprint = ForemInstance.deployed_at return path if release_footprint.blank? "#{path}-#{params[:locale]}-#{release_footprint}-#{SiteConfig.admin_action_taken_at.rfc3339}" diff --git a/app/models/forem_instance.rb b/app/models/forem_instance.rb new file mode 100644 index 000000000..c37f5a6c0 --- /dev/null +++ b/app/models/forem_instance.rb @@ -0,0 +1,9 @@ +class ForemInstance + def self.deployed_at + @deployed_at ||= ApplicationConfig["RELEASE_FOOTPRINT"].presence || ENV["HEROKU_RELEASE_CREATED_AT"].presence + end + + def self.latest_commit_id + @latest_commit_id ||= ApplicationConfig["FOREM_BUILD_SHA"].presence || ENV["HEROKU_SLUG_COMMIT"].presence + end +end diff --git a/app/views/admin/admin_portals/index.html.erb b/app/views/admin/admin_portals/index.html.erb index f05e447c1..3aed91fa0 100644 --- a/app/views/admin/admin_portals/index.html.erb +++ b/app/views/admin/admin_portals/index.html.erb @@ -2,11 +2,11 @@
Last deployed
-
<%= ApplicationConfig["RELEASE_FOOTPRINT"].presence || ENV["HEROKU_RELEASE_CREATED_AT"].presence || "Not Available" %>
+
<%= ForemInstance.deployed_at || "Not Available" %>
Latest Commit ID
-
<%= ApplicationConfig["FOREM_BUILD_SHA"].presence || ENV["HEROKU_SLUG_COMMIT"].presence || "Not Available" %>
+
<%= ForemInstance.latest_commit_id || "Not Available" %>
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 63b4bf5e3..0323f3f38 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -26,7 +26,8 @@ " - data-release-footprint="<%= ApplicationConfig["RELEASE_FOOTPRINT"] %>" + data-deployed-at="<%= ForemInstance.deployed_at %>" + data-latest-commit-id="<%= ForemInstance.latest_commit_id %>" data-ga-tracking="<%= SiteConfig.ga_tracking_id %>">