Skip to content

Commit 6a38de6

Browse files
author
Dave Bartolomeo
authored
Merge pull request #2570 from github/henrymercer/more-robust-tag-name
Improve robustness of extracting the bundle tag name
2 parents 3aa7135 + 1f4b0cb commit 6a38de6

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

lib/setup-codeql.js

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.test.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-codeql.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,13 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to dow
249249
);
250250
});
251251
});
252+
253+
test('tryGetTagNameFromUrl extracts the right tag name for a repo name containing "codeql-bundle"', (t) => {
254+
t.is(
255+
setupCodeql.tryGetTagNameFromUrl(
256+
"https://github.com/org/codeql-bundle-testing/releases/download/codeql-bundle-v2.19.0/codeql-bundle-linux64.tar.zst",
257+
getRunnerLogger(true),
258+
),
259+
"codeql-bundle-v2.19.0",
260+
);
261+
});

src/setup-codeql.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,30 @@ function tryGetBundleVersionFromTagName(
138138
return match[1];
139139
}
140140

141-
function tryGetTagNameFromUrl(url: string, logger: Logger): string | undefined {
142-
const match = url.match(/\/(codeql-bundle-.*)\//);
143-
if (match === null || match.length < 2) {
141+
export function tryGetTagNameFromUrl(
142+
url: string,
143+
logger: Logger,
144+
): string | undefined {
145+
const matches = [...url.matchAll(/\/(codeql-bundle-[^/]*)\//g)];
146+
if (!matches.length) {
144147
logger.debug(`Could not determine tag name for URL ${url}.`);
145148
return undefined;
146149
}
150+
// Example: https://github.com/org/codeql-bundle-testing/releases/download/codeql-bundle-v2.19.0/codeql-bundle-linux64.tar.zst
151+
// We require a trailing forward slash to be part of the match, so the last match gives us the tag
152+
// name. An alternative approach would be to also match against `/releases/`, but this approach
153+
// assumes less about the structure of the URL.
154+
const match = matches[matches.length - 1];
155+
156+
if (match === null || match.length !== 2) {
157+
logger.debug(
158+
`Could not determine tag name for URL ${url}. Matched ${JSON.stringify(
159+
match,
160+
)}.`,
161+
);
162+
return undefined;
163+
}
164+
147165
return match[1];
148166
}
149167

0 commit comments

Comments
 (0)