chore: fix notes stack updates (#41600)

* chore: fix removeSupercededStackUpdates for generating notes

* add early stop for less than

* Update script/release/notes/notes.js

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* clean up comparison functionality

* add tests

---------

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
This commit is contained in:
Michaela Laurencin 2024-04-29 08:41:54 -07:00 committed by GitHub
parent 5310b79ffb
commit ef097b77ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 67 additions and 1 deletions

View file

@ -485,6 +485,24 @@ const getNotes = async (fromRef, toRef, newVersion) => {
return notes;
};
const compareVersions = (v1, v2) => {
const [split1, split2] = [v1.split('.'), v2.split('.')];
if (split1.length !== split2.length) {
throw new Error(`Expected version strings to have same number of sections: ${split1} and ${split2}`);
}
for (let i = 0; i < split1.length; i++) {
const p1 = parseInt(split1[i], 10);
const p2 = parseInt(split2[i], 10);
if (p1 > p2) return 1;
else if (p1 < p2) return -1;
// Continue checking the value if this portion is equal
}
return 0;
};
const removeSupercededStackUpdates = (commits) => {
const updateRegex = /^Updated ([a-zA-Z.]+) to v?([\d.]+)/;
const notupdates = [];
@ -496,8 +514,9 @@ const removeSupercededStackUpdates = (commits) => {
notupdates.push(commit);
continue;
}
const [, dep, version] = match;
if (!newest[dep] || newest[dep].version < version) {
if (!newest[dep] || compareVersions(version, newest[dep].version) > 0) {
newest[dep] = { commit, version };
}
}