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
This commit is contained in:
parent
0c6c5c55a1
commit
4549144fbb
11 changed files with 53 additions and 10 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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}"
|
||||
|
|
|
|||
9
app/models/forem_instance.rb
Normal file
9
app/models/forem_instance.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -2,11 +2,11 @@
|
|||
<div class="tag-card crayons-card p-4 m:p-6 m:pt-4 mb-4 flex flex-row relative">
|
||||
<div class="mr-8">
|
||||
<div class="crayons-field__description">Last deployed</div>
|
||||
<div><%= ApplicationConfig["RELEASE_FOOTPRINT"].presence || ENV["HEROKU_RELEASE_CREATED_AT"].presence || "Not Available" %></div>
|
||||
<div><%= ForemInstance.deployed_at || "Not Available" %></div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="crayons-field__description">Latest Commit ID</div>
|
||||
<div><%= ApplicationConfig["FOREM_BUILD_SHA"].presence || ENV["HEROKU_SLUG_COMMIT"].presence || "Not Available" %></div>
|
||||
<div><%= ForemInstance.latest_commit_id || "Not Available" %></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@
|
|||
</head>
|
||||
<body class="admin default-header"
|
||||
data-honeybadger-key="<%= ApplicationConfig["HONEYBADGER_JS_API_KEY"] %>"
|
||||
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 %>">
|
||||
<header class="crayons-header" role="banner">
|
||||
<div class="crayons-header__container">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<base target="_parent">
|
||||
<% cache "liquid_tag_styles_#{ApplicationConfig['RELEASE_FOOTPRINT']}", expires_in: 8.hours do #TODO: Render specific ltag class instead of everything %>
|
||||
<% cache "liquid_tag_styles_#{ForemInstance.deployed_at}", expires_in: 8.hours do #TODO: Render specific ltag class instead of everything %>
|
||||
<style><%= Rails.application.assets["ltags/LiquidTags.css"].to_s.html_safe %></style>
|
||||
<% end %>
|
||||
<% begin %>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<!-- Start Bottom Shell -->
|
||||
<% unless internal_navigation? %>
|
||||
<% cache("footer-and-signup-modal--#{user_signed_in?}--#{ApplicationConfig['RELEASE_FOOTPRINT']}", expires_in: 24.hours) do %>
|
||||
<% cache("footer-and-signup-modal--#{user_signed_in?}--#{ForemInstance.deployed_at}", expires_in: 24.hours) do %>
|
||||
<%= render "layouts/footer" %>
|
||||
<%= render "layouts/signup_modal" unless user_signed_in? %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@
|
|||
data-pusher-key="<%= ApplicationConfig["PUSHER_KEY"] %>"
|
||||
data-app-domain="<%= ChatChannel.urlsafe_encoded_app_domain %>"
|
||||
data-honeybadger-key="<%= ApplicationConfig["HONEYBADGER_JS_API_KEY"] %>"
|
||||
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 %>">
|
||||
<div id="body-styles">
|
||||
<style>
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
# We will set RELEASE_FOOTPRINT in our Forem Cloud environment, or use HEROKU_SLUG_COMMIT if set (e.g. Heroku env)
|
||||
ENV["RELEASE_FOOTPRINT"] ||= ENV["HEROKU_RELEASE_CREATED_AT"]
|
||||
33
spec/models/forem_instance_spec.rb
Normal file
33
spec/models/forem_instance_spec.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe ForemInstance, type: :model do
|
||||
describe "deployed_at" do
|
||||
it "sets the RELEASE_FOOTPRINT if present" do
|
||||
allow(ApplicationConfig).to receive(:[]).with("RELEASE_FOOTPRINT").and_return("A deploy date")
|
||||
stub_const("ENV", ENV.to_h.merge("HEROKU_RELEASE_CREATED_AT" => ""))
|
||||
expect(described_class.deployed_at).to be(ApplicationConfig["RELEASE_FOOTPRINT"])
|
||||
end
|
||||
|
||||
it "sets the HEROKU_RELEASE_CREATED_AT if the RELEASE_FOOTPRINT is not present" do
|
||||
allow(ApplicationConfig).to receive(:[]).with("RELEASE_FOOTPRINT").and_return("")
|
||||
stub_const("ENV", ENV.to_h.merge("HEROKU_RELEASE_CREATED_AT" => "A deploy date set on Heroku"))
|
||||
described_class.instance_variable_set(:@deployed_at, nil)
|
||||
expect(described_class.deployed_at).to be(ENV["HEROKU_RELEASE_CREATED_AT"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "latest_commit_id" do
|
||||
it "sets the FOREM_BUILD_SHA if present" do
|
||||
allow(ApplicationConfig).to receive(:[]).with("FOREM_BUILD_SHA").and_return("A commit id")
|
||||
stub_const("ENV", ENV.to_h.merge("HEROKU_SLUG_COMMIT" => ""))
|
||||
expect(described_class.latest_commit_id).to be(ApplicationConfig["FOREM_BUILD_SHA"])
|
||||
end
|
||||
|
||||
it "sets the HEROKU_RELEASE_CREATED_AT if the RELEASE_FOOTPRINT is not present" do
|
||||
allow(ApplicationConfig).to receive(:[]).with("FOREM_BUILD_SHA").and_return("")
|
||||
stub_const("ENV", ENV.to_h.merge("HEROKU_SLUG_COMMIT" => "A Commit ID set from Heroku"))
|
||||
described_class.instance_variable_set(:@latest_commit_id, nil)
|
||||
expect(described_class.latest_commit_id).to be(ENV["HEROKU_SLUG_COMMIT"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -34,6 +34,7 @@ RSpec.describe "/admin", type: :request do
|
|||
|
||||
it "shows the correct value if the Last deployed time is available" do
|
||||
stub_const("ENV", ENV.to_h.merge("HEROKU_RELEASE_CREATED_AT" => "Some date"))
|
||||
ForemInstance.instance_variable_set(:@deployed_at, nil)
|
||||
|
||||
get admin_path
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue