Skip to content

Commit

Permalink
simplify & style errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mnyrop committed Dec 1, 2023
1 parent d917a04 commit 95826e0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 99 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ jobs:
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
# skipping ogm v1 for efficiency
# - name: lint v1 records
# run: bundle exec rake lint:v1
- name: lint v1 records
run: bundle exec rake lint:v1
- name: lint aardvark records
run: bundle exec rake lint:aardvark
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
source 'https://rubygems.org'

gem 'geo_combine'
gem 'json_schemer'
gem 'rake'
gem 'ruby-progressbar'
Expand Down
58 changes: 0 additions & 58 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,25 @@ GIT
GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
base64 (0.2.0)
bigdecimal (3.1.4)
builder (3.2.4)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
crass (1.0.6)
dotenv (2.8.1)
drb (2.2.0)
ruby2_keywords
faraday (2.7.11)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
faraday-net_http_persistent (2.1.0)
faraday (~> 2.5)
net-http-persistent (~> 4.0)
geo_combine (0.8.0)
activesupport
faraday-net_http_persistent (~> 2.0)
git
json-schema
nokogiri
rsolr
sanitize
thor
git (1.18.0)
addressable (~> 2.8)
rchardet (~> 1.8)
hana (1.3.7)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json-schema (4.1.1)
addressable (>= 2.8)
json_schemer (2.1.1)
hana (~> 1.3)
regexp_parser (~> 2.0)
simpleidn (~> 0.2)
minitest (5.20.0)
mutex_m (0.2.0)
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
public_suffix (5.0.3)
racc (1.7.3)
rake (13.0.6)
rchardet (1.8.0)
regexp_parser (2.8.2)
rsolr (2.5.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sanitize (6.1.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
simpleidn (0.2.1)
unf (~> 0.1.4)
thor (1.2.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.9.1)
Expand All @@ -96,7 +39,6 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
geo_combine
json_schemer
rake
ruby-progressbar
Expand Down
11 changes: 7 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
require_relative 'lib/lint'

namespace :lint do
AARDVARK_SCHEMA_URL = 'https://opengeometadata.org/schema/geoblacklight-schema-aardvark.json'
OGM_V1_SCHEMA_URL = 'https://opengeometadata.org/schema/geoblacklight-schema-1.0.json'

desc "lint version 1 geoblacklight.json records"
task :v1 do
puts "OGM v1 ~>"
puts "\nOGM v1 ~>"
paths = Dir.glob("./metadata-1.0/**/*/geoblacklight.json")
lint_v1 paths
lint paths, OGM_V1_SCHEMA_URL
end
desc "lint aardvark geoblacklight.json records"
task :aardvark do
puts "AARDVARK ~>"
puts "\nAARDVARK ~>"
paths = Dir.glob("./metadata-aardvark/*/**/*.json")
lint_aardvark paths
lint paths, AARDVARK_SCHEMA_URL
end
desc "lint all records"
task :all do
Expand Down
51 changes: 18 additions & 33 deletions lib/lint.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,31 @@
require 'geo_combine'
require 'json'
require 'json_schemer'
require 'open-uri'
require 'ruby-progressbar'

AARDVARK_SCHEMA = 'https://opengeometadata.org/schema/geoblacklight-schema-aardvark.json'

def lint_aardvark (paths)
schema = JSON.load URI.open(AARDVARK_SCHEMA)
schemer = JSONSchemer.schema(schema)
def lint(paths, schema_url)
invalid = []
schemer = JSONSchemer.schema JSON.load(URI.open(schema_url))
bar = ProgressBar.create format: "Linting record %c/%C (%P% complete ) — %e", total: paths.length

paths.each do |path|
record = JSON.parse File.read(path)
id = File.basename(path, '.json')
record = JSON.parse File.read(path)
id = record['layer_id_s'] || record['id']

next puts "#{id}: ✅" if schemer.valid? record

puts "#{id}: ❌ #{schemer.validate(record).first['error']}"
invalid << {
'id' => id,
'errors' => schemer.validate(record).map { |x| x['error'] }
} unless schemer.valid?(record)
bar.increment
end
end

def lint_v1(paths)
records_invalid = 0
records_valid = 0
invalid_paths = []
progess_bar = ProgressBar.create format: "Linting record %c/%C (%P% complete ) — %e", total: paths.length

paths.each do |path|
rec = GeoCombine::Geoblacklight.new(File.read(path))
begin
rec.valid?
records_valid += 1
rescue
records_invalid += 1
invalid_paths << path
if invalid.empty?
puts "All #{paths.length} records passed ✅"
else
puts "#{invalid.length}/#{paths.length} records have failed schema validation:"
invalid.each do |i|
puts "❌ #{i['id']}"
i['errors'].each { |e| puts "\t #{e}" }
end
progess_bar.increment
end

if records_invalid > 0
raise "Contains #{records_invalid} invalid records:\n#{invalid_paths}"
else
puts "All records passed ✅"
end
end

0 comments on commit 95826e0

Please sign in to comment.