diff --git a/tests/custom_checks.rb b/tests/custom_checks.rb index c9914df93..6cfe42ced 100644 --- a/tests/custom_checks.rb +++ b/tests/custom_checks.rb @@ -2,6 +2,7 @@ # https://github.com/gjtorikian/html-proofer#custom-tests require 'json' +require 'yaml' class CustomChecks < ::HTMLProofer::Check BASE_PATH = '_site' @@ -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) @@ -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