firmware_tools/differences/json.groovy
Dan Hawkins 1b74ea88ff Squashed 'Common_scripts/' content from commit 2c26b22
git-subtree-dir: Common_scripts
git-subtree-split: 2c26b221f1
2022-01-12 14:42:51 +00:00

51 lines
1.5 KiB
Groovy

def comparefiles(importedjsonfile, currentjsonfile) {
echo "Comparing json file: ${importedjsonfile} with: ${currentjsonfile}"
if (isUnix()) {
sh """
which jq
if [ \$? -ne 0 ]; then exit 1; fi
# jq -S sorts json output
diff -c <(jq -S . "${importedjsonfile}") <(jq -S . "${currentjsonfile}")
"""
}
else {
// Jq and diffutils can be installed on windows with chocolatey
powershell """
# echo Checking utilities exist
# set
# echo %PATH%
try {
if (Get-Command jq) {}
}
catch {
echo "jq is unavailable"
exit \$false
}
try {
if (Get-Command diff) {}
}
catch {
echo "diff is unavailable"
exit \$false
}
# echo Sorting json in files to compare
# jq -S sorts json output
jq -S . "${importedjsonfile}" > temp1.txt
if (\$lastexitcode -ge 1) { exit 1 }
jq -S . "${currentjsonfile}" > temp2.txt
if (\$lastexitcode -ge 1) { exit 1 }
# echo Diffing sorted json files
diff.exe -c temp1.txt temp2.txt
\$lec = \$lastexitcode
Remove-Item temp1.txt
Remove-Item temp2.txt
if (\$lec -ge 1) { exit 1 }
"""
}
}
return this;