Skip to content

Commit 4e401e6

Browse files
authored
fix(validation): use runtime config validation entrypoint (#288)
* feat(devx): add config validation workflow * fix(devx): pin prettier and harden config validation * fix(ci): skip schema-only changed config fetch tests * Fix RuboCop CI warnings * fix(validation): use runtime config validation entrypoint * style: fixes
1 parent 597881a commit 4e401e6

6 files changed

Lines changed: 67 additions & 7 deletions

File tree

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
77
gem 'html2rss', github: 'html2rss/html2rss', branch: :master
88

99
group :development do
10-
# gem 'html2rss-generator', path: '../generator'
1110
gem 'html2rss-generator', github: 'html2rss/generator', branch: :main
1211

1312
gem 'nokogiri'

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ GIT
1212

1313
GIT
1414
remote: https://github.com/html2rss/html2rss
15-
revision: 762a09c15e5def5897b2d08f0e3c11c023cc9b35
15+
revision: e0dca5bf74b17c1e2a0618fc0a4af27c16da1883
1616
branch: master
1717
specs:
1818
html2rss (0.17.0)
@@ -224,7 +224,7 @@ GEM
224224
rubocop-ast (>= 1.49.0, < 2.0)
225225
ruby-progressbar (~> 1.7)
226226
unicode-display_width (>= 2.4.0, < 4.0)
227-
rubocop-ast (1.49.0)
227+
rubocop-ast (1.49.1)
228228
parser (>= 3.3.7.2)
229229
prism (~> 1.7)
230230
rubocop-performance (1.26.1)

bin/setup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ bundle install
77

88
echo
99
echo "==> Installing Node dependencies (required for make lint)..."
10-
npm install --ignore-scripts --no-fund --no-audit
10+
npm ci --ignore-scripts --no-fund --no-audit
1111

1212
echo
1313
echo "==> Checking system tools..."

bin/validate_configs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33

44
require 'bundler/setup'
55
require 'html2rss'
6-
require 'yaml'
6+
7+
unless Html2rss::Config.respond_to?(:validate_yaml)
8+
warn 'Error: installed html2rss gem does not support Config.validate_yaml.'
9+
warn 'Run: bundle update html2rss'
10+
exit 1
11+
end
712

813
files = Dir['lib/html2rss/configs/**/*.yml']
914
failed = []
1015

1116
files.each do |file|
12-
config = YAML.safe_load_file(file, symbolize_names: true)
13-
result = Html2rss::Config.validate(config)
17+
result = Html2rss::Config.validate_yaml(file)
1418

1519
if result.success?
1620
puts "ok #{file}"

spec/bin/validate_configs_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
require 'fileutils'
4+
require 'tmpdir'
5+
6+
RSpec.describe 'bin/validate_configs' do # rubocop:disable RSpec/DescribeClass
7+
let(:script_path) { File.expand_path('../../bin/validate_configs', __dir__) }
8+
let(:config_path) { File.join('lib', 'html2rss', 'configs', 'example.com', 'search.yml') }
9+
let(:success_output) do
10+
a_string_including(
11+
"ok #{config_path}",
12+
'1 configs validated successfully.'
13+
)
14+
end
15+
16+
it 'passes validation for parameterized configs when defaults are present' do
17+
with_temp_config do |dir|
18+
expect { run_script(dir) }.to output(success_output).to_stdout
19+
.and output('').to_stderr
20+
end
21+
end
22+
23+
def with_temp_config
24+
Dir.mktmpdir do |dir|
25+
write_config(dir)
26+
yield dir
27+
end
28+
end
29+
30+
def write_config(dir)
31+
FileUtils.mkdir_p(File.join(dir, File.dirname(config_path)))
32+
File.write(File.join(dir, config_path), valid_config)
33+
end
34+
35+
def run_script(dir)
36+
Dir.chdir(dir) { load script_path }
37+
end
38+
39+
def valid_config
40+
<<~YAML
41+
parameters:
42+
query:
43+
type: string
44+
default: ruby
45+
headers:
46+
X-Query: "%<query>s"
47+
channel:
48+
url: "https://example.com/search?q=%<query>s"
49+
selectors:
50+
items:
51+
selector: ".item"
52+
title:
53+
selector: "h2"
54+
YAML
55+
end
56+
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'bundler/setup'
44
require 'tzinfo'
5+
56
require 'html2rss'
67
require 'html2rss/configs'
78

0 commit comments

Comments
 (0)