Skip to content

Commit 99cdbdb

Browse files
committed
feat(devx): add config validation workflow
1 parent 9744aa8 commit 99cdbdb

7 files changed

Lines changed: 101 additions & 11 deletions

File tree

.github/workflows/ruby.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v2
15-
- uses: actions/setup-node@v2
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
1616
with:
1717
node-version: "20"
1818

1919
- name: Install dependencies
20-
run: |
21-
sudo apt-get install -yqq yamllint
20+
run: sudo apt-get install -yqq yamllint
2221

2322
- name: Set up Ruby
2423
uses: ruby/setup-ruby@v1
@@ -29,6 +28,9 @@ jobs:
2928
- name: Run linters
3029
run: make lint
3130

31+
- name: Validate configs
32+
run: make validate
33+
3234
test:
3335
strategy:
3436
fail-fast: false
@@ -38,7 +40,7 @@ jobs:
3840
runs-on: ubuntu-latest
3941

4042
steps:
41-
- uses: actions/checkout@v2
43+
- uses: actions/checkout@v4
4244

4345
- name: Set up Ruby
4446
uses: ruby/setup-ruby@v1
@@ -53,7 +55,7 @@ jobs:
5355
runs-on: ubuntu-latest
5456

5557
steps:
56-
- uses: actions/checkout@v2
58+
- uses: actions/checkout@v4
5759

5860
- name: Set up Ruby
5961
uses: ruby/setup-ruby@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/spec/reports/
88
/tmp/
99
/node_modules/
10+
/schema/
1011

1112
# rspec failure tracking
1213
.rspec_status

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"redhat.vscode-yaml"
4+
]
5+
}

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
default: lint test
1+
default: lint validate test
22

33
lint:
44
yamllint lib/html2rss/configs/ .github/
55
bundle exec rubocop -P -f quiet
6-
npx prettier --check lib/**/*.yml .github/**/*.yml README.md
6+
npx prettier --check lib/**/*.yml .github/**/*.yml README.md
7+
8+
validate:
9+
bundle exec ruby bin/validate_configs
10+
11+
schema:
12+
mkdir -p schema
13+
bundle exec html2rss schema --write schema/html2rss-config.schema.json
714

815
test:
916
bundle exec rspec

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ channel:
4040

4141
The `type` field specifies the parameter type (currently only `string` is supported), and `default` provides the default value when no parameter is explicitly provided.
4242

43+
## Validation
44+
45+
Validate configs against the html2rss schema before committing:
46+
47+
```bash
48+
# Validate all configs
49+
make validate
50+
51+
# Validate a single config directly
52+
bundle exec html2rss validate lib/html2rss/configs/github.com/releases.yml
53+
```
54+
4355
## Testing
4456

4557
Uses **dynamic test generation** - no individual spec files needed!
@@ -55,7 +67,7 @@ make test-config CONFIG=github.com/releases.yml
5567
make test-domain DOMAIN=github.com
5668
```
5769

58-
**Adding new configs**: Just create the YAML file and run tests. No spec file needed.
70+
**Adding new configs**: Just create the YAML file and run `make validate` then tests. No spec file needed.
5971

6072
**Config folder convention**: Place configs under the registrable domain folder (e.g., `example.com/` or `bbc.co.uk/`). Legacy subdomain folders (e.g., `news.example.com/`) are allowed but not preferred.
6173

bin/setup

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33
IFS=$'\n\t'
4-
set -vx
54

5+
echo "==> Installing Ruby dependencies..."
66
bundle install
77

8-
# Do any other automated setup that you need to do here
8+
echo
9+
echo "==> Installing Node dependencies (required for make lint)..."
10+
npm install --no-fund --no-audit --no-save prettier
11+
12+
echo
13+
echo "==> Checking system tools..."
14+
if command -v yamllint &>/dev/null; then
15+
echo " yamllint: ok ($(yamllint --version))"
16+
else
17+
echo " yamllint: not found"
18+
echo " Install with one of:"
19+
echo " brew install yamllint"
20+
echo " pip install yamllint"
21+
fi
22+
23+
echo
24+
echo "==> Setup complete. Common commands:"
25+
echo
26+
echo " make # lint + validate + test"
27+
echo " make lint # yamllint, rubocop, prettier"
28+
echo " make validate # validate all configs against the html2rss schema"
29+
echo " make test # run rspec"
30+
echo
31+
echo " make test-config CONFIG=github.com/releases.yml # test a single config"
32+
echo " make test-domain DOMAIN=github.com # test all configs for a domain"
33+
echo " make schema # write schema locally (optional)"

bin/validate_configs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'bundler/setup'
5+
require 'html2rss'
6+
require 'yaml'
7+
8+
unless Html2rss::Config.respond_to?(:validate)
9+
warn 'Error: installed html2rss gem does not support Config.validate.'
10+
warn 'Run: bundle update html2rss'
11+
exit 1
12+
end
13+
14+
files = Dir['lib/html2rss/configs/**/*.yml']
15+
failed = []
16+
17+
files.each do |file|
18+
config = YAML.safe_load_file(file, symbolize_names: true)
19+
result = Html2rss::Config.validate(config)
20+
21+
if result.success?
22+
puts "ok #{file}"
23+
else
24+
puts "FAIL #{file}"
25+
result.errors.to_h.each do |key, messages|
26+
Array(messages).each { |msg| warn " #{key}: #{msg}" }
27+
end
28+
failed << file
29+
end
30+
end
31+
32+
puts
33+
if failed.empty?
34+
puts "#{files.size} configs validated successfully."
35+
else
36+
warn "#{failed.size}/#{files.size} configs failed validation."
37+
exit 1
38+
end

0 commit comments

Comments
 (0)