Created
January 16, 2022 23:10
-
-
Save lollipopman/9ff2fce57d8901e198cded5d225ffffa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o errexit | |
tmp_dir=$(mktemp -p /tmp -d vinyl.XXXXXXXXXX) | |
cleanup() { | |
local exit_code=$? | |
if [[ -d "${tmp_dir}" ]]; then | |
rm -r "${tmp_dir}" | |
fi | |
return $exit_code | |
} | |
trap cleanup SIGINT SIGHUP SIGABRT EXIT | |
orig=$1 | |
if ! vinyl -m "${orig}" >"${tmp_dir}"/orig-vinyl.yaml; then | |
printf 'ERROR: vinyl failed to parse %s\n' "$orig" | |
exit 1 | |
fi | |
if ! ruby -e ' | |
require "yaml" | |
orig = ARGV[0] | |
vinyl = ARGV[1] | |
begin | |
orig_yaml = YAML.load_file(orig, fallback: nil) | |
rescue => e | |
puts "ERROR: Ruby unable to parse #{orig}" | |
puts e | |
end | |
begin | |
vinyl_yaml = YAML.load_file(vinyl, fallback: nil) | |
rescue => e | |
puts "ERROR: Ruby unable to parse #{vinyl}" | |
puts e | |
end | |
if orig_yaml == vinyl_yaml | |
exit 0 | |
else | |
puts "# ORIG" | |
puts orig_yaml.inspect | |
puts "# VINYL" | |
puts vinyl_yaml.inspect | |
exit 1 | |
end | |
' "$orig" "${tmp_dir}"/orig-vinyl.yaml; then | |
printf 'ERROR: Ruby parsing, %s\n' "$orig" | |
exit 1 | |
fi | |
if ! python3 -c ' | |
import yaml | |
import sys | |
try: | |
orig = open(sys.argv[1], "r") | |
orig_yaml = yaml.safe_load(orig) | |
vinyl = open(sys.argv[2], "r") | |
vinyl_yaml = yaml.safe_load(vinyl) | |
except OSError as err: | |
print(f"ERROR: Python unable to parse\n{err}") | |
exit(1) | |
except yaml.YAMLError as err: | |
print(f"ERROR: Python unable to parse\n{err}") | |
exit(1) | |
if orig_yaml == vinyl_yaml: | |
exit(0) | |
else: | |
print("# ORIG") | |
print(yaml.dump(orig_yaml)) | |
print("# VINYL") | |
print(yaml.dump(vinyl_yaml)) | |
exit(1) | |
' "$orig" "${tmp_dir}"/orig-vinyl.yaml; then | |
printf 'ERROR: Python parsing, %s\n' "$orig" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment