Skip to content

Commit

Permalink
Merge pull request #206 from mitou/add-test-to-check-yaml-data
Browse files Browse the repository at this point in the history
Add custom check to Projects/Creators data in YAML
  • Loading branch information
yasulab authored Nov 27, 2024
2 parents e32913c + 42bb592 commit 0716e94
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/custom_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# https://github.com/gjtorikian/html-proofer#custom-tests

require 'json'
require 'yaml'

class CustomChecks < ::HTMLProofer::Check
BASE_PATH = '_site'
Expand All @@ -13,6 +14,7 @@ def run
check_meta_tags
check_json_apis if valid_and_equal_to?(BASE_PATH + '/apis.html')
check_deadlines if valid_and_equal_to?(BASE_PATH + '/guideline.html')
check_yaml_data if valid_and_equal_to?(BASE_PATH + '/projects/index.html')
end

def valid_and_equal_to?(filename)
Expand Down Expand Up @@ -93,4 +95,21 @@ def check_deadlines
prev_text = node.text
end
end

# Check Creators/Projects YAML data and make CI failed if broken
# e.g.: https://github.com/mitou/jr.mitou.org/pull/206
def check_yaml_data
projects = YAML.load_file("_data/projects.yml", symbolize_names: true)
creator_ids = YAML.load_file("_data/creators.yml", symbolize_names: true).map{ |creator| creator[:id] }

projects.each do |project|
add_failure(
<<~ERROR_MESSAGE
The following creator ID is NOT found in _data/creators.yml
\s Project ID: #{project[:id]}
\s Creator ID: #{project[:creator_ids]}
ERROR_MESSAGE
) if (project[:creator_ids] & creator_ids).empty?
end
end
end

0 comments on commit 0716e94

Please sign in to comment.