mirror of
https://github.com/github/codeql-action.git
synced 2026-04-29 02:18:47 +00:00
Add getLatestToolcacheVersion with tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as path from "path";
|
||||
|
||||
import * as toolcache from "@actions/tool-cache";
|
||||
import test from "ava";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
@@ -263,3 +264,15 @@ test('tryGetTagNameFromUrl extracts the right tag name for a repo name containin
|
||||
"codeql-bundle-v2.19.0",
|
||||
);
|
||||
});
|
||||
|
||||
test("getLatestToolcacheVersion returns undefined if there are no CodeQL CLIs in the toolcache", (t) => {
|
||||
sinon.stub(toolcache, "findAllVersions").returns([]);
|
||||
t.is(setupCodeql.getLatestToolcacheVersion(getRunnerLogger(true)), undefined);
|
||||
});
|
||||
|
||||
test("getLatestToolcacheVersion returns latest version in the toolcache", (t) => {
|
||||
const testVersions = ["2.3.1", "3.2.1", "1.2.3"];
|
||||
sinon.stub(toolcache, "findAllVersions").returns(testVersions);
|
||||
|
||||
t.is(setupCodeql.getLatestToolcacheVersion(getRunnerLogger(true)), "3.2.1");
|
||||
});
|
||||
|
||||
@@ -816,6 +816,34 @@ async function getNightlyToolsUrl(logger: Logger) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the latest version of the CodeQL CLI that is available in the toolcache, or `undefined`
|
||||
* if no CodeQL CLI is available in the toolcache.
|
||||
*
|
||||
* @param logger The logger to use.
|
||||
* @returns The latest version of the CodeQL CLI that is available in the toolcache, or `undefined` if there is none.
|
||||
*/
|
||||
export function getLatestToolcacheVersion(logger: Logger): string | undefined {
|
||||
const allVersions = toolcache
|
||||
.findAllVersions("CodeQL")
|
||||
.sort((a, b) => (semver.lt(a, b) ? 1 : -1));
|
||||
logger.debug(
|
||||
`Found the following versions of the CodeQL tools in the toolcache: ${JSON.stringify(
|
||||
allVersions,
|
||||
)}.`,
|
||||
);
|
||||
|
||||
if (allVersions.length > 0) {
|
||||
const latestToolcacheVersion = allVersions[0];
|
||||
logger.info(
|
||||
`CLI version ${latestToolcacheVersion} is the latest version in the toolcache.`,
|
||||
);
|
||||
return latestToolcacheVersion;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isReservedToolsValue(tools: string): boolean {
|
||||
return (
|
||||
CODEQL_BUNDLE_VERSION_ALIAS.includes(tools) ||
|
||||
|
||||
Reference in New Issue
Block a user