From 799f0ad63bdd367c87533d7eb8b01c7efda93b42 Mon Sep 17 00:00:00 2001 From: Kilian von Pflugk Date: Fri, 23 Aug 2024 22:51:42 +0200 Subject: [PATCH] CI: only keep entries with the highest and second highest targetAbi --- validate-and-update-manifest.js | 41 +++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/validate-and-update-manifest.js b/validate-and-update-manifest.js index ce74e73..9f5d683 100644 --- a/validate-and-update-manifest.js +++ b/validate-and-update-manifest.js @@ -38,10 +38,14 @@ async function updateManifest() { // Add the new version to the manifest jsonData[0].versions.unshift(newVersion); - // Write the updated manifest to file if validation is successful - fs.writeFileSync(manifestPath, JSON.stringify(jsonData, null, 4)); console.log('Manifest updated successfully.'); updateReadMeVersion(); + + cleanUpOldReleases(); + + // Write the modified JSON data back to the file + fs.writeFileSync(manifestPath, JSON.stringify(jsonData, null, 4), 'utf8'); + process.exit(0); // Exit with no error } @@ -123,6 +127,39 @@ function updateReadMeVersion() { } } +function cleanUpOldReleases() { + // Extract all unique targetAbi values + const abiSet = new Set(); + jsonData.forEach(entry => { + entry.versions.forEach(version => { + abiSet.add(version.targetAbi); + }); + }); + + // Convert the Set to an array and sort it in descending order + const abiArray = Array.from(abiSet).sort((a, b) => { + const aParts = a.split('.').map(Number); + const bParts = b.split('.').map(Number); + + for (let i = 0; i < aParts.length; i++) { + if (aParts[i] > bParts[i]) return -1; + if (aParts[i] < bParts[i]) return 1; + } + return 0; + }); + + // Identify the highest and second highest targetAbi + const highestAbi = abiArray[0]; + const secondHighestAbi = abiArray[1]; + + // Filter the versions array to keep only those with the highest or second highest targetAbi + jsonData.forEach(entry => { + entry.versions = entry.versions.filter(version => + version.targetAbi === highestAbi || version.targetAbi === secondHighestAbi + ); + }); +} + async function run() { await updateManifest(); }