Non-0 exit code when comparison detects changes
dargmuesli opened this issue · 4 comments
dargmuesli commented
Hey there, would it be possible to let reg-suit compare
exit with a non-0 exit code when changes are detected? This way it's easy for scripts to decide whether to continue, e.g. CI systems could then fail the build. Other tools like Creevey already work like this. Alternatively, how could I detect that reg-suit compare
detected changes?
maniator commented
Anyone know if this is being worked on?
dargmuesli commented
If noone said so, I guess not.
I've created a shell script that uses jq
to check out.json
for changes as a workaround:
https://github.com/maevsi/maevsi/blob/742dfd1e9906c1d590254f2423f9e3f07989f9c8/nuxt/.storybook/storycap/test.sh#L12-L51
maniator commented
maniator commented
@dargmuesli I wrote something in node (modeled after your code)
const jq = require('node-jq');
const path = require('path');
const outJson = path.join(__dirname, 'working-directory/out.json');
async function runCheck() {
const failedItems = await jq.run('.failedItems[]', outJson, {});
if (failedItems.length) {
console.error('You have diff changes, please view them');
}
const newItems = await jq.run('.newItems[]', outJson, {});
if (newItems.length) {
console.error('You have new items, please view them');
}
const deletedItems = await jq.run('.deletedItems[]', outJson, {});
if (deletedItems.length) {
console.error('You have deleted items, please view them');
}
if (failedItems.length || deletedItems.length || newItems.length) {
console.error('Run "npm run view:diff" to view');
console.error(
'If you are satisfied with the changes, run "npm run diff:approve"',
);
process.exit(1);
}
}
runCheck().catch((err) => {
console.error(err);
process.exit(1);
});