[deploy] Remove need for ENV vars during asset precompile (#10349)

* Remove need for ENV vars during asset precompile

* Add open-search test
This commit is contained in:
Ben Halpern 2020-09-16 13:57:05 -04:00 committed by GitHub
parent 5ba8c44b05
commit 3e09a7768f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 48 additions and 10 deletions

View file

@ -6,4 +6,3 @@
//= link administrate/application.css
//= link administrate/application.js
//= link katex.css
//= link search.xml

View file

@ -685,9 +685,9 @@ var instantClick
// INITIALIZE/ERROR HANDLING
Honeybadger.configure({
apiKey: "<%= ApplicationConfig['HONEYBADGER_JS_API_KEY'] %>",
apiKey: document.body.dataset.honeybadgerKey,
environment: "<%= Rails.env %>",
revision: "<%= ApplicationConfig['HEROKU_SLUG_COMMIT'] %>",
revision: document.body.dataset.releaseFootprint,
ignorePatterns: [/ResizeObserver/i, /MetaMask/i],
});

View file

@ -159,7 +159,7 @@ function toggleCodeOfConduct() {
var checkboxWrapper = document.getElementById('toggle-code-of-conduct-checkbox');
if (checkboxWrapper && !codeOfConduct) {
checkboxWrapper.innerHTML = '<input type="checkbox" name="checked_code_of_conduct" class="checkbox" required/>\
<label for="checked_code_of_conduct">I\'ve read the <a href="<%= URL.url('code-of-conduct') %>">code of conduct</a></label>'
<label for="checked_code_of_conduct">I\'ve read the <a href="/code-of-conduct">code of conduct</a></label>'
}
}

View file

@ -5,7 +5,7 @@ function buildCommentFormHTML(commentableId, commentableType, parentId) {
if (user && !user.codeOfConduct && user.commentCount < 1){
codeOfConductHTML = '<div class="code-of-conduct sub-comment-code-of-conduct" style="display:block" id="toggle-code-of-conduct-checkbox">\
<input class="checkbox" type="checkbox" name="checked_code_of_conduct" required />\
<label for="checked_code_of_conduct">I\'ve read the <a href="<%= URL.url('code-of-conduct') %>">code of conduct</a></label>\
<label for="checked_code_of_conduct">I\'ve read the <a href="/code-of-conduct">code of conduct</a></label>\
</div>'
}
var randomIdNumber = Math.floor(Math.random() * 1991)

View file

@ -61,7 +61,7 @@ function buildCommentHTML(comment) {
<a href="'+comment.url+'/settings" class="crayons-link crayons-link--block">\
Settings\
</a>\
<a href="/report-abuse?url=<%= URL.url %>'+comment.url+'" class="crayons-link crayons-link--block">Report Abuse</a>\
<a href="/report-abuse?url='+comment.url+'" class="crayons-link crayons-link--block">Report Abuse</a>\
</div>\
</div>\
</div>\

View file

@ -0,0 +1,8 @@
class OpenSearchController < ApplicationController
before_action :set_cache_control_headers, only: %i[show]
def show
set_surrogate_key_header "open-search-xml"
render layout: false
end
end

View file

@ -24,7 +24,11 @@
<%= stylesheet_link_tag "admin" %>
</head>
<body class="admin">
<body class="admin"
data-honybadger-key="<%= ApplicationConfig['HONEYBADGER_JS_API_KEY'] %>"
data-release-footprint="<%= ApplicationConfig['RELEASE_FOOTPRINT'] %>"
data-ga-tracking="<%= SiteConfig.ga_tracking_id %>">
>
<header class="top-bar" id="top-bar" role="banner">
<div class="top-bar__container">
<a href="/" class="top-bar--logo" aria-label="<%= community_name %> Home"><%= logo_svg %></a>

View file

@ -45,7 +45,7 @@
<meta property="fb:pages" content="568966383279687" />
<meta name="theme-color" content="#000000" />
<link rel="manifest" href="/manifest.json" />
<link rel="search" href="<%= asset_path("search.xml") %>" type="application/opensearchdescription+xml" title="<%= community_qualified_name %>" />
<link rel="search" href="<%= URL.url("open-search.xml") %>" type="application/opensearchdescription+xml" title="<%= community_qualified_name %>" />
<% end %>
</head>
<% unless internal_navigation? %>
@ -55,6 +55,8 @@
class="<%= SiteConfig.default_font.tr("_", "-") %>-article-body"
data-pusher-key="<%= ApplicationConfig["PUSHER_KEY"] %>"
data-app-name="<%= ApplicationConfig["APP_NAME"] %>"
data-honybadger-key="<%= ApplicationConfig['HONEYBADGER_JS_API_KEY'] %>"
data-release-footprint="<%= ApplicationConfig['RELEASE_FOOTPRINT'] %>"
data-ga-tracking="<%= SiteConfig.ga_tracking_id %>">
<div id="body-styles">
<style>

View file

@ -1,5 +1,14 @@
# rubocop:disable Metrics/BlockLength
Rails.application.configure do
# Allow the app to know when booted up in context where we haven't set ENV vars
# If we have not set this ENV var it means we haven't set the environment
ENV["ENV_AVAILABLE"] = ENV["APP_DOMAIN"].present?.to_s
if ENV["ENV_AVAILABLE"] == "false"
# We still need _something_ here, but if booted without environment (aka asset precompile),
# it shouldn't need to be the proper value
ENV["SECRET_KEY_BASE"] = "NOT_SET"
end
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
@ -115,7 +124,7 @@ Rails.application.configure do
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
sendgrid_api_key_present = ENV["SENDGRID_API_KEY"].present?
config.action_mailer.default_url_options = { host: protocol + ENV["APP_DOMAIN"] }
config.action_mailer.default_url_options = { host: protocol + ENV["APP_DOMAIN"].to_s }
ActionMailer::Base.smtp_settings = {
address: "smtp.sendgrid.net",
port: "587",

View file

@ -3,7 +3,7 @@
# tools like Blazer.
# further setup instructions: https://github.com/ankane/hypershield#database-setup
if Rails.env.production?
if Rails.env.production? && ENV["ENV_AVAILABLE"] == "true"
Hypershield.enabled = ENV["ENABLE_HYPERSHIELD"].present?
# Validate that hypershield schema exists before trying to use it

View file

@ -453,6 +453,10 @@ Rails.application.routes.draw do
get "/serviceworker" => "service_worker#index"
get "/manifest" => "service_worker#manifest"
# open search
get "/open-search" => "open_search#show",
:constraints => { format: /xml/ }
get "/shell_top" => "shell#top"
get "/shell_bottom" => "shell#bottom"

View file

@ -0,0 +1,12 @@
require "rails_helper"
RSpec.describe "OpenSearch", type: :request do
let(:user) { create(:user, saw_onboarding: false) }
describe "GET /open-search.xml" do
it "has proper information" do
get "/open-search.xml"
expect(response.body).to include("<ShortName>#{SiteConfig.community_name} Search</ShortName>")
end
end
end