Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom check to Projects/Creators data in YAML #206

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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