diff options
author | 2020-03-12 08:30:43 +0100 | |
---|---|---|
committer | 2020-03-12 08:30:43 +0100 | |
commit | 17181637c809617dcfcd3eda28f6fb95c4eea3c7 (patch) | |
tree | 8c59947dce1fc88f3dc75fdb07220c667c694914 /scripts | |
parent | Restructure docs introduction (diff) | |
download | ferdium-recipes-17181637c809617dcfcd3eda28f6fb95c4eea3c7.tar.gz ferdium-recipes-17181637c809617dcfcd3eda28f6fb95c4eea3c7.tar.zst ferdium-recipes-17181637c809617dcfcd3eda28f6fb95c4eea3c7.zip |
Fail verify-all script if there are errors during validation
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/verify-all.js | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/scripts/verify-all.js b/scripts/verify-all.js index b3a559d..0b6397b 100644 --- a/scripts/verify-all.js +++ b/scripts/verify-all.js | |||
@@ -35,51 +35,56 @@ const decompress = (src, dest) => new Promise((resolve, reject) => { | |||
35 | const tempUncompressed = path.join(__dirname, `uncompressed/`); | 35 | const tempUncompressed = path.join(__dirname, `uncompressed/`); |
36 | 36 | ||
37 | for (const recipeInfo of all) { | 37 | for (const recipeInfo of all) { |
38 | // Get recipe infos | 38 | try { |
39 | const recipe = recipeInfo.id; | 39 | // Get recipe infos |
40 | const recipeNum = all.findIndex(e => e === recipeInfo); | 40 | const recipe = recipeInfo.id; |
41 | const compressedRecipe = path.join(__dirname, '../', `${recipe}.tar.gz`); | 41 | const recipeNum = all.findIndex(e => e === recipeInfo); |
42 | const uncompressedRecipe = path.join(__dirname, '../', 'uncompressed', recipe); | 42 | const compressedRecipe = path.join(__dirname, '../', `${recipe}.tar.gz`); |
43 | 43 | const uncompressedRecipe = path.join(__dirname, '../', 'uncompressed', recipe); | |
44 | // Check that recipe exists | ||
45 | if (!await fs.pathExists(compressedRecipe) || !await fs.pathExists(uncompressedRecipe)) { | ||
46 | console.log(`Error: Recipe "${recipe}" exists in all.json but not found.`); | ||
47 | process.exit(1); | ||
48 | } | ||
49 | |||
50 | // Clear temporary extraction folder | ||
51 | if (await fs.pathExists(tempUncompressed)) { | ||
52 | await fs.remove(tempUncompressed); | ||
53 | } | ||
54 | await fs.mkdir(tempUncompressed); | ||
55 | |||
56 | // Package to uncompressed recipe to .tar.gz | ||
57 | await decompress(compressedRecipe, tempUncompressed); | ||
58 | |||
59 | // Compare directories | ||
60 | const compare = await dircompare.compare(uncompressedRecipe, tempUncompressed, { | ||
61 | compareContent: true, | ||
62 | // Don't fail because of DS_Store files | ||
63 | excludeFilter: '.DS_Store', | ||
64 | }); | ||
65 | |||
66 | if (compare.same) { | ||
67 | console.log(`✓ ${recipe} is valid (${recipeNum + 1} of ${all.length})`); | ||
68 | } else { | ||
69 | console.log(`❌ Compressed and uncompressed files for "${recipe}" are NOT equal:`); | ||
70 | 44 | ||
71 | // Output information about differences | 45 | // Check that recipe exists |
72 | for (const file of compare.diffSet) { | 46 | if (!await fs.pathExists(compressedRecipe) || !await fs.pathExists(uncompressedRecipe)) { |
73 | if (file.state !== 'equal') { | 47 | console.log(`Error: Recipe "${recipe}" exists in all.json but not found.`); |
74 | console.log(`- "${file.name1 || file.name2}" is not equal (${file.type1} in uncompressed, ${file.type2} in archive)`); | 48 | process.exit(1); |
49 | } | ||
50 | |||
51 | // Clear temporary extraction folder | ||
52 | if (await fs.pathExists(tempUncompressed)) { | ||
53 | await fs.remove(tempUncompressed); | ||
54 | } | ||
55 | await fs.mkdir(tempUncompressed); | ||
56 | |||
57 | // Package to uncompressed recipe to .tar.gz | ||
58 | await decompress(compressedRecipe, tempUncompressed); | ||
59 | |||
60 | // Compare directories | ||
61 | const compare = await dircompare.compare(uncompressedRecipe, tempUncompressed, { | ||
62 | compareContent: true, | ||
63 | // Don't fail because of DS_Store files | ||
64 | excludeFilter: '.DS_Store', | ||
65 | }); | ||
66 | |||
67 | if (compare.same) { | ||
68 | console.log(`✓ ${recipe} is valid (${recipeNum + 1} of ${all.length})`); | ||
69 | } else { | ||
70 | console.log(`❌ Compressed and uncompressed files for "${recipe}" are NOT equal:`); | ||
71 | |||
72 | // Output information about differences | ||
73 | for (const file of compare.diffSet) { | ||
74 | if (file.state !== 'equal') { | ||
75 | console.log(`- "${file.name1 || file.name2}" is not equal (${file.type1} in uncompressed, ${file.type2} in archive)`); | ||
76 | } | ||
75 | } | 77 | } |
78 | |||
79 | process.exit(1); | ||
76 | } | 80 | } |
77 | 81 | ||
82 | // Remove temporary compressed file | ||
83 | await fs.remove(tempUncompressed); | ||
84 | } catch(e) { | ||
85 | console.log('Error while verifying recipe:', e); | ||
78 | process.exit(1); | 86 | process.exit(1); |
79 | } | 87 | } |
80 | |||
81 | // Remove temporary compressed file | ||
82 | await fs.remove(tempUncompressed); | ||
83 | } | 88 | } |
84 | 89 | ||
85 | console.log('All recipes are valid.'); | 90 | console.log('All recipes are valid.'); |