✨ Add release path module
This commit is contained in:
parent
ee3fd0a60f
commit
620cb8bb1d
1 changed files with 58 additions and 36 deletions
|
@ -40,13 +40,35 @@ function getFroms({ product, to: releaseTo}: {product: string, to: number}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks whether there is a valid path between our current release and the release we want to update to, and returns true or false.
|
/**
|
||||||
|
* Checks whether there is a valid path between our current release and the release we want to update to, and returns an array with
|
||||||
|
* the release path, or an empty array if no path exists.
|
||||||
|
* E.g. for `{ from: 21, to: 24 }`, it returns [[21, 22], [22, 23], [23, 24]].
|
||||||
* Does not actually look at the manifest.xml file but theorizes on possible patches based on the usually created patches, allowing
|
* Does not actually look at the manifest.xml file but theorizes on possible patches based on the usually created patches, allowing
|
||||||
* us to find release pathes for products that have not been released yet.
|
* us to find release pathes for products that have not been released yet.
|
||||||
*/
|
*/
|
||||||
export default function findReleasePath({ product, from, to}: {product: string, from: number, to: number}) {
|
export default function findReleasePath({ product, from, to}: {product: string, from: number, to: number}): Array<[number, number]> {
|
||||||
//TODO: need to recursively get froms until path is found
|
//We assume that "from < to" is true for all patches
|
||||||
//TODO: need to ignore patches that we know are bugged (i.e. missing from CDN)
|
|
||||||
return getFroms({ product, to }).includes(from);
|
const froms = getFroms({ product, to });
|
||||||
//TODO: we also need to return the release path, e.g. [[3, 4], [4, 5], [5, 6]]
|
|
||||||
|
//If we can patch, return immediately
|
||||||
|
if (froms.includes(from)) {
|
||||||
|
return [[from, to]];
|
||||||
|
}
|
||||||
|
|
||||||
|
//Otherwise, check all froms recursively, by checking interim releases
|
||||||
|
const smallerFroms = froms.filter((num) => num > from);
|
||||||
|
//Always prefer shortest release paths (e.g. 1->3 vs. 1->2->3) by ensuring we check smallest froms first
|
||||||
|
smallerFroms.sort();
|
||||||
|
|
||||||
|
for (let i = 0, il = smallerFroms.length; i < il; i += 1) {
|
||||||
|
const interim = smallerFroms[i];
|
||||||
|
const releasePath = findReleasePath({ product, from, to: interim} );
|
||||||
|
if (releasePath.length > 0) {
|
||||||
|
return [...releasePath, [interim, to]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue