Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Move CICD logic for cehcks to the config using ERB
Browse files Browse the repository at this point in the history
  • Loading branch information
dshevtsov committed Aug 2, 2019
1 parent 9cd1ced commit e6ddd49
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
8 changes: 3 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ require 'html-proofer'
require 'kramdown'
require 'launchy'
require 'colorator'
require 'erb'

# Load ruby files with helper methods from the 'rakelib/' directory
require_relative 'rakelib/lib/link-checker.rb'
require_relative 'rakelib/lib/converter.rb'
require_relative 'rakelib/lib/double-slash-check.rb'
require_relative 'rakelib/lib/doc-config.rb'
# Require helper methods from the 'rakelib/lib' directory
Dir.glob('rakelib/lib/**/*.rb') { |file| require_relative(file) }

desc "Same as 'rake', 'rake preview'"
task default: %w[preview]
Expand Down
4 changes: 3 additions & 1 deletion _checks/html-check-hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
require 'html-proofer'
require 'yaml'
require 'erb'
require_relative '../rakelib/lib/double-slash-check.rb'

Jekyll::Hooks.register :site, :post_write do |site|
Expand All @@ -17,7 +18,8 @@
# Check 'url_ignore' in '_config.checks.yml'
# and add 'excludes' from Jekyll configurtiuon.
#
checks_config = YAML.load_file('_config.checks.yml')
template = ERB.new File.read '_config.checks.yml.erb'
checks_config = YAML.safe_load template.result(binding), permitted_classes: [Symbol, Regexp]
url_ignore = checks_config.dig('html-proofer', :url_ignore)
jekyll_excludes = site.config['exclude']
jekyll_excludes_as_regex = jekyll_excludes.map { |item| Regexp.new Regexp.escape(item) }
Expand Down
8 changes: 6 additions & 2 deletions _config.checks.yml → _config.checks.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#
html-proofer:

<% if ENV['BUILD_NUMBER'] %>
:url_swap: "<%= ENV['BUILD_NUMBER'] %>:''"
<% end %>

# Do not check external links.
:disable_external: false

Expand All @@ -12,7 +16,7 @@ html-proofer:

# Ignores images with empty alt tags.
:empty_alt_ignore: true

# Sort errors by description in the report
:error_sort: :desc

Expand All @@ -30,7 +34,7 @@ html-proofer:

:internal_domains:
- devdocs.magento.com
- devdocs.magedevteam.com
# - devdocs.magedevteam.com

# Ignore any link that includes a specified pattern
# :url_ignore:
Expand Down
11 changes: 6 additions & 5 deletions rakelib/lib/link-checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ def self.check_site
# Read options from the '_config.checks.yml'
# Ignore baseurl if $branch is available in environment
def self.options
config = YAML.load_file('_config.checks.yml')
baseurl = ENV['BUILD_NUMBER']
return config['html-proofer'] unless baseurl
url_swap = { url_swap: { %r{\A/#{baseurl}} => '' } }
config['html-proofer'].merge(url_swap)
template = ERB.new File.read '_config.checks.yml.erb'
YAML.safe_load template.result(binding), permitted_classes: [Symbol, Regexp]
# baseurl = ENV['BUILD_NUMBER']
# return config['html-proofer'] unless baseurl
# url_swap = { url_swap: { %r{\A/#{baseurl}} => '' } }
# config['html-proofer'].merge(url_swap)
end

# Relative path for the link checker report
Expand Down

0 comments on commit e6ddd49

Please sign in to comment.