mirror of
https://github.com/github/codeql-action.git
synced 2026-04-29 18:30:14 +00:00
Store and check action version in Config
This commit is contained in:
@@ -199,6 +199,7 @@ test("load code quality config", async (t) => {
|
||||
|
||||
// And the config we expect it to result in
|
||||
const expectedConfig: configUtils.Config = {
|
||||
version: actionsUtil.getActionVersion(),
|
||||
analysisKinds: [AnalysisKind.CodeQuality],
|
||||
languages: [KnownLanguage.actions],
|
||||
buildMode: undefined,
|
||||
@@ -273,6 +274,55 @@ test("loading config saves config", async (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
test("loading config with version mismatch throws", async (t) => {
|
||||
return await withTmpDir(async (tempDir) => {
|
||||
const logger = getRunnerLogger(true);
|
||||
|
||||
const codeql = createStubCodeQL({
|
||||
async betterResolveLanguages() {
|
||||
return {
|
||||
extractors: {
|
||||
javascript: [{ extractor_root: "" }],
|
||||
python: [{ extractor_root: "" }],
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
// Sanity check the saved config file does not already exist
|
||||
t.false(fs.existsSync(configUtils.getPathToParsedConfigFile(tempDir)));
|
||||
|
||||
// Sanity check that getConfig returns undefined before we have called initConfig
|
||||
t.deepEqual(await configUtils.getConfig(tempDir, logger), undefined);
|
||||
|
||||
// Stub `getActionVersion` to return some nonsense.
|
||||
const getActionVersionStub = sinon
|
||||
.stub(actionsUtil, "getActionVersion")
|
||||
.resolves("does-not-exist");
|
||||
|
||||
await configUtils.initConfig(
|
||||
createTestInitConfigInputs({
|
||||
languagesInput: "javascript,python",
|
||||
tempDir,
|
||||
codeql,
|
||||
workspacePath: tempDir,
|
||||
logger,
|
||||
}),
|
||||
);
|
||||
|
||||
// Restore `getActionVersion`.
|
||||
getActionVersionStub.restore();
|
||||
|
||||
// The saved config file should now exist
|
||||
t.true(fs.existsSync(configUtils.getPathToParsedConfigFile(tempDir)));
|
||||
|
||||
// Trying to read the configuration should now throw an error.
|
||||
await t.throwsAsync(configUtils.getConfig(tempDir, logger), {
|
||||
instanceOf: ConfigurationError,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test("load input outside of workspace", async (t) => {
|
||||
return await withTmpDir(async (tempDir) => {
|
||||
try {
|
||||
@@ -389,6 +439,7 @@ test("load non-empty input", async (t) => {
|
||||
|
||||
// And the config we expect it to parse to
|
||||
const expectedConfig: configUtils.Config = {
|
||||
version: actionsUtil.getActionVersion(),
|
||||
analysisKinds: [AnalysisKind.CodeScanning],
|
||||
languages: [KnownLanguage.javascript],
|
||||
buildMode: BuildMode.None,
|
||||
|
||||
Reference in New Issue
Block a user