Improve robustness of extracting bundle tag name

This commit is contained in:
Henry Mercer 2024-10-28 19:48:51 +00:00
parent 3aa71356c7
commit b07135c4b8
3 changed files with 29 additions and 5 deletions

13
lib/setup-codeql.js generated
View file

@ -140,11 +140,20 @@ function tryGetBundleVersionFromTagName(tagName, logger) {
return match[1];
}
function tryGetTagNameFromUrl(url, logger) {
const match = url.match(/\/(codeql-bundle-.*)\//);
if (match === null || match.length < 2) {
const matches = [...url.matchAll(/\/(codeql-bundle-[^/]*)\//g)];
if (!matches.length) {
logger.debug(`Could not determine tag name for URL ${url}.`);
return undefined;
}
// Example: https://github.com/org/codeql-bundle-testing/releases/download/codeql-bundle-v2.19.0/codeql-bundle-linux64.tar.zst
// We require a trailing forward slash to be part of the match, so the last match gives us the tag
// name. An alternative approach would be to also match against `/releases/`, but this approach
// assumes less about the structure of the URL.
const match = matches[matches.length - 1];
if (match === null || match.length !== 2) {
logger.debug(`Could not determine tag name for URL ${url}. Matched ${JSON.stringify(match)}.`);
return undefined;
}
return match[1];
}
function tryGetBundleVersionFromUrl(url, logger) {