CI: only keep entries with the highest and second highest targetAbi

This commit is contained in:
Kilian von Pflugk 2024-08-23 22:51:42 +02:00
parent 6348040293
commit 799f0ad63b

View File

@ -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();
}