mirror of
https://github.com/github/codeql-action.git
synced 2026-01-06 14:40:10 +08:00
Improve robustness of extracting bundle tag name
This commit is contained in:
@@ -139,11 +139,26 @@ function tryGetBundleVersionFromTagName(
|
||||
}
|
||||
|
||||
function tryGetTagNameFromUrl(url: string, logger: Logger): string | undefined {
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user